Merge pull request #33 from modgethanc/issues-30

implements default nopub feature
master
hvincent 2018-02-28 17:38:17 -05:00 committed by GitHub
commit 091240c489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 180 additions and 94 deletions

View File

@ -4,7 +4,7 @@ from setuptools import setup
setup( setup(
name='ttbp', name='ttbp',
version='0.10.2', version='0.11.2',
description='command line social blogging tool used on tilde.town', description='command line social blogging tool used on tilde.town',
url='https://github.com/modgethanc/ttbp', url='https://github.com/modgethanc/ttbp',
author='~endorphant', author='~endorphant',
@ -20,6 +20,7 @@ setup(
'inflect==0.2.5', 'inflect==0.2.5',
'mistune==0.8.1', 'mistune==0.8.1',
'colorama==0.3.9', 'colorama==0.3.9',
'six'
], ],
include_package_data = True, include_package_data = True,
entry_points = { entry_points = {

View File

@ -82,7 +82,7 @@ ___________________________________________________________
| ____ ____ ____ _ ____ ____ _ _ ____ _ _ _ ____ | | ____ ____ ____ _ ____ ____ _ _ ____ _ _ _ ____ |
| |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ | | |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ |
| | |___ |___ |___ ___] |___ | \| |__] | | \| |___ | | | |___ |___ |___ ___] |___ | \| |__] | | \| |___ |
| ver 0.11.1 (rainbows) | | ver 0.11.2 (rainbows) |
|__________________________________________________________| |__________________________________________________________|
'''.lstrip() '''.lstrip()
@ -146,4 +146,12 @@ version 0.9.3 features:
exciting exciting
* general PSA: feel free to use the github repo for bugs/feature requests: * general PSA: feel free to use the github repo for bugs/feature requests:
https://github.com/modgethanc/ttbp/issues""", https://github.com/modgethanc/ttbp/issues""",
} "0.11.2": """
~[version 0.11.2 update]~
* added a new option to allow setting entries to default to either public or
non-public on posting; this option only really makes sense if you're
already publishing to html/gopher, but is available either way!
you can find this option under 'settings' as 'post as nopub'."""
}

View File

@ -235,12 +235,13 @@ def write_global_feed(blogList):
prints to blog feed prints to blog feed
''' '''
try:
outfile = open(FEED, "w") outfile = open(FEED, "w")
## header ## header
outfile.write("""\ outfile.write("""\
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\"> <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
<html> <html>
<head> <head>
<title>tilde.town feels engine</title> <title>tilde.town feels engine</title>
<link rel=\"stylesheet\" href=\"style.css\" /> <link rel=\"stylesheet\" href=\"style.css\" />
@ -256,7 +257,7 @@ def write_global_feed(blogList):
<!--<p>curious? run <b>~endorphant/bin/ttbp</b> while logged in to tilde.town.</p> <!--<p>curious? run <b>~endorphant/bin/ttbp</b> while logged in to tilde.town.</p>
<p>it's still a little volatile. let me know if anything breaks.</p>---></div> <p>it's still a little volatile. let me know if anything breaks.</p>---></div>
<p>&nbsp;</p> <p>&nbsp;</p>
""") """)
## docs ## docs
outfile.write("""\ outfile.write("""\
@ -281,11 +282,13 @@ def write_global_feed(blogList):
</ul> </ul>
</div> </div>
</body> </body>
</html> </html>
""") """)
outfile.close() outfile.close()
#subprocess.call(['chmod', 'a+w', FEED]) #subprocess.call(['chmod', 'a+w', FEED])
except FileNotFoundError:
pass
## misc helpers ## misc helpers
@ -309,7 +312,7 @@ def meta(entries = FILES):
for filename in entries: for filename in entries:
mtime = os.path.getmtime(filename) mtime = os.path.getmtime(filename)
try: try:
wc = subprocess.check_output(["wc","-w",filename], stderr=subprocess.STDOUT).split()[0] wc = int(subprocess.check_output(["wc","-w",filename], stderr=subprocess.STDOUT).split()[0])
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
wc = "???" wc = "???"
timestamp = time.strftime("%Y-%m-%d at %H:%M", time.localtime(mtime)) timestamp = time.strftime("%Y-%m-%d at %H:%M", time.localtime(mtime))

View File

