From 844d10304116aa18e25f604d77f70e65e8b83f97 Mon Sep 17 00:00:00 2001 From: Vincent Zeng Date: Sun, 31 Dec 2017 13:40:20 -0500 Subject: [PATCH] making some gopher directory adjustments --- ttbp/config/__init__.py | 1 + ttbp/gopher.py | 13 +++++-------- ttbp/ttbp.py | 11 +++++++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ttbp/config/__init__.py b/ttbp/config/__init__.py index 6c64ef5..227e642 100644 --- a/ttbp/config/__init__.py +++ b/ttbp/config/__init__.py @@ -67,6 +67,7 @@ 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_PATH = os.path.join(USER_HOME, 'public_gopher', 'feels') USER_CONFIG = os.path.join(PATH, 'config') TTBPRC = os.path.join(USER_CONFIG, 'ttbprc') USER_DATA = os.path.join(PATH, 'entries') diff --git a/ttbp/gopher.py b/ttbp/gopher.py index be8fcc0..37c7129 100644 --- a/ttbp/gopher.py +++ b/ttbp/gopher.py @@ -70,13 +70,6 @@ def publish_gopher(gopher_path, entry_filenames): for entry_filename in entry_filenames: filename = os.path.basename(entry_filename) - ''' old file copying bit - with open(os.path.join(ttbp_gopher, filename), 'w') as gopher_entry: - with open(entry_filename, 'r') as source_entry: - gopher_entry.write(source_entry.read()) - ''' - # symlink instead - 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]) @@ -86,7 +79,6 @@ def publish_gopher(gopher_path, entry_filenames): file_label=label, filename=filename)) - def setup_gopher(gopher_path): """Given a path relative to ~/public_gopher, this function: @@ -97,11 +89,16 @@ def setup_gopher(gopher_path): function. """ public_gopher = os.path.expanduser('~/public_gopher') + if not os.path.isdir(public_gopher): + """ print("\n\tERROR: you don't seem to have gopher set up (no public_gopher directory)") return + """ + os.makedirs(public_gopher) ttbp_gopher = os.path.join(public_gopher, gopher_path) + if os.path.isdir(ttbp_gopher): print("\n\tERROR: gopher path is already set up. quitting so we don't overwrite anything.") return diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index 185650c..74a89c3 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -1014,14 +1014,21 @@ please enter\ return publish def unpublish(): + '''remove all published entries in html and gopher. ''' - remove user's published directory, if it exists. this should only remove the symlink in public_html. - ''' + + global SETTINGS + directory = SETTINGS.get("publish dir") + if directory: publishDir = os.path.join(config.PUBLIC, directory) subprocess.call(["rm", publishDir]) + if SETTINGS.get("gopher"): + SETTINGS.update({"gopher": False}) + subprocess.call(["rm", config.GOPHER_PATH]) + def update_publishing(): ''' updates publishing directory if user is publishing. otherwise, wipe it.