can save settings now

master
endorphant 2016-05-01 18:43:12 -04:00
parent 7f1b9e1480
commit b727bbd916
1 changed files with 23 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import random
import tempfile import tempfile
import subprocess import subprocess
import time import time
import json
#import core #import core
import chatter import chatter
@ -19,6 +20,7 @@ USER = os.path.basename(os.path.expanduser("~"))
PATH = os.path.join("/home", USER, ".ttbp") PATH = os.path.join("/home", USER, ".ttbp")
WWW = os.path.join(PATH, "www") WWW = os.path.join(PATH, "www")
CONFIG = os.path.join(PATH, "config") CONFIG = os.path.join(PATH, "config")
TTBPRC = os.path.join(CONFIG, "ttbprc")
DATA = os.path.join(PATH, "entries") DATA = os.path.join(PATH, "entries")
SETTINGS = { SETTINGS = {
"editor":"vim", "editor":"vim",
@ -66,15 +68,16 @@ def stop():
return "\n\t"+chatter.say("bye") return "\n\t"+chatter.say("bye")
def check_init(): def check_init():
global SETTINGS
if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")): if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")):
print("welcome back, "+USER+".") print("welcome back, "+USER+".")
if not os.path.isfile(os.path.join(CONFIG, "ttbprc")): while not os.path.isfile(TTBPRC):
print("\nyour ttbp configuration doesn't look right. let's make you a fresh copy.\n\n") setup_handler()
try: try:
setup() SETTINGS = json.load(open(TTBPRC))
except KeyboardInterrupt: except ValueError:
print("\n\nsorry, trying again.\n\n") setup_handler()
setup()
raw_input("\n\npress enter to explore your feelings.\n\n") raw_input("\n\npress enter to explore your feelings.\n\n")
return "" return ""
else: else:
@ -84,6 +87,14 @@ 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_handler():
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()
def setup(): def setup():
global SETTINGS global SETTINGS
@ -122,6 +133,11 @@ def setup():
subprocess.call(["ln", "-s", publishing, WWW]) subprocess.call(["ln", "-s", publishing, WWW])
print("\npublishing to "+LIVE+USER+"/"+SETTINGS["publish dir"]+"/\n\n") print("\npublishing to "+LIVE+USER+"/"+SETTINGS["publish dir"]+"/\n\n")
# save settings
ttbprc = open(TTBPRC, "w")
ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':')))
ttbprc.close()
return SETTINGS return SETTINGS
## menus ## menus