From b727bbd916a189a31231d61aadbb4be8bdc54e3a Mon Sep 17 00:00:00 2001 From: endorphant Date: Sun, 1 May 2016 18:43:12 -0400 Subject: [PATCH] can save settings now --- bin/ttbp.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/bin/ttbp.py b/bin/ttbp.py index c967c08..067b80e 100644 --- a/bin/ttbp.py +++ b/bin/ttbp.py @@ -5,6 +5,7 @@ import random import tempfile import subprocess import time +import json #import core import chatter @@ -19,6 +20,7 @@ USER = os.path.basename(os.path.expanduser("~")) PATH = os.path.join("/home", USER, ".ttbp") WWW = os.path.join(PATH, "www") CONFIG = os.path.join(PATH, "config") +TTBPRC = os.path.join(CONFIG, "ttbprc") DATA = os.path.join(PATH, "entries") SETTINGS = { "editor":"vim", @@ -66,15 +68,16 @@ def stop(): return "\n\t"+chatter.say("bye") def check_init(): + global SETTINGS if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")): 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() + while not os.path.isfile(TTBPRC): + setup_handler() + try: + SETTINGS = json.load(open(TTBPRC)) + except ValueError: + setup_handler() + raw_input("\n\npress enter to explore your feelings.\n\n") return "" 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") 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(): global SETTINGS @@ -122,6 +133,11 @@ def setup(): subprocess.call(["ln", "-s", publishing, WWW]) 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 ## menus