From e1359d3899a8bb729b2eea4d59d789c5dd132870 Mon Sep 17 00:00:00 2001 From: Vincent Zeng Date: Thu, 22 Mar 2018 21:59:19 -0400 Subject: [PATCH] cleaning up gopher/html publish/unpublish behavior for purging and loading backups --- ttbp/config/__init__.py | 3 ++- ttbp/gopher.py | 9 +++++++++ ttbp/ttbp.py | 34 +++++++++++++++++++++------------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/ttbp/config/__init__.py b/ttbp/config/__init__.py index 860266e..ee66099 100644 --- a/ttbp/config/__init__.py +++ b/ttbp/config/__init__.py @@ -68,12 +68,13 @@ USER_HOME = os.path.expanduser('~') PATH = os.path.join(USER_HOME, '.ttbp') PUBLIC = os.path.join(USER_HOME, 'public_html') WWW = os.path.join(PATH, 'www') +GOPHER_ENTRIES = os.path.join(PATH, 'gopher') GOPHER_PATH = os.path.join(USER_HOME, 'public_gopher', 'feels') USER_CONFIG = os.path.join(PATH, 'config') TTBPRC = os.path.join(USER_CONFIG, 'ttbprc') MAIN_FEELS = os.path.join(PATH, 'entries') BURIED_FEELS = os.path.join(PATH, 'buried') -NOPUB = os.path.join(USER_CONFIG, "nopub") +NOPUB = os.path.join(USER_CONFIG, 'nopub') BACKUPS = os.path.join(PATH, 'backups') ## UI diff --git a/ttbp/gopher.py b/ttbp/gopher.py index a8fbb7b..17f02a3 100644 --- a/ttbp/gopher.py +++ b/ttbp/gopher.py @@ -7,6 +7,7 @@ import time import subprocess from . import util +from . import config #from .core import parse_date GOPHER_PROMPT = """ @@ -107,3 +108,11 @@ def setup_gopher(gopher_path): os.makedirs(gopher_entries) subprocess.call(["ln", "-s", gopher_entries, ttbp_gopher]) + +def unpublish(): + """blanks all gopher things and recreates the directories.""" + + subprocess.call(["rm", "-rf", config.GOPHER_PATH]) + subprocess.call(["rm", "-rf", config.GOPHER_ENTRIES]) + os.mkdir(config.GOPHER_ENTRIES) + subprocess.call(["ln", "-s", config.GOPHER_ENTRIES, config.GOPHER_PATH]) diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index e92d1db..2c13d88 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -926,6 +926,7 @@ type the following purge code: print("...") time.sleep(0.5) unpublish() + if not subprocess.call(["rm", "-rf", config.MAIN_FEELS]): subprocess.call(["mkdir", config.MAIN_FEELS]) core.load_files() @@ -984,10 +985,12 @@ purge code: print("...") time.sleep(0.5) unpublish() - publishDir = os.path.join(config.PUBLIC, SETTINGS.get("publish dir")) - if os.path.exists(publishDir): - subprocess.call(["rm", "-rf", publishDir]) - + + if core.publishing(): + publishDir = os.path.join(config.PUBLIC, SETTINGS.get("publish dir")) + make_publish_dir(publishDir) + + if not subprocess.call(["rm", "-rf", config.PATH]): print(""" account deleted! if you ever want to come back, you're always welcome to start @@ -1525,12 +1528,12 @@ def unpublish(): publishDir = os.path.join(config.PUBLIC, directory) if os.path.exists(publishDir): subprocess.call(["rm", "-rf", publishDir]) - #make_publish_dir(directory) + subprocess.call(["rm", "-rf", config.WWW]) + make_publish_dir(SETTINGS.get("publish dir")) #SETTINGS.update({"publish dir": None}) if SETTINGS.get("gopher"): - #SETTINGS.update({"gopher": False}) - subprocess.call(["rm", config.GOPHER_PATH]) + gopher.unpublish() def update_publishing(): ''' @@ -1553,7 +1556,7 @@ def update_publishing(): core.load(SETTINGS) -def make_publish_dir(dir): +def make_publish_dir(publish_dir): ''' setup helper to create publishing directory ''' @@ -1566,13 +1569,18 @@ def make_publish_dir(dir): index.write("

ttbp blog placeholder

") index.close() - publishDir = os.path.join(config.PUBLIC, dir) - if os.path.exists(publishDir): - subprocess.call(["rm", publishDir]) + if core.publishing(): + live = os.path.join(config.PUBLIC, publish_dir) + if os.path.exists(live): + subprocess.call(["rm", live]) - subprocess.call(["ln", "-s", config.WWW, publishDir]) + subprocess.call(["ln", "-s", config.WWW, live]) - print("\n\tpublishing to "+config.LIVE+config.USER+"/"+SETTINGS.get("publish dir")+"/\n\n") + return "\n\tpublishing to "+config.LIVE+config.USER+"/"+SETTINGS.get("publish dir")+"/\n\n" + + else: + return "" + #print("\n\tpublishing to "+config.LIVE+config.USER+"/"+SETTINGS.get("publish dir")+"/\n\n") def update_gopher(): '''