@ -40,6 +40,7 @@ import time
import json import json
from email.mime.text import MIMEText from email.mime.text import MIMEText
import datetime import datetime
from six.moves import input
import inflect import inflect
@ -49,7 +50,7 @@ from . import chatter
from . import gopher from . import gopher
from . import util from . import util
__version__ = "0.11.1" __version__ = "0.11.2"
__author__ = "endorphant <endorphant@tilde.town)" __author__ = "endorphant <endorphant@tilde.town)"
p = inflect.engine() p = inflect.engine()
@ -107,7 +108,7 @@ def menu_handler(options, prompt, pagify=10, rainbow=False, top=""):
return util.list_select(options, prompt) return util.list_select(options, prompt)
else: else:
return page_helper(options, prompt, pagify, rainbow, page, total, top) return page_helper(options, prompt, pagify, rainbow, page, int(total), top)
def page_helper(options, prompt, pagify, rainbow, page, total, top): def page_helper(options, prompt, pagify, rainbow, page, total, top):
''' '''
@ -125,7 +126,7 @@ def page_helper(options, prompt, pagify, rainbow, page, total, top):
optPage = options[x:y] optPage = options[x:y]
util.print_menu(optPage, SETTINGS.get("rainbows", False)) util.print_menu(optPage, SETTINGS.get("rainbows", False))
print("\n\t( page {page} of {total}; type 'u' or 'd' to scroll up and down )").format(page=page+1, total=total+1) print("\n\t( page {page} of {total}; type 'u' or 'd' to scroll up and down)".format(page=page+1, total=total+1))
ans = util.list_select(optPage, prompt) ans = util.list_select(optPage, prompt)
@ -224,14 +225,16 @@ def check_init():
print("{greeting}, {user}".format(greeting=chatter.say("greet"), print("{greeting}, {user}".format(greeting=chatter.say("greet"),
user=config.USER)) user=config.USER))
load_settings = load_user_settings()
## ttbp env validation ## ttbp env validation
if not user_up_to_date(): if not user_up_to_date():
update_user_version() update_user_version()
if not valid_setup(): if not valid_setup(load_settings):
setup_repair() setup_repair()
else: else:
raw_input("press <enter> to explore your feels.\n\n") input("press <enter> to explore your feels.\n\n")
core.load(SETTINGS) core.load(SETTINGS)
@ -244,7 +247,7 @@ def init():
""" """
try: try:
raw_input(""" input("""
i don't recognize you, stranger. let's make friends. i don't recognize you, stranger. let's make friends.
press <enter> to begin, or <ctrl-c> to get out of here.""") press <enter> to begin, or <ctrl-c> to get out of here.""")
@ -294,7 +297,7 @@ press <enter> to begin, or <ctrl-c> to get out of here.""")
setup() setup()
core.load(SETTINGS) core.load(SETTINGS)
raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n") input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
return "" return ""
def gen_header(): def gen_header():
@ -326,23 +329,14 @@ def gen_header():
""" """
return header return header
def valid_setup(): def valid_setup(load_settings):
''' '''
Checks to see if user has a valid ttbp environment. Checks to see if user has a valid ttbp environment.
''' '''
global SETTINGS if not load_settings:
if not os.path.isfile(config.TTBPRC):
return False return False
try:
SETTINGS = json.load(open(config.TTBPRC))
except ValueError:
return False
core.load(SETTINGS)
for option in iter(DEFAULT_SETTINGS): for option in iter(DEFAULT_SETTINGS):
if option != "publish dir" and SETTINGS.get(option, None) is None: if option != "publish dir" and SETTINGS.get(option, None) is None:
return False return False
@ -361,6 +355,24 @@ def valid_setup():
return True return True
def load_user_settings():
"""attempts to load user's ttbprc; returns settings dict if valie, otherwise
returns false"""
global SETTINGS
if not os.path.isfile(config.TTBPRC):
return False
try:
SETTINGS = json.load(open(config.TTBPRC))
except ValueError:
return False
core.load(SETTINGS)
return SETTINGS
def setup_repair(): def setup_repair():
''' '''
setup repair function setup repair function
@ -380,7 +392,8 @@ def setup_repair():
"publishing": select_publishing, "publishing": select_publishing,
"publish dir": select_publish_dir, "publish dir": select_publish_dir,
"gopher": gopher.select_gopher, "gopher": gopher.select_gopher,
"rainbows": toggle_rainbows "rainbows": toggle_rainbows,
"post as nopub": toggle_pub_default
} }
for option in iter(settings_map): for option in iter(settings_map):
@ -394,7 +407,7 @@ def setup_repair():
print("...") print("...")
time.sleep(1) time.sleep(1)
raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n") input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
def setup(): def setup():
''' '''
@ -418,7 +431,7 @@ def setup():
util.print_menu(menuOptions, SETTINGS.get("rainbows", False)) util.print_menu(menuOptions, SETTINGS.get("rainbows", False))
try: try:
choice = raw_input("\npick a setting to change (or type 'q' to exit): ") choice = input("\npick a setting to change (or type 'q' to exit): ")
except KeyboardInterrupt: except KeyboardInterrupt:
redraw(EJECT) redraw(EJECT)
return SETTINGS return SETTINGS
@ -473,7 +486,14 @@ def setup():
save_settings() save_settings()
return setup() return setup()
raw_input("\nyou're all good to go, {friend}! hit <enter> to continue.\n\n".format(friend=chatter.say("friend"))) #nopub toggling
elif settingList[int(choice)] == "post as nopub":
SETTINGS.update({"post as nopub": toggle_pub_default()})
redraw("posting default set to {nopub}".format(nopub=SETTINGS.get("post as nopub")))
save_settings()
return setup()
input("\nyou're all good to go, {friend}! hit <enter> to continue.\n\n".format(friend=chatter.say("friend")))
redraw() redraw()
return SETTINGS return SETTINGS
@ -509,7 +529,7 @@ def main_menu():
util.print_menu(menuOptions, SETTINGS.get("rainbows", False)) util.print_menu(menuOptions, SETTINGS.get("rainbows", False))
try: try:
choice = raw_input("\ntell me about your feels (or type 'q' to exit): ") choice = input("\ntell me about your feels (or type 'q' to exit): ")
except KeyboardInterrupt: except KeyboardInterrupt:
redraw(EJECT) redraw(EJECT)
return main_menu() return main_menu()
@ -569,12 +589,12 @@ def feedback_menu():
''' '''
util.print_menu(SUBJECTS, SETTINGS.get("rainbows", False)) util.print_menu(SUBJECTS, SETTINGS.get("rainbows", False))
choice = raw_input("\npick a category for your feedback: ") choice = input("\npick a category for your feedback: ")
cat = "" cat = ""
if choice in ['0', '1', '2', '3']: if choice in ['0', '1', '2', '3']:
cat = SUBJECTS[int(choice)] cat = SUBJECTS[int(choice)]
entered = raw_input(""" entered = input("""
composing a {mail_category} to ~endorphant. composing a {mail_category} to ~endorphant.
press <enter> to open an external text editor. mail will be sent once you save and quit. press <enter> to open an external text editor. mail will be sent once you save and quit.
@ -752,7 +772,7 @@ i'd love to hear about your ideas and brainstorm about new features!
thanks to everyone who reads, listens, writes, and feels.\ thanks to everyone who reads, listens, writes, and feels.\
""") """)
raw_input("\n\npress <enter> to go back home.\n\n") input("\n\npress <enter> to go back home.\n\n")
redraw() redraw()
return return
@ -764,7 +784,7 @@ def write_entry(entry=os.path.join(config.USER_DATA, "test.txt")):
main feels-recording handler main feels-recording handler
''' '''
entered = raw_input(""" entered = input("""
feels will be recorded for today, {today}. feels will be recorded for today, {today}.
if you've already started recording feels for this day, you if you've already started recording feels for this day, you
@ -786,8 +806,10 @@ editor.
left = "" left = ""
if SETTINGS.get("post as nopub"):
core.toggle_nopub(os.path.basename(entry))
else:
if core.publishing(): if core.publishing():
core.load_files()
core.write("index.html") core.write("index.html")
left = "posted to {url}/index.html\n\n>".format( left = "posted to {url}/index.html\n\n>".format(
url="/".join( url="/".join(
@ -797,6 +819,8 @@ editor.
if SETTINGS.get('gopher'): if SETTINGS.get('gopher'):
gopher.publish_gopher('feels', core.get_files()) gopher.publish_gopher('feels', core.get_files())
left += " also posted to your ~/public_gopher!\n" left += " also posted to your ~/public_gopher!\n"
core.load_files()
redraw(left + " thanks for sharing your feels!") redraw(left + " thanks for sharing your feels!")
return return
@ -976,7 +1000,7 @@ wall will be recorded if you save the file, and you can cancel
your changes by exiting without saving. your changes by exiting without saving.
""") """)
raw_input("press <enter> to visit the wall\n\n") input("press <enter> to visit the wall\n\n")
subprocess.call([SETTINGS.get("editor"), config.WALL]) subprocess.call([SETTINGS.get("editor"), config.WALL])
subprocess.call(["rm", config.WALL_LOCK]) subprocess.call(["rm", config.WALL_LOCK])
redraw("thanks for visiting the graffiti wall!") redraw("thanks for visiting the graffiti wall!")
@ -984,6 +1008,46 @@ your changes by exiting without saving.
## misc helpers ## misc helpers
def toggle_pub_default():
"""setup helper for setting default publish privacy (does not apply
retroactively). """
if SETTINGS.get("post as nopub", False) is True:
(nopub, will) = ("(nopub)", "won't")
else:
(nopub, will) = ("public", "will")
if SETTINGS.get("publishing", False) is True:
publishing = ""
else:
publishing = """\
since you're currently not publishing your posts to html/gopher, this setting
won't affect the visibility of your posts. however, the option is still here if
you'd like to change it.
"""
print("""
DEFAULT POST PRIVACY
your entries are set to automatically post as {nopub}. this means they {will} be
posted to your world-visible pages at first (which you can always change after
the fact.)
this setting only affects subsequent posts; it does not apply retroactively.
{publishing}""".format(nopub=nopub, will=will, publishing=publishing))
ans = util.input_yn("""\
would you like to change this behavior?
please enter""")
if ans:
return not SETTINGS.get("post as nopub")
else:
return SETTINGS.get("post as nopub")
def toggle_rainbows(): def toggle_rainbows():
"""setup helper for rainbow toggling """setup helper for rainbow toggling
""" """
@ -1037,13 +1101,13 @@ def select_publish_dir():
print("\ncurrent publish dir:\t"+os.path.join(config.PUBLIC, SETTINGS["publish dir"])) print("\ncurrent publish dir:\t"+os.path.join(config.PUBLIC, SETTINGS["publish dir"]))
republish = True republish = True
choice = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ") choice = input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ")
if not choice: if not choice:
choice = "blog" choice = "blog"
publishDir = os.path.join(config.PUBLIC, choice) publishDir = os.path.join(config.PUBLIC, choice)
while os.path.exists(publishDir): while os.path.exists(publishDir):
second = raw_input("\n"+publishDir+"""\ second = input("\n"+publishDir+"""\
already exists! already exists!
setting this as your publishing directory means this program may setting this as your publishing directory means this program may
@ -1244,7 +1308,6 @@ def update_user_version():
ttbprc.close() ttbprc.close()
# from earlier than 0.10.1 # from earlier than 0.10.1
if y < 10: if y < 10:
# select gopher # select gopher
print("[ NEW FEATURE ]") print("[ NEW FEATURE ]")
@ -1266,6 +1329,12 @@ def update_user_version():
print("[ NEW FEATURE ]") print("[ NEW FEATURE ]")
SETTINGS.update({"rainbows": toggle_rainbows()}) SETTINGS.update({"rainbows": toggle_rainbows()})
if z < 2:
# set default option for 0.11.2
# print("default nopub: false")
SETTINGS.update({"post as nopub": False})
save_settings()
print(""" print("""
you're all good to go, """+chatter.say("friend")+"""! please contact ~endorphant if you're all good to go, """+chatter.say("friend")+"""! please contact ~endorphant if
something strange happened to you during this update. something strange happened to you during this update.
@ -1283,10 +1352,14 @@ something strange happened to you during this update.
# version 0.11.1 patch notes # version 0.11.1 patch notes
print(config.UPDATES["0.11.1"]) print(config.UPDATES["0.11.1"])
if y < 11 or z < 2:
# version 0.11.2 patch notes
print(config.UPDATES["0.11.2"])
confirm = "" confirm = ""
while confirm not in ("x", "<x>", "X", "<X>"): while confirm not in ("x", "<x>", "X", "<X>"):
confirm = raw_input("\nplease type <x> when you've finished reading about the updates! ") confirm = input("\nplease type <x> when you've finished reading about the updates! ")
print("\n\n") print("\n\n")

View File

@ -25,6 +25,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
''' '''
import random import random
import time import time
from six.moves import input
import colorama import colorama
import inflect import inflect
@ -179,7 +180,7 @@ def list_select(options, prompt):
ans = "" ans = ""
invalid = True invalid = True
choice = raw_input("\n"+prompt) choice = input("\n"+prompt)
if choice in BACKS: if choice in BACKS:
return False return False
@ -205,11 +206,11 @@ def input_yn(query):
''' '''
try: try:
ans = raw_input(query+" [y/n] ") ans = input(query+" [y/n] ")
except KeyboardInterrupt: except KeyboardInterrupt:
input_yn(query) input_yn(query)
while ans not in ["y", "n"]: while ans not in ["y", "n"]:
ans = raw_input("'y' or 'n' please: ") ans = input("'y' or 'n' please: ")
return ans == "y" return ans == "y"