cleaning up gopher publishing + more verbose docs

master
endorphant 2017-12-04 23:18:42 -05:00
parent e3669b8135
commit 9fd7b8020e
2 changed files with 32 additions and 16 deletions

View File

@ -4,22 +4,28 @@ This module contains gopher-related stuff.
import getpass
import os
import time
import subprocess
from . import util
from .core import parse_date
GOPHER_PROMPT = """
Would you like to publish your feels to gopher?
gopher is a pre-web technology that is text-oriented and primarily used to
share folders of your files with the world.
Would you like to publish your feels to gopher?
Entries you write will automatically get linked to ~/public_gopher/feels/,
including gophermap generation. Files you manually delete will no longer be
visible from your gopherhole, and will be purged from your gophermap on your
next entry update.
If you don't know what it is or don't want it that is totally ok!
You can always change this later.""".lstrip()
GOPHERMAP_HEADER = """
welcome to {user}'s feels on gopher.
welcome to {user}'s gopherfeels.
.:: .::
.: .::
@ -29,12 +35,12 @@ GOPHERMAP_HEADER = """
.:: .: .: .:: .::
.:: .:::: .:::: .:::.:: .::
this file was created on their behalf by ttbp.
this file is automatically generated by ttbp.
0(about ttbp)\t/~endorphant/ttbp.txt\ttilde.town\t70
1(back to user's home)\t/~{user}
entries:
entries:
"""
@ -52,7 +58,7 @@ def publish_gopher(gopher_path, entry_filenames):
gopher_path)
if not os.path.isdir(ttbp_gopher):
print('\n\tERROR: something is wrong. your gopher directory is missing. re-enable gopher publishing.')
print('\n\tERROR: something is wrong. your gopher directory is missing. re-enable gopher publishing from the settings menu to fix this up!')
return
with open(os.path.join(ttbp_gopher, 'gophermap'), 'w') as gophermap:
@ -61,11 +67,15 @@ 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
subprocess.call(["ln", "-s", entry_filename, os.path.join(ttbp_gopher, os.path.basename(entry_fileNAME))])
#label = time.strftime("%Y-%m-%d at %H:%M", time.localtime(os.path.getmtime(entry_filename)))
label = "-".join(parse_date(entry_filename))
gophermap.write('0{file_label}\t{filename}\n'.format(
file_label=label,
@ -75,8 +85,8 @@ def publish_gopher(gopher_path, entry_filenames):
def setup_gopher(gopher_path):
"""Given a path relative to ~/public_gopher, this function:
- creates a directory under public_gopher
- creates a landing page
- creates a directory ~/.ttbp/gopher
- symlinks that directory to ~/public_gopher/{gopher_path}
It doesn't create a gophermap as that is left to the publish_gopher
function.
@ -91,4 +101,8 @@ def setup_gopher(gopher_path):
print("\n\tERROR: gopher path is already set up. quitting so we don't overwrite anything.")
return
os.makedirs(ttbp_gopher)
#os.makedirs(ttbp_gopher)
gopher_entries = os.path.join(os.path.expanduser("~/.ttbp"), "gopher")
os.makedirs(gopher_entries)
subprocess.call(["ln", "-s", gopher_entries, ttbp_gopher])

View File

@ -354,6 +354,9 @@ def valid_setup():
if not os.path.exists(os.path.join(config.WWW, SETTINGS.get("pubish dir"))):
return False
if not SETTINGS.get("gopher"):
return False
return True
def setup_repair():
@ -376,9 +379,9 @@ def setup():
master setup function
* editor selection
* publishing toggle
* publish/unpublish as needed
* publishing toggle (publish/unpublish as needed)
* directory selection
* gopher opt in/out
TODO: break this out better?
'''
@ -661,15 +664,13 @@ def show_credits():
'''
print("""
ttbp was written by ~endorphant in python. the codebase is
ttbp was written for tilde.town by ~endorphant in python. the codebase is
publicly available on github at https://github.com/modgethanc/ttbp
other contributors:
~vilmibm, packaging help and gopher support
~sanqui, the bug swatter
for the full changelog, see ~endorphant/projects/ttbp/changelog.txt
if you have ideas for ttbp, you are welcome to contact me to discuss them;
please send me tildemail or open a github issue. i am not a very experienced
developer, and ttbp is one of my first public-facing projects, so i appreciate
@ -719,8 +720,9 @@ editor.
core.write("index.html")
left = "posted to "+config.LIVE+config.USER+"/"+str(SETTINGS.get("publish dir"))+"/index.html\n\n>"
if SETTINGS['gopher']:
if SETTINGS.get('gopher'):
gopher.publish_gopher('feels', core.get_files())
left += "also posted to your ~/public_gopher!"
redraw(left + " thanks for sharing your feels!")
return