From 7f1b9e1480e1fe0e34a1f15c6e64547851d38229 Mon Sep 17 00:00:00 2001 From: endorphant Date: Sun, 1 May 2016 18:26:26 -0400 Subject: [PATCH] user setting checks --- bin/core.py | 28 +++++++++------ bin/ttbp.py | 100 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 102 insertions(+), 26 deletions(-) diff --git a/bin/core.py b/bin/core.py index 3eb7f62..6642796 100644 --- a/bin/core.py +++ b/bin/core.py @@ -1,6 +1,7 @@ #!/usr/bin/python import os +import chatter SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin") USER = os.path.basename(os.path.expanduser("~")) @@ -11,6 +12,10 @@ WWW = os.path.join(PATH, "www") CONFIG = os.path.join(PATH, "config") DATA = os.path.join(PATH, "entries") +HEADER = "" +FOOTER = "" +FILES = [] + MONTHS = { "01":"january", "02":"february", @@ -26,20 +31,21 @@ MONTHS = { "12":"december" } -HEADER = open(os.path.join(CONFIG, "header.txt")).read() -FOOTER = open(os.path.join(CONFIG, "footer.txt")).read() +def load(): + global FILES + global HEADER + global FOOTER -FILES = [] + HEADER = open(os.path.join(CONFIG, "header.txt")).read() + FOOTER = open(os.path.join(CONFIG, "footer.txt")).read() -for file in os.listdir(DATA): - filename = os.path.join(DATA, file) - if os.path.isfile(filename) and os.path.splitext(filename)[1] == ".txt": - FILES.append(file) - #print(file) + for file in os.listdir(DATA): + filename = os.path.join(DATA, file) + if os.path.isfile(filename) and os.path.splitext(filename)[1] == ".txt": + FILES.append(file) -FILES.sort() -FILES.reverse() -#print("found: "+str(FILES)) + FILES.sort() + FILES.reverse() def write(outurl="default.html"): outfile = open(os.path.join(WWW, outurl), "w") diff --git a/bin/ttbp.py b/bin/ttbp.py index 36d4f8b..c967c08 100644 --- a/bin/ttbp.py +++ b/bin/ttbp.py @@ -9,23 +9,33 @@ import time #import core import chatter +## system globals SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin") +LIVE = "http://tilde.town/~" +FEEDBACK = os.path.join("/home", "endorphant", "ttbp-mail") + +## user globals USER = os.path.basename(os.path.expanduser("~")) PATH = os.path.join("/home", USER, ".ttbp") - -LIVE = "http://tilde.town/~" WWW = os.path.join(PATH, "www") CONFIG = os.path.join(PATH, "config") DATA = os.path.join(PATH, "entries") +SETTINGS = { + "editor":"vim", + "publish dir":"blog" + } -FEEDBACK = os.path.join("/home", "endorphant", "ttbp-mail") +## ui globals BANNER = open(os.path.join(SOURCE, "config", "banner.txt")).read() -#CLOSER = "\n\tsee you later, space cowboy..." - SPACER = "\n\n\n" INVALID = "please pick a number from the list of options!\n\n" DUST = "sorry about the dust, but this part is still under construction. check back later!\n\n" +## ref + +EDITORS = ["vim", "vi", "emacs", "pico", "nano"] +SUBJECTS = ["bug report", "feature suggestion", "general comment"] + ## def redraw(leftover=""): @@ -46,10 +56,10 @@ def start(): redraw() print(main_menu()) except ValueError or SyntaxError: - redraw("\n\noh no i didn't understand that") + redraw("oh no i didn't understand that. let's go home and start over.") print(main_menu()) except KeyboardInterrupt: - redraw("\n\neject button fired") + redraw("eject button fired! going home now.") print(main_menu()) def stop(): @@ -57,7 +67,15 @@ def stop(): def check_init(): if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")): - raw_input("welcome back, "+USER+".\n\npress enter to explore your feelings.\n\n") + print("welcome back, "+USER+".") + if not os.path.isfile(os.path.join(CONFIG, "ttbprc")): + print("\nyour ttbp configuration doesn't look right. let's make you a fresh copy.\n\n") + try: + setup() + except KeyboardInterrupt: + print("\n\nsorry, trying again.\n\n") + setup() + raw_input("\n\npress enter to explore your feelings.\n\n") return "" else: return init() @@ -66,6 +84,46 @@ def init(): raw_input("i don't recognize you, stranger. let's make friends someday.\n\npress enter to explore some options.\n\n") return "" +def setup(): + global SETTINGS + + # editor selection + print_menu(EDITORS) + choice = raw_input("\npick your favorite text editor: ") + while choice not in ['0', '1', '2', '3', '4']: + choice = raw_input("\nplease pick a number from the list: ") + + SETTINGS["editor"] = EDITORS[int(choice)] + print("\ntext editor set to >"+SETTINGS["editor"]) + + # publish directory selection + choice = raw_input("\n\nwhere do you want your blog published? (leave blank to use default \"blog\") ") + if not choice: + choice = "blog" + + publishing = os.path.join("/home", USER, "public_html", choice) + while os.path.exists(publishing): + second = raw_input("\n"+publishing+" already exists!\nif you're sure you want to use it, hit to confirm. otherwise, pick another location: ") + if second == "": + break + choice = second + publishing = os.path.join("/home", USER, "public_html", choice) + + SETTINGS["publish dir"] = choice + + # set up publish directory + if not os.path.exists(publishing): + subprocess.call(["mkdir", publishing]) + subprocess.call(["touch", os.path.join(publishing, "index.html")]) + index = open(os.path.join(publishing, "index.html"), "w") + index.write("

