diff --git a/setup.py b/setup.py index 227ebe3..906c91d 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup setup( name='ttbp', - version='0.10.2', + version='0.11.2', description='command line social blogging tool used on tilde.town', url='https://github.com/modgethanc/ttbp', author='~endorphant', @@ -20,6 +20,7 @@ setup( 'inflect==0.2.5', 'mistune==0.8.1', 'colorama==0.3.9', + 'six' ], include_package_data = True, entry_points = { diff --git a/ttbp/config/__init__.py b/ttbp/config/__init__.py index 942400f..495f874 100644 --- a/ttbp/config/__init__.py +++ b/ttbp/config/__init__.py @@ -82,7 +82,7 @@ ___________________________________________________________ | ____ ____ ____ _ ____ ____ _ _ ____ _ _ _ ____ | | |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ | | | |___ |___ |___ ___] |___ | \| |__] | | \| |___ | -| ver 0.11.1 (rainbows) | +| ver 0.11.2 (rainbows) | |__________________________________________________________| '''.lstrip() @@ -146,4 +146,12 @@ version 0.9.3 features: exciting * general PSA: feel free to use the github repo for bugs/feature requests: 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'.""" +} diff --git a/ttbp/core.py b/ttbp/core.py index 3c358c0..7084fdd 100644 --- a/ttbp/core.py +++ b/ttbp/core.py @@ -235,57 +235,60 @@ def write_global_feed(blogList): prints to blog feed ''' - outfile = open(FEED, "w") + try: + outfile = open(FEED, "w") - ## header - outfile.write("""\ - - - - tilde.town feels engine - - - -
-

tilde.town feels engine

+ ## header + outfile.write("""\ + + + + tilde.town feels engine + + + +
+

tilde.town feels engine

-

github - repo | state - of the ttbp

-
-

 

-""") +

github + repo | state + of the ttbp

+
+

 

+ """) - ## docs - outfile.write("""\ -
""") - outfile.write(mistune.markdown(open(os.path.join(config.INSTALL_PATH, "..", "README.md"), "r").read())) - outfile.write("""\ -
""") + ## docs + outfile.write("""\ +
""") + outfile.write(mistune.markdown(open(os.path.join(config.INSTALL_PATH, "..", "README.md"), "r").read())) + outfile.write("""\ +
""") - ## feed - outfile.write("""\ -

 

-
-

live feels-sharing:

