polished menu feature, resolves #23
parent
9fd7b8020e
commit
5b16817f50
|
@ -74,7 +74,9 @@ def publish_gopher(gopher_path, entry_filenames):
|
||||||
'''
|
'''
|
||||||
# symlink instead
|
# symlink instead
|
||||||
|
|
||||||
subprocess.call(["ln", "-s", entry_filename, os.path.join(ttbp_gopher, os.path.basename(entry_fileNAME))])
|
gopher_entry_symlink = os.path.join(ttbp_gopher, os.path.basename(entry_filename))
|
||||||
|
if not os.path.exists(gopher_entry_symlink):
|
||||||
|
subprocess.call(["ln", "-s", entry_filename, gopher_entry_symlink])
|
||||||
|
|
||||||
label = "-".join(parse_date(entry_filename))
|
label = "-".join(parse_date(entry_filename))
|
||||||
gophermap.write('0{file_label}\t{filename}\n'.format(
|
gophermap.write('0{file_label}\t{filename}\n'.format(
|
||||||
|
|
74
ttbp/ttbp.py
74
ttbp/ttbp.py
|
@ -72,7 +72,7 @@ RAINBOW = False
|
||||||
|
|
||||||
## ref
|
## ref
|
||||||
|
|
||||||
EDITORS = ["vim", "vi", "emacs", "pico", "nano", "ed", "micro"]
|
EDITORS = ["nano", "vim", "vi", "emacs", "pico", "ed", "micro"]
|
||||||
SUBJECTS = ["help request", "bug report", "feature suggestion", "general comment"]
|
SUBJECTS = ["help request", "bug report", "feature suggestion", "general comment"]
|
||||||
|
|
||||||
## ttbp specific utilities
|
## ttbp specific utilities
|
||||||
|
@ -354,7 +354,7 @@ def valid_setup():
|
||||||
if not os.path.exists(os.path.join(config.WWW, SETTINGS.get("pubish dir"))):
|
if not os.path.exists(os.path.join(config.WWW, SETTINGS.get("pubish dir"))):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not SETTINGS.get("gopher"):
|
if isinstance(SETTINGS.get("gopher"), type(None)):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -388,43 +388,80 @@ def setup():
|
||||||
|
|
||||||
global SETTINGS
|
global SETTINGS
|
||||||
|
|
||||||
|
menuOptions = []
|
||||||
|
settingList = sorted(list(SETTINGS))
|
||||||
|
|
||||||
|
for setting in settingList:
|
||||||
|
menuOptions.append(setting + ": \t" + str(SETTINGS.get(setting)))
|
||||||
|
util.print_menu(menuOptions, RAINBOW)
|
||||||
|
|
||||||
|
try:
|
||||||
|
choice = raw_input("\npick a setting to change (or type 'q' to exit): ")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
redraw(EJECT)
|
||||||
|
return SETTINGS
|
||||||
|
"""
|
||||||
print("\n\ttext editor:\t" +SETTINGS.get("editor"))
|
print("\n\ttext editor:\t" +SETTINGS.get("editor"))
|
||||||
if core.publishing():
|
if core.publishing():
|
||||||
print("\tpublish dir:\t" +os.path.join(config.PUBLIC, str(SETTINGS.get("publish dir"))))
|
print("\tpublish dir:\t" +os.path.join(config.PUBLIC, str(SETTINGS.get("publish dir"))))
|
||||||
print("\tpublishing:\t"+str(SETTINGS.get("publishing")))
|
print("\tpublishing:\t"+str(SETTINGS.get("publishing")))
|
||||||
print("\tgopher:\t"+str(SETTINGS.get('gopher')))
|
print("\tgopher:\t"+str(SETTINGS.get('gopher')))
|
||||||
print("")
|
print("")
|
||||||
|
"""
|
||||||
|
|
||||||
|
if choice in QUITS:
|
||||||
|
redraw()
|
||||||
|
return SETTINGS
|
||||||
|
|
||||||
# editor selection
|
# editor selection
|
||||||
|
if settingList[int(choice)] == "editor":
|
||||||
SETTINGS.update({"editor": select_editor()})
|
SETTINGS.update({"editor": select_editor()})
|
||||||
redraw("text editor set to: "+SETTINGS["editor"])
|
redraw("text editor set to: "+SETTINGS["editor"])
|
||||||
|
save_settings()
|
||||||
|
return setup()
|
||||||
|
|
||||||
# publishing selection
|
# publishing selection
|
||||||
|
elif settingList[int(choice)] == "publishing":
|
||||||
SETTINGS.update({"publishing":select_publishing()})
|
SETTINGS.update({"publishing":select_publishing()})
|
||||||
core.reload_ttbprc(SETTINGS)
|
core.reload_ttbprc(SETTINGS)
|
||||||
update_publishing()
|
#update_publishing()
|
||||||
redraw("blog publishing: "+str(core.publishing()))
|
#print("blog publishing: "+str(core.publishing()))
|
||||||
|
redraw("publishing set to "+str(SETTINGS.get("publishing")))
|
||||||
|
save_settings()
|
||||||
|
return setup()
|
||||||
|
|
||||||
if core.publishing():
|
# publish dir selection
|
||||||
print("publish directory: ~"+config.USER+"/public_html/"+SETTINGS.get("publish dir"))
|
elif settingList[int(choice)] == "publish dir":
|
||||||
|
update_publishing()
|
||||||
|
redraw("publishing your entries to "+config.LIVE+config.USER+"/"+str(SETTINGS.get("publish dir"))+"/index.html")
|
||||||
|
save_settings()
|
||||||
|
return setup()
|
||||||
|
|
||||||
# gopher opt-in
|
# gopher opt-in
|
||||||
|
elif settingList[int(choice)] == "gopher":
|
||||||
SETTINGS.update({'gopher': gopher.select_gopher()})
|
SETTINGS.update({'gopher': gopher.select_gopher()})
|
||||||
#redraw('opting into gopher: ' + str(SETTINGS['gopher']))
|
#redraw('opting into gopher: ' + str(SETTINGS['gopher']))
|
||||||
# TODO for now i'm hardcoding where people's gopher stuff is generated. if
|
# TODO for now i'm hardcoding where people's gopher stuff is generated. if
|
||||||
# there is demand for this to be configurable we can expose that.
|
# there is demand for this to be configurable we can expose that.
|
||||||
gopher.setup_gopher('feels')
|
gopher.setup_gopher('feels')
|
||||||
|
redraw("gopher publishing set to "+str(SETTINGS.get("gopher")))
|
||||||
# save settings
|
save_settings()
|
||||||
ttbprc = open(config.TTBPRC, "w")
|
return setup()
|
||||||
ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':')))
|
|
||||||
ttbprc.close()
|
|
||||||
|
|
||||||
raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
|
raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
|
||||||
redraw()
|
redraw()
|
||||||
|
|
||||||
return SETTINGS
|
return SETTINGS
|
||||||
|
|
||||||
|
def save_settings():
|
||||||
|
"""
|
||||||
|
Save current settings.
|
||||||
|
"""
|
||||||
|
|
||||||
|
ttbprc = open(config.TTBPRC, "w")
|
||||||
|
ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':')))
|
||||||
|
ttbprc.close()
|
||||||
|
|
||||||
## menus
|
## menus
|
||||||
|
|
||||||
def main_menu():
|
def main_menu():
|
||||||
|
@ -479,11 +516,7 @@ def main_menu():
|
||||||
graffiti_handler()
|
graffiti_handler()
|
||||||
elif choice == '5':
|
elif choice == '5':
|
||||||
redraw("now changing your settings. press <ctrl-c> if you didn't mean to do this.")
|
redraw("now changing your settings. press <ctrl-c> if you didn't mean to do this.")
|
||||||
try:
|
|
||||||
core.load(setup()) # reload settings to core
|
core.load(setup()) # reload settings to core
|
||||||
except KeyboardInterrupt():
|
|
||||||
redraw(EJECT)
|
|
||||||
redraw()
|
|
||||||
elif choice == '6':
|
elif choice == '6':
|
||||||
redraw("you're about to send mail to ~endorphant about ttbp")
|
redraw("you're about to send mail to ~endorphant about ttbp")
|
||||||
feedback_menu()
|
feedback_menu()
|
||||||
|
@ -722,7 +755,7 @@ 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!"
|
left += " also posted to your ~/public_gopher!\n"
|
||||||
redraw(left + " thanks for sharing your feels!")
|
redraw(left + " thanks for sharing your feels!")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -882,13 +915,14 @@ def select_editor():
|
||||||
setup helper for editor selection
|
setup helper for editor selection
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
print("")
|
||||||
|
print("your current editor is: "+SETTINGS.get("editor"))
|
||||||
util.print_menu(EDITORS, RAINBOW)
|
util.print_menu(EDITORS, RAINBOW)
|
||||||
choice = util.list_select(EDITORS, "pick your favorite text editor: ")
|
choice = util.list_select(EDITORS, "pick your favorite text editor, or type 'q' to go back: ")
|
||||||
|
|
||||||
if choice is False:
|
if choice is False:
|
||||||
redraw("please pick a text editor!")
|
# if selection is canceled, return either previously set editor or default
|
||||||
select_editor()
|
return SETTINGS.get("editor", EDITORS[0])
|
||||||
|
|
||||||
return EDITORS[int(choice)]
|
return EDITORS[int(choice)]
|
||||||
|
|
||||||
def select_publish_dir():
|
def select_publish_dir():
|
||||||
|
|
Loading…
Reference in New Issue