forked from endorphant/ttbp
user setting checks
parent
5f3085c337
commit
7f1b9e1480
22
bin/core.py
22
bin/core.py
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import chatter
|
||||||
|
|
||||||
SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin")
|
SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin")
|
||||||
USER = os.path.basename(os.path.expanduser("~"))
|
USER = os.path.basename(os.path.expanduser("~"))
|
||||||
|
@ -11,6 +12,10 @@ WWW = os.path.join(PATH, "www")
|
||||||
CONFIG = os.path.join(PATH, "config")
|
CONFIG = os.path.join(PATH, "config")
|
||||||
DATA = os.path.join(PATH, "entries")
|
DATA = os.path.join(PATH, "entries")
|
||||||
|
|
||||||
|
HEADER = ""
|
||||||
|
FOOTER = ""
|
||||||
|
FILES = []
|
||||||
|
|
||||||
MONTHS = {
|
MONTHS = {
|
||||||
"01":"january",
|
"01":"january",
|
||||||
"02":"february",
|
"02":"february",
|
||||||
|
@ -26,20 +31,21 @@ MONTHS = {
|
||||||
"12":"december"
|
"12":"december"
|
||||||
}
|
}
|
||||||
|
|
||||||
HEADER = open(os.path.join(CONFIG, "header.txt")).read()
|
def load():
|
||||||
FOOTER = open(os.path.join(CONFIG, "footer.txt")).read()
|
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):
|
for file in os.listdir(DATA):
|
||||||
filename = os.path.join(DATA, file)
|
filename = os.path.join(DATA, file)
|
||||||
if os.path.isfile(filename) and os.path.splitext(filename)[1] == ".txt":
|
if os.path.isfile(filename) and os.path.splitext(filename)[1] == ".txt":
|
||||||
FILES.append(file)
|
FILES.append(file)
|
||||||
#print(file)
|
|
||||||
|
|
||||||
FILES.sort()
|
FILES.sort()
|
||||||
FILES.reverse()
|
FILES.reverse()
|
||||||
#print("found: "+str(FILES))
|
|
||||||
|
|
||||||
def write(outurl="default.html"):
|
def write(outurl="default.html"):
|
||||||
outfile = open(os.path.join(WWW, outurl), "w")
|
outfile = open(os.path.join(WWW, outurl), "w")
|
||||||
|
|
98
bin/ttbp.py
98
bin/ttbp.py
|
@ -9,23 +9,33 @@ import time
|
||||||
#import core
|
#import core
|
||||||
import chatter
|
import chatter
|
||||||
|
|
||||||
|
## system globals
|
||||||
SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin")
|
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("~"))
|
USER = os.path.basename(os.path.expanduser("~"))
|
||||||
PATH = os.path.join("/home", USER, ".ttbp")
|
PATH = os.path.join("/home", USER, ".ttbp")
|
||||||
|
|
||||||
LIVE = "http://tilde.town/~"
|
|
||||||
WWW = os.path.join(PATH, "www")
|
WWW = os.path.join(PATH, "www")
|
||||||
CONFIG = os.path.join(PATH, "config")
|
CONFIG = os.path.join(PATH, "config")
|
||||||
DATA = os.path.join(PATH, "entries")
|
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()
|
BANNER = open(os.path.join(SOURCE, "config", "banner.txt")).read()
|
||||||
#CLOSER = "\n\tsee you later, space cowboy..."
|
|
||||||
|
|
||||||
SPACER = "\n\n\n"
|
SPACER = "\n\n\n"
|
||||||
INVALID = "please pick a number from the list of options!\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"
|
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=""):
|
def redraw(leftover=""):
|
||||||
|
@ -46,10 +56,10 @@ def start():
|
||||||
redraw()
|
redraw()
|
||||||
print(main_menu())
|
print(main_menu())
|
||||||
except ValueError or SyntaxError:
|
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())
|
print(main_menu())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
redraw("\n\neject button fired")
|
redraw("eject button fired! going home now.")
|
||||||
print(main_menu())
|
print(main_menu())
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
|
@ -57,7 +67,15 @@ def stop():
|
||||||
|
|
||||||
def check_init():
|
def check_init():
|
||||||
if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")):
|
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 ""
|
return ""
|
||||||
else:
|
else:
|
||||||
return init()
|
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")
|
raw_input("i don't recognize you, stranger. let's make friends someday.\n\npress enter to explore some options.\n\n")
|
||||||
return ""
|
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 <enter> 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("<h1>ttbp blog placeholder</h1>")
|
||||||
|
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
|
## menus
|
||||||
|
|
||||||
def print_menu(menu):
|
def print_menu(menu):
|
||||||
|
@ -83,21 +141,34 @@ def main_menu():
|
||||||
#os.system("clear")
|
#os.system("clear")
|
||||||
#print(BANNER)
|
#print(BANNER)
|
||||||
#redraw()
|
#redraw()
|
||||||
menuOptions = ["record feelings", "check out neighbors","send feedback"]
|
menuOptions = [
|
||||||
|
"record feelings",
|
||||||
|
"check out neighbors",
|
||||||
|
"change settings",
|
||||||
|
"send feedback",
|
||||||
|
"see credits"]
|
||||||
#print(SPACER)
|
#print(SPACER)
|
||||||
print("you're at ttbp home now. remember, you can always press ctrl-c to come back here.\n\n")
|
print("you're at ttbp home now. remember, you can always press ctrl-c to come back here.\n\n")
|
||||||
print_menu(menuOptions)
|
print_menu(menuOptions)
|
||||||
#print("how are you feeling today? ")
|
#print("how are you feeling today? ")
|
||||||
|
|
||||||
|
try:
|
||||||
choice = raw_input("\ntell me about your feels (enter 'none' to quit): ")
|
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':
|
if choice == '0':
|
||||||
redraw(DUST)
|
redraw(DUST)
|
||||||
elif choice == '1':
|
elif choice == '1':
|
||||||
redraw(DUST)
|
redraw(DUST)
|
||||||
elif choice == '2':
|
elif choice == '2':
|
||||||
|
redraw(DUST)
|
||||||
|
elif choice == '3':
|
||||||
redraw()
|
redraw()
|
||||||
feedback_menu()
|
feedback_menu()
|
||||||
|
elif choice == '4':
|
||||||
|
redraw(DUST)
|
||||||
elif choice == "none":
|
elif choice == "none":
|
||||||
return stop()
|
return stop()
|
||||||
else:
|
else:
|
||||||
|
@ -107,14 +178,13 @@ def main_menu():
|
||||||
|
|
||||||
def feedback_menu():
|
def feedback_menu():
|
||||||
print("you're about to send mail to ~endorphant about ttbp\n\n")
|
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: ")
|
choice = raw_input("\npick a category for your feedback: ")
|
||||||
|
|
||||||
cat = ""
|
cat = ""
|
||||||
if choice in ['0', '1', '2']:
|
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")
|
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))
|
redraw(send_feedback(cat))
|
||||||
return
|
return
|
||||||
|
@ -127,7 +197,7 @@ def feedback_menu():
|
||||||
|
|
||||||
def write_entry(entry=os.path.join(DATA, "test.txt")):
|
def write_entry(entry=os.path.join(DATA, "test.txt")):
|
||||||
|
|
||||||
subprocess.call(["vim", entry])
|
subprocess.call([SETTINGS["editor"], entry])
|
||||||
return "wrote to "+entry
|
return "wrote to "+entry
|
||||||
|
|
||||||
def send_feedback(subject="none", mailbox=os.path.join(FEEDBACK, USER+"-"+str(int(time.time()))+".msg")):
|
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 = ""
|
mail = ""
|
||||||
|
|
||||||
temp = tempfile.NamedTemporaryFile()
|
temp = tempfile.NamedTemporaryFile()
|
||||||
subprocess.call(['vim', temp.name])
|
subprocess.call([SETTINGS["editor"], temp.name])
|
||||||
mail = open(temp.name, 'r').read()
|
mail = open(temp.name, 'r').read()
|
||||||
|
|
||||||
outfile = open(mailbox, 'w')
|
outfile = open(mailbox, 'w')
|
||||||
|
|
Loading…
Reference in New Issue