- -
- - -""") - - outfile.close() - #subprocess.call(['chmod', 'a+w', FEED]) + outfile.close() + #subprocess.call(['chmod', 'a+w', FEED]) + except FileNotFoundError: + pass ## misc helpers @@ -309,7 +312,7 @@ def meta(entries = FILES): for filename in entries: mtime = os.path.getmtime(filename) 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: wc = "???" timestamp = time.strftime("%Y-%m-%d at %H:%M", time.localtime(mtime)) diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index 90d867c..ebaea39 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -40,6 +40,7 @@ import time import json from email.mime.text import MIMEText import datetime +from six.moves import input import inflect @@ -49,7 +50,7 @@ from . import chatter from . import gopher from . import util -__version__ = "0.11.1" +__version__ = "0.11.2" __author__ = "endorphant to explore your feels.\n\n") + input("press to explore your feels.\n\n") core.load(SETTINGS) @@ -244,7 +247,7 @@ def init(): """ try: - raw_input(""" + input(""" i don't recognize you, stranger. let's make friends. press to begin, or to get out of here.""") @@ -294,7 +297,7 @@ press to begin, or to get out of here.""") setup() core.load(SETTINGS) - raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit to continue.\n\n") + input("\nyou're all good to go, "+chatter.say("friend")+"! hit to continue.\n\n") return "" def gen_header(): @@ -326,23 +329,14 @@ def gen_header(): """ return header -def valid_setup(): +def valid_setup(load_settings): ''' Checks to see if user has a valid ttbp environment. ''' - global SETTINGS - - if not os.path.isfile(config.TTBPRC): + if not load_settings: return False - try: - SETTINGS = json.load(open(config.TTBPRC)) - except ValueError: - return False - - core.load(SETTINGS) - for option in iter(DEFAULT_SETTINGS): if option != "publish dir" and SETTINGS.get(option, None) is None: return False @@ -361,6 +355,24 @@ def valid_setup(): 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(): ''' setup repair function @@ -380,7 +392,8 @@ def setup_repair(): "publishing": select_publishing, "publish dir": select_publish_dir, "gopher": gopher.select_gopher, - "rainbows": toggle_rainbows + "rainbows": toggle_rainbows, + "post as nopub": toggle_pub_default } for option in iter(settings_map): @@ -394,7 +407,7 @@ def setup_repair(): print("...") time.sleep(1) - raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit to continue.\n\n") + input("\nyou're all good to go, "+chatter.say("friend")+"! hit to continue.\n\n") def setup(): ''' @@ -418,7 +431,7 @@ def setup(): util.print_menu(menuOptions, SETTINGS.get("rainbows", False)) 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: redraw(EJECT) return SETTINGS @@ -473,7 +486,14 @@ def setup(): save_settings() return setup() - raw_input("\nyou're all good to go, {friend}! hit 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 to continue.\n\n".format(friend=chatter.say("friend"))) redraw() return SETTINGS @@ -509,7 +529,7 @@ def main_menu(): util.print_menu(menuOptions, SETTINGS.get("rainbows", False)) 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: redraw(EJECT) return main_menu() @@ -569,12 +589,12 @@ def feedback_menu(): ''' 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 = "" if choice in ['0', '1', '2', '3']: cat = SUBJECTS[int(choice)] - entered = raw_input(""" + entered = input(""" composing a {mail_category} to ~endorphant. press 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.\ """) - raw_input("\n\npress to go back home.\n\n") + input("\n\npress to go back home.\n\n") redraw() return @@ -764,7 +784,7 @@ def write_entry(entry=os.path.join(config.USER_DATA, "test.txt")): main feels-recording handler ''' - entered = raw_input(""" + entered = input(""" feels will be recorded for today, {today}. if you've already started recording feels for this day, you @@ -786,17 +806,21 @@ editor. left = "" - if core.publishing(): - core.load_files() - core.write("index.html") - left = "posted to {url}/index.html\n\n>".format( - url="/".join( - [config.LIVE+config.USER, - str(SETTINGS.get("publish dir"))])) + if SETTINGS.get("post as nopub"): + core.toggle_nopub(os.path.basename(entry)) + else: + if core.publishing(): + core.write("index.html") + left = "posted to {url}/index.html\n\n>".format( + url="/".join( + [config.LIVE+config.USER, + str(SETTINGS.get("publish dir"))])) - if SETTINGS.get('gopher'): - gopher.publish_gopher('feels', core.get_files()) - left += " also posted to your ~/public_gopher!\n" + if SETTINGS.get('gopher'): + gopher.publish_gopher('feels', core.get_files()) + left += " also posted to your ~/public_gopher!\n" + + core.load_files() redraw(left + " thanks for sharing your feels!") return @@ -976,7 +1000,7 @@ wall will be recorded if you save the file, and you can cancel your changes by exiting without saving. """) - raw_input("press to visit the wall\n\n") + input("press to visit the wall\n\n") subprocess.call([SETTINGS.get("editor"), config.WALL]) subprocess.call(["rm", config.WALL_LOCK]) redraw("thanks for visiting the graffiti wall!") @@ -984,6 +1008,46 @@ your changes by exiting without saving. ## 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(): """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"])) 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: choice = "blog" publishDir = os.path.join(config.PUBLIC, choice) while os.path.exists(publishDir): - second = raw_input("\n"+publishDir+"""\ + second = input("\n"+publishDir+"""\ already exists! setting this as your publishing directory means this program may @@ -1244,7 +1308,6 @@ def update_user_version(): ttbprc.close() # from earlier than 0.10.1 - if y < 10: # select gopher print("[ NEW FEATURE ]") @@ -1266,6 +1329,12 @@ def update_user_version(): print("[ NEW FEATURE ]") 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(""" you're all good to go, """+chatter.say("friend")+"""! please contact ~endorphant if 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 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 = "" while confirm not in ("x", "", "X", ""): - confirm = raw_input("\nplease type when you've finished reading about the updates! ") + confirm = input("\nplease type when you've finished reading about the updates! ") print("\n\n") diff --git a/ttbp/util.py b/ttbp/util.py index 85707b5..5168018 100644 --- a/ttbp/util.py +++ b/ttbp/util.py @@ -25,6 +25,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import random import time +from six.moves import input import colorama import inflect @@ -179,7 +180,7 @@ def list_select(options, prompt): ans = "" invalid = True - choice = raw_input("\n"+prompt) + choice = input("\n"+prompt) if choice in BACKS: return False @@ -205,11 +206,11 @@ def input_yn(query): ''' try: - ans = raw_input(query+" [y/n] ") + ans = input(query+" [y/n] ") except KeyboardInterrupt: input_yn(query) while ans not in ["y", "n"]: - ans = raw_input("'y' or 'n' please: ") + ans = input("'y' or 'n' please: ") return ans == "y"