adding publish setting to patcher

patcher now asks user to set new publish option on load. publish and
unpublish correctly links or unlinks file from user's public_html.

also, ~tightened up the graphics a little~
master
endorphant 2016-05-19 23:19:02 -04:00
parent 2a406d7958
commit d94f3d2830
3 changed files with 101 additions and 70 deletions

View File

@ -38,8 +38,8 @@ SETTINGS = {
} }
## ui globals ## ui globals
BANNER = util.attach_rainbow()+open(os.path.join(SOURCE, "config", "banner.txt")).read()+util.attach_reset() BANNER = util.attach_rainbow()+open(os.path.join(SOURCE, "config", "banner.txt")).read()+"~potentially volatile beta version~"+util.attach_reset()
SPACER = "\n\n\n" SPACER = "\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"
QUITS = ['exit', 'quit', 'q', 'x'] QUITS = ['exit', 'quit', 'q', 'x']
@ -48,7 +48,7 @@ EJECT = "eject button fired! going home now."
## ref ## ref
EDITORS = ["vim", "vi", "emacs", "pico", "nano"] EDITORS = ["vim", "vi", "emacs", "pico", "nano", "ed"]
SUBJECTS = ["help request", "bug report", "feature suggestion", "general comment"] SUBJECTS = ["help request", "bug report", "feature suggestion", "general comment"]
## ##
@ -75,10 +75,6 @@ just keep in mind that you might lose anything you've started here.\
print(stop()) print(stop())
return return
## PATCH CHECK HERE
if not updated():
update_version()
## ##
redraw() redraw()
@ -97,22 +93,27 @@ def stop():
return "\n\n\t"+chatter.say("bye")+"\n\n" return "\n\n\t"+chatter.say("bye")+"\n\n"
def check_init(): def check_init():
global SETTINGS global SETTINGS
print("\n\n") print("\n\n")
if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")): if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")):
print(chatter.say("greet")+", "+USER+".") print(chatter.say("greet")+", "+USER+".\n")
while not os.path.isfile(TTBPRC): while not os.path.isfile(TTBPRC):
setup_handler() setup_handler()
try: try:
SETTINGS = json.load(open(TTBPRC)) SETTINGS = json.load(open(TTBPRC))
except ValueError: except ValueError:
setup_handler() setup_handler()
raw_input("\n\npress <enter> to explore your feels.\n\n") ## PATCH CHECK HERE
core.load() if not updated():
return "" print(update_version())
else:
return init() raw_input("press <enter> to explore your feels.\n\n")
core.load()
return ""
else:
return init()
def init(): def init():
try: try:
@ -186,24 +187,18 @@ def setup():
# publishing selection # publishing selection
SETTINGS.update({"publishing":select_publishing()}) SETTINGS.update({"publishing":select_publishing()})
update_publishing()
redraw("blog publishing: "+str(publishing())) redraw("blog publishing: "+str(publishing()))
if publishing(): if publishing():
oldDir = SETTINGS.get("publish dir") print("publish directory: ~"+USER+"/public_html/"+SETTINGS.get("publish dir"))
newDir = select_publish_dir()
SETTINGS.update({"publish dir": newDir})
subprocess.call(["rm", "-rf", os.path.join(PUBLIC, oldDir)])
make_publish_dir(newDir)
core.load_files()
core.write("index.html")
else:
unpublish()
# save settings # save settings
ttbprc = open(TTBPRC, "w") ttbprc = open(TTBPRC, "w")
ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':'))) ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':')))
ttbprc.close() ttbprc.close()
raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
redraw()
return SETTINGS return SETTINGS
## menus ## menus
@ -246,29 +241,28 @@ def main_menu():
write_entry(os.path.join(DATA, today+".txt")) write_entry(os.path.join(DATA, today+".txt"))
www_neighbors(find_ttbps()) www_neighbors(find_ttbps())
elif choice == '1': elif choice == '1':
redraw("here are your recorded feels, listed by date:\n\n") redraw("here are your recorded feels, listed by date:\n")
view_own() view_own()
elif choice == '2': elif choice == '2':
users = find_ttbps() users = find_ttbps()
redraw("the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:\n\n") redraw("the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:\n")
view_neighbors(users) view_neighbors(users)
elif choice == '3': elif choice == '3':
redraw("now viewing most recent entries\n\n") redraw("now viewing most recent entries\n")
view_feed() view_feed()
elif choice == '4': elif choice == '4':
pretty_settings = "\n\ttext editor:\t" +SETTINGS.get("editor") pretty_settings = "\n\n\ttext editor:\t" +SETTINGS.get("editor")
pretty_settings += "\n\tpublish dir:\t" +os.path.join(PUBLIC, SETTINGS.get("publish dir")) if publishing():
pretty_settings += "\n\tpublish dir:\t" +os.path.join(PUBLIC, SETTINGS.get("publish dir"))
pretty_settings += "\n\tpubishing:\t"+str(SETTINGS.get("publishing")) pretty_settings += "\n\tpubishing:\t"+str(SETTINGS.get("publishing"))
redraw("now changing your settings. press <ctrl-c> if you didn't mean to do this.\n\ncurrent settings "+pretty_settings+"\n") redraw("now changing your settings. press <ctrl-c> if you didn't mean to do this."+pretty_settings+"\n")
try: try:
setup() setup()
except KeyboardInterrupt(): except KeyboardInterrupt():
redraw(EJECT) redraw(EJECT)
raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
redraw() redraw()
elif choice == '5': elif choice == '5':
redraw()
feedback_menu() feedback_menu()
elif choice == '6': elif choice == '6':
redraw() redraw()
@ -371,6 +365,8 @@ def show_credits():
ttbp was written by ~endorphant in python. the codebase is ttbp was written by ~endorphant in python. the codebase is
publicly available on github at https://github.com/modgethanc/ttbp publicly available on github at https://github.com/modgethanc/ttbp
for the full changelog, see ~endorphant/projects/ttbp/changelog.txt
if you have ideas for ttbp, you are welcome to fork the repo and if you have ideas for ttbp, you are welcome to fork the repo and
work on it. i'm only a neophyte dev, so i apologize for any work on it. i'm only a neophyte dev, so i apologize for any
horrendously ugly coding habits i have. i'd love to hear about your horrendously ugly coding habits i have. i'd love to hear about your
@ -577,7 +573,10 @@ def list_select(options, prompt):
def input_yn(query): def input_yn(query):
# returns boolean True or False # returns boolean True or False
ans = raw_input(query+" [y/n] ") try:
ans = raw_input(query+" [y/n] ")
except KeyboardInterrupt:
input_yn(query)
while ans not in ["y", "n"]: while ans not in ["y", "n"]:
ans = raw_input("'y' or 'n' please: ") ans = raw_input("'y' or 'n' please: ")
@ -605,7 +604,7 @@ def select_editor():
print_menu(EDITORS) print_menu(EDITORS)
choice = raw_input("\npick your favorite text editor: ") choice = raw_input("\npick your favorite text editor: ")
while choice not in ['0', '1', '2', '3', '4']: while choice not in ['0', '1', '2', '3', '4', '5']:
choice = raw_input("\nplease pick a number from the list: ") choice = raw_input("\nplease pick a number from the list: ")
return EDITORS[int(choice)] return EDITORS[int(choice)]
@ -617,7 +616,7 @@ def select_publish_dir():
republish = False republish = False
if current: if current:
print("\tcurrent publish dir:\t"+os.path.join(PUBLIC, SETTINGS["publish dir"])+"\n\n") print("\ncurrent publish dir:\t"+os.path.join(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 = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ")
@ -626,7 +625,7 @@ def select_publish_dir():
publishDir = os.path.join(PUBLIC, choice) publishDir = os.path.join(PUBLIC, choice)
while os.path.exists(publishDir): while os.path.exists(publishDir):
second = raw_input("\n"+publishDir+" already exists!\nif you're sure you want to use it, hit <enter> to confirm. otherwise, pick another location: ") second = raw_input("\n"+publishDir+" already exists!\n\nif you're sure you want to use it, hit <enter> to confirm. otherwise, pick another location: ")
if second == "": if second == "":
break break
choice = second choice = second
@ -640,9 +639,13 @@ def select_publishing():
publish = input_yn("""\ publish = input_yn("""\
do you want to publish your feels online? do you want to publish your feels online?
if yes, i'll make a directory in your public_html where your blog posts if yes, your feels will be published to a directory of your choice in
will be published. if not, your posts will only be readable from your public_html. i'll confirm the location of that directory in a
within the tilde.town network. moment.
if not, your feels will only be readable from within the tilde.town
network. if you already have a publishing directory, i'll remove it for
you (don't worry, your written entries will still be saved!)
you can change this option any time. you can change this option any time.
@ -654,13 +657,29 @@ please enter\
def unpublish(): def unpublish():
# remove user's published directory, if it exists # remove user's published directory, if it exists
publishDir = os.path.join(PUBLIC, SETTINGS.get("publish dir")) dir = SETTINGS.get("publish dir")
if dir:
publishDir = os.path.join(PUBLIC, dir)
subprocess.call(["rm", publishDir])
#subprocess.call(["rm", WWW])
if os.path.exists(publishDir): def update_publishing():
subprocess.call(["rm", "-rf", publishDir]) # handler to update publishing directory, or wipe it
subprocess.call(["rm", WWW])
return global SETTINGS
if publishing():
oldDir = SETTINGS.get("publish dir")
newDir = select_publish_dir()
SETTINGS.update({"publish dir": newDir})
if oldDir:
subprocess.call(["rm", "-rf", os.path.join(PUBLIC, oldDir)])
make_publish_dir(newDir)
core.load_files()
core.write("index.html")
else:
unpublish()
SETTINGS.update({"publish dir": None})
def make_publish_dir(dir): def make_publish_dir(dir):
# setup helper to create publishing directory # setup helper to create publishing directory
@ -698,17 +717,24 @@ def updated():
return False return False
def update_version(): def update_version():
# updates current user to current version # updates user to current version
global SETTINGS
versionFile = os.path.join(PATH, "version") versionFile = os.path.join(PATH, "version")
print(versionFile)
print("ttbp had some updates!")
# from 0.8.5 to 0.8.6: # from 0.8.5 to 0.8.6:
if not os.path.isfile(versionFile):# and publishing(): if not os.path.isfile(versionFile):
#print("hi let's fix this") print("\ngive me a second to update you from version 0.8.5 to "+VERSION+"...\n")
time.sleep(1)
print("...")
time.sleep(2)
# change style.css location # change style.css location
if os.path.exists(os.path.join(WWW, "style.css")): if os.path.isfile(os.path.join(WWW, "style.css")):
subprocess.call(["mv", os.path.join(WWW, "style.css"), CONFIG]) subprocess.call(["mv", os.path.join(WWW, "style.css"), CONFIG])
# change www symlink # change www symlink
@ -719,9 +745,7 @@ def update_version():
subprocess.call(["ln", "-s", os.path.join(CONFIG, "style.css"), os.path.join(WWW, "style.css")]) subprocess.call(["ln", "-s", os.path.join(CONFIG, "style.css"), os.path.join(WWW, "style.css")])
publishDir = os.path.join(PUBLIC, SETTINGS.get("publish dir")) publishDir = os.path.join(PUBLIC, SETTINGS.get("publish dir"))
#print(publishDir)
if os.path.exists(publishDir): if os.path.exists(publishDir):
#print("removing "+publishDir)
subprocess.call(["rm", "-rf", publishDir]) subprocess.call(["rm", "-rf", publishDir])
subprocess.call(["ln", "-s", WWW, os.path.join(PUBLIC, SETTINGS.get("publish dir"))]) subprocess.call(["ln", "-s", WWW, os.path.join(PUBLIC, SETTINGS.get("publish dir"))])
@ -729,11 +753,18 @@ def update_version():
core.load_files() core.load_files()
core.write("index.html") core.write("index.html")
# add publishing setting
print("\nnew feature!\n")
SETTINGS.update({"publishing":select_publishing()})
update_publishing()
# increment user versionfile # increment user versionfile
open(versionFile, "w").write(VERSION) open(versionFile, "w").write(VERSION)
return "you're all good to go, "+chatter.say("friend")+"!\n"
##### #####
start()
#start() #print("ttbp beta is out to lunch. bbl.")
print("ttbp beta is out to lunch. bbl.")

View File

@ -6,5 +6,4 @@
| | |___ |___ |___ ___] |___ | \| |__] | | \| |___ | | | |___ |___ |___ ___] |___ | \| |__] | | \| |___ |
| | | |
| ver 0.8.5 (almost stable) | | ver 0.8.5 (almost stable) |
| ~endorphant/projects/ttbp/changelog.txt |
|__________________________________________________________| |__________________________________________________________|