ttbp blog placeholder

") + index.close() + subprocess.call(["rm", WWW]) + subprocess.call(["ln", "-s", publishing, WWW]) + print("\npublishing to "+LIVE+USER+"/"+SETTINGS["publish dir"]+"/\n\n") + + return SETTINGS + ## menus def print_menu(menu): @@ -83,21 +141,34 @@ def main_menu(): #os.system("clear") #print(BANNER) #redraw() - menuOptions = ["record feelings", "check out neighbors","send feedback"] + menuOptions = [ + "record feelings", + "check out neighbors", + "change settings", + "send feedback", + "see credits"] #print(SPACER) print("you're at ttbp home now. remember, you can always press ctrl-c to come back here.\n\n") print_menu(menuOptions) #print("how are you feeling today? ") - choice = raw_input("\ntell me about your feels (enter 'none' to quit): ") + try: + choice = raw_input("\ntell me about your feels (enter 'none' to quit): ") + except KeyboardInterrupt: + redraw("eject button fired! going home now.") + return main_menu() if choice == '0': redraw(DUST) elif choice == '1': redraw(DUST) elif choice == '2': + redraw(DUST) + elif choice == '3': redraw() feedback_menu() + elif choice == '4': + redraw(DUST) elif choice == "none": return stop() else: @@ -107,14 +178,13 @@ def main_menu(): def feedback_menu(): print("you're about to send mail to ~endorphant about ttbp\n\n") - menuOptions = ["bug report", "feature suggestion", "general comment"] - print_menu(menuOptions) + print_menu(SUBJECTS) choice = raw_input("\npick a category for your feedback: ") cat = "" if choice in ['0', '1', '2']: - cat = menuOptions[int(choice)] + cat = SUBJECTS[int(choice)] raw_input("\ncomposing a "+cat+" to ~endorphant.\n\npress enter to open an external text editor. mail will be sent once you save and quit.\n") redraw(send_feedback(cat)) return @@ -127,7 +197,7 @@ def feedback_menu(): def write_entry(entry=os.path.join(DATA, "test.txt")): - subprocess.call(["vim", entry]) + subprocess.call([SETTINGS["editor"], entry]) return "wrote to "+entry def send_feedback(subject="none", mailbox=os.path.join(FEEDBACK, USER+"-"+str(int(time.time()))+".msg")): @@ -135,7 +205,7 @@ def send_feedback(subject="none", mailbox=os.path.join(FEEDBACK, USER+"-"+str(in mail = "" temp = tempfile.NamedTemporaryFile() - subprocess.call(['vim', temp.name]) + subprocess.call([SETTINGS["editor"], temp.name]) mail = open(temp.name, 'r').read() outfile = open(mailbox, 'w')