View File

@ -36,7 +36,7 @@ SETTINGS = {
## ui globals ## ui globals
BANNER = util.attach_rainbow()+open(os.path.join(SOURCE, "config", "banner.txt")).read()+util.attach_reset() BANNER = util.attach_rainbow()+open(os.path.join(SOURCE, "config", "banner.txt")).read()+util.attach_reset()
SPACER = "\n\n\n" SPACER = "\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"
QUITS = ['exit', 'quit', 'q', 'x'] QUITS = ['exit', 'quit', 'q', 'x']
@ -45,7 +45,7 @@ EJECT = "eject button fired! going home now."
## ref ## ref
EDITORS = ["vim", "vi", "emacs", "pico", "nano"] EDITORS = ["vim", "vi", "emacs", "pico", "nano", "ed"]
SUBJECTS = ["help request", "bug report", "feature suggestion", "general comment"] SUBJECTS = ["help request", "bug report", "feature suggestion", "general comment"]
## ##
@ -53,7 +53,6 @@ SUBJECTS = ["help request", "bug report", "feature suggestion", "general comment
def redraw(leftover=""): def redraw(leftover=""):
os.system("clear") os.system("clear")
print(BANNER) print(BANNER)
print("DEV NOTE: want to see more color? try ~endorphant/bin/ttbp-beta and let me know what you think!")
print(SPACER) print(SPACER)
if leftover: if leftover:
print("> "+leftover+"\n") print("> "+leftover+"\n")
@ -192,7 +191,7 @@ def setup():
# editor selection # editor selection
print_menu(EDITORS) print_menu(EDITORS)
choice = raw_input("\npick your favorite text editor: ") choice = raw_input("\npick your favorite text editor: ")
while choice not in ['0', '1', '2', '3', '4']: while choice not in ['0', '1', '2', '3', '4', '5']:
choice = raw_input("\nplease pick a number from the list: ") choice = raw_input("\nplease pick a number from the list: ")
SETTINGS["editor"] = EDITORS[int(choice)] SETTINGS["editor"] = EDITORS[int(choice)]
@ -272,14 +271,14 @@ def main_menu():
write_entry(os.path.join(DATA, today+".txt")) write_entry(os.path.join(DATA, today+".txt"))
www_neighbors(find_ttbps()) www_neighbors(find_ttbps())
elif choice == '1': elif choice == '1':
redraw("here are your recorded feels, listed by date:\n\n") redraw("here are your recorded feels, listed by date:\n")
view_own() view_own()
elif choice == '2': elif choice == '2':
users = find_ttbps() users = find_ttbps()
redraw("the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:\n\n") redraw("the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:\n")
view_neighbors(users) view_neighbors(users)
elif choice == '3': elif choice == '3':
redraw("now viewing most recent entries\n\n") redraw("now viewing most recent entries\n")
view_feed() view_feed()
elif choice == '4': elif choice == '4':
pretty_settings = "\n\ttext editor:\t" +SETTINGS["editor"] pretty_settings = "\n\ttext editor:\t" +SETTINGS["editor"]
@ -396,6 +395,8 @@ def show_credits():
ttbp was written by ~endorphant in python. the codebase is ttbp was written by ~endorphant in python. the codebase is
publicly available on github at https://github.com/modgethanc/ttbp publicly available on github at https://github.com/modgethanc/ttbp
for the full changelog, see ~endorphant/projects/ttbp/changelog.txt
if you have ideas for ttbp, you are welcome to fork the repo and if you have ideas for ttbp, you are welcome to fork the repo and
work on it. i'm only a neophyte dev, so i apologize for any work on it. i'm only a neophyte dev, so i apologize for any
horrendously ugly coding habits i have. i'd love to hear about your horrendously ugly coding habits i have. i'd love to hear about your