From c44860dc7290d2b0bce20823e7124c432b64129d Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Mon, 20 Nov 2017 18:07:12 -0800 Subject: [PATCH 1/8] remove stray symlink --- bin/www | 1 - 1 file changed, 1 deletion(-) delete mode 120000 bin/www diff --git a/bin/www b/bin/www deleted file mode 120000 index 61882c2..0000000 --- a/bin/www +++ /dev/null @@ -1 +0,0 @@ -/home/endorphant/public_html/ttbp/ \ No newline at end of file From 576383413263430afc80fa7b2e289e145f87b5a4 Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Mon, 20 Nov 2017 18:48:32 -0800 Subject: [PATCH 2/8] create setup.py and ttbp package --- setup.py | 30 +++++++++++ ttbp/__init__.py | 0 {bin => ttbp}/_ttbp.py | 0 ttbp/chatter.py | 69 ++++++++++++++++++++++++ {bin => ttbp}/config/banner-beta.txt | 0 {bin => ttbp}/config/banner.txt | 0 {bin => ttbp}/config/defaults/footer.txt | 0 {bin => ttbp}/config/defaults/header.txt | 0 {bin => ttbp}/config/defaults/style.css | 0 {bin => ttbp}/core.py | 0 {bin => ttbp}/ttbp.py | 10 ++-- {bin => ttbp}/update.py | 0 {bin => ttbp}/util.py | 0 13 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 setup.py create mode 100644 ttbp/__init__.py rename {bin => ttbp}/_ttbp.py (100%) create mode 100644 ttbp/chatter.py rename {bin => ttbp}/config/banner-beta.txt (100%) rename {bin => ttbp}/config/banner.txt (100%) rename {bin => ttbp}/config/defaults/footer.txt (100%) rename {bin => ttbp}/config/defaults/header.txt (100%) rename {bin => ttbp}/config/defaults/style.css (100%) rename {bin => ttbp}/core.py (100%) rename {bin => ttbp}/ttbp.py (99%) rename {bin => ttbp}/update.py (100%) rename {bin => ttbp}/util.py (100%) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..da9d421 --- /dev/null +++ b/setup.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +from setuptools import setup + +setup( + name='ttbp', + version='0.10.0', + description='command line social blogging tool used on tilde.town', + url='https://github.com/modgethanc/ttbp', + author='~endorphant', + author_email='endorphant@tilde.town', + license='MIT', + classifiers=[ + 'Topic :: Artistic Software', + 'License :: OSI Approved :: MIT License', + ], + keywords='blog', + packages=['ttbp'], + install_requires = [ + 'inflect==0.2.5', + 'mistune==0.8.1' + ], + include_package_data = True, + entry_points = { + 'console_scripts': [ + 'feels = ttbp.ttbp:start', + 'ttbp = ttbp.ttbp:start', + ] + }, +) diff --git a/ttbp/__init__.py b/ttbp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bin/_ttbp.py b/ttbp/_ttbp.py similarity index 100% rename from bin/_ttbp.py rename to ttbp/_ttbp.py diff --git a/ttbp/chatter.py b/ttbp/chatter.py new file mode 100644 index 0000000..ed2bbda --- /dev/null +++ b/ttbp/chatter.py @@ -0,0 +1,69 @@ +import json +import os +import random + +DEFAULT_LANG = { + "greet":[ + "hi", + "hey", + "howdy", + "good morning", + "good afternoon", + "good day", + "good evening", + "welcome back", + "nice to see you" + ], + "bye":[ + "see you later, space cowboy", + "bye, townie", + "until next time, friend", + "come back whenever" + ], + "friend":[ + "friend", + "pal", + "buddy", + "townie" + ], + "months":{ + "01":"january", + "02":"february", + "03":"march", + "04":"april", + "05":"may", + "06":"june", + "07":"july", + "08":"august", + "09":"september", + "10":"october", + "11":"november", + "12":"december" + } +} + +if os.path.exists("/home/endorphant/lib/python/chatterlib.json"): + with open("/home/endorphant/lib/python/chatterlib.json", 'r') as f: + LANG = json.load(f) +else: + LANG = DEFAULT_LANG + +def say(keyword): + ''' + takes a keyword and randomly returns from language dictionary to match that keyword + + returns None if keyword doesn't exist + + TODO: validate keyword? + ''' + + return random.choice(LANG.get(keyword)) + +def month(num): + ''' + takes a MM and returns lovercase full name of that month + + TODO: validate num? + ''' + + return LANG["months"].get(num) diff --git a/bin/config/banner-beta.txt b/ttbp/config/banner-beta.txt similarity index 100% rename from bin/config/banner-beta.txt rename to ttbp/config/banner-beta.txt diff --git a/bin/config/banner.txt b/ttbp/config/banner.txt similarity index 100% rename from bin/config/banner.txt rename to ttbp/config/banner.txt diff --git a/bin/config/defaults/footer.txt b/ttbp/config/defaults/footer.txt similarity index 100% rename from bin/config/defaults/footer.txt rename to ttbp/config/defaults/footer.txt diff --git a/bin/config/defaults/header.txt b/ttbp/config/defaults/header.txt similarity index 100% rename from bin/config/defaults/header.txt rename to ttbp/config/defaults/header.txt diff --git a/bin/config/defaults/style.css b/ttbp/config/defaults/style.css similarity index 100% rename from bin/config/defaults/style.css rename to ttbp/config/defaults/style.css diff --git a/bin/core.py b/ttbp/core.py similarity index 100% rename from bin/core.py rename to ttbp/core.py diff --git a/bin/ttbp.py b/ttbp/ttbp.py similarity index 99% rename from bin/ttbp.py rename to ttbp/ttbp.py index bcfc0a5..28b8231 100644 --- a/bin/ttbp.py +++ b/ttbp/ttbp.py @@ -31,6 +31,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. the complete codebase is available at: https://github.com/modgethanc/ttbp ''' +from __future__ import absolute_import import os import random @@ -41,12 +42,13 @@ import json from email.mime.text import MIMEText; import re -import core -import chatter import inflect -import util -__version__ = "0.9.2" +from . import core +from . import chatter +from . import util + +__version__ = "0.10.0" __author__ = "endorphant Date: Mon, 20 Nov 2017 19:07:25 -0800 Subject: [PATCH 3/8] create a .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..abfbc72 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +*.swp +*.egg-info From ab17642361b656ea5cb364b504117f49624d89fe Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Mon, 20 Nov 2017 22:02:10 -0800 Subject: [PATCH 4/8] consolidate variables in config module --- ttbp/config/__init__.py | 82 ++++++++++++++++++++++ ttbp/config/banner.txt | 8 --- ttbp/core.py | 45 +++++------- ttbp/ttbp.py | 150 ++++++++++++++++++---------------------- ttbp/util.py | 6 +- 5 files changed, 171 insertions(+), 120 deletions(-) create mode 100644 ttbp/config/__init__.py delete mode 100644 ttbp/config/banner.txt diff --git a/ttbp/config/__init__.py b/ttbp/config/__init__.py new file mode 100644 index 0000000..6d8639d --- /dev/null +++ b/ttbp/config/__init__.py @@ -0,0 +1,82 @@ +from __future__ import absolute_import +import os + +from . import util + +## System config + +# We refer to some package files (ie .css stuff), so we save a reference to the +# path. +INSTALL_PATH = dirname(sys.modules['ttbp'].__file__) + +# We use this to store any persisted, global state. +VAR = '/var/global/ttbp' +VAR_WWW = os.path.join(VAR, 'www') + +if not os.path.isdir('/var/global'): + raise Exception('bad system state: /var/global does not exist.') + +if not os.path.isdir(VAR): + os.mkdir(VAR) + +if not os.path.isdir(VAR_WWW): + os.mkdir(VAR_WWW) + +LIVE = 'https://tilde.town/~' +FEEDBOX = "endorphant@tilde.town" +USERFILE = os.path.join(VAR, "users.txt") +GRAFF_DIR = os.path.join(VAR, "graffiti") +WALL = os.path.join(GRAFF_DIR, "wall.txt") +WALL_LOCK = os.path.join(GRAFF_DIR, ".lock") + +## Defaults + +DEFAULT_HEADER = ''' + + + + $USER on TTBP + + + +
+

~$USER@TTBP

+
+ +
+'''.ltrim() + +DEFAULT_FOOTER = ''' +
+ + +'''.ltrim() + +with open(os.path.join(INSTALL_PATH, 'config', 'defaults', 'style.css')) as f: + DEFAULT_STYLE = f.read() + + +## User config + +USER = os.path.basename(os.path.expanduser('~')) +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') +USER_CONFIG = os.path.join(PATH, 'config') +TTBPRC = os.path.join(USER_CONFIG, 'ttbprc') +USER_DATA = os.path.join(PATH, 'entries') +NOPUB = os.path.join(USER_CONFIG, "nopub") + +## UI + +BANNER = ''' +__________________________________________________________ +| | +| the tilde.town | +| ____ ____ ____ _ ____ ____ _ _ ____ _ _ _ ____ | +| |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ | +| | |___ |___ |___ ___] |___ | \| |__] | | \| |___ | +| ver 0.10.0 (almost stable) | +|__________________________________________________________| +'''.ltrim() diff --git a/ttbp/config/banner.txt b/ttbp/config/banner.txt deleted file mode 100644 index 53f8893..0000000 --- a/ttbp/config/banner.txt +++ /dev/null @@ -1,8 +0,0 @@ - __________________________________________________________ -| | -| the tilde.town | -| ____ ____ ____ _ ____ ____ _ _ ____ _ _ _ ____ | -| |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ | -| | |___ |___ |___ ___] |___ | \| |__] | | \| |___ | -| ver 0.9.2 (almost stable) | -|__________________________________________________________| diff --git a/ttbp/core.py b/ttbp/core.py index 852883f..31f164d 100644 --- a/ttbp/core.py +++ b/ttbp/core.py @@ -39,19 +39,10 @@ import re import mistune import json -import chatter +from . import chatter +from . import config -SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin") -USER = os.path.basename(os.path.expanduser("~")) -PATH = os.path.join("/home", USER, ".ttbp") - -LIVE = "http://tilde.town/~" -WWW = os.path.join(PATH, "www") -CONFIG = os.path.join(PATH, "config") -DATA = os.path.join(PATH, "entries") -FEED = os.path.join(SOURCE, "www", "index.html") -DOCS = os.path.join(SOURCE, "www", "help.html") -NOPUB = os.path.join(CONFIG, "nopub") +FEED = os.path.join(config.VAR_WWW, "index.html") SETTINGS = {} HEADER = "" @@ -67,8 +58,8 @@ def load(ttbprc={}): global FOOTER global SETTINGS - HEADER = open(os.path.join(CONFIG, "header.txt")).read() - FOOTER = open(os.path.join(CONFIG, "footer.txt")).read() + HEADER = open(os.path.join(config.USER_CONFIG, "header.txt")).read() + FOOTER = open(os.path.join(config.USER_CONFIG, "footer.txt")).read() SETTINGS = ttbprc load_files() @@ -94,13 +85,13 @@ def load_files(): FILES = [] - for filename in os.listdir(DATA): + for filename in os.listdir(config.USER_DATA): if nopub(filename): - link = os.path.join(WWW, os.path.splitext(os.path.basename(filename))[0]+".html") + link = os.path.join(config.WWW, os.path.splitext(os.path.basename(filename))[0]+".html") if os.path.exists(link): subprocess.call(["rm", link]) continue - filename = os.path.join(DATA, filename) + filename = os.path.join(config.USER_DATA, filename) if os.path.isfile(filename) and valid(filename): FILES.append(filename) @@ -119,7 +110,7 @@ def write(outurl="default.html"): * calls write_page() on each file to make permalinks ''' - outfile = open(os.path.join(WWW, outurl), "w") + outfile = open(os.path.join(config.WWW, outurl), "w") outfile.write("\n\n") @@ -140,7 +131,7 @@ def write(outurl="default.html"): outfile.close() - return os.path.join(LIVE+USER,os.path.basename(os.path.realpath(WWW)),outurl) + return os.path.join(config.LIVE+config.USER,os.path.basename(os.path.realpath(config.WWW)),outurl) def write_page(filename): ''' @@ -150,7 +141,7 @@ def write_page(filename): url ''' - outurl = os.path.join(WWW, "".join(parse_date(filename))+".html") + outurl = os.path.join(config.WWW, "".join(parse_date(filename))+".html") outfile = open(outurl, "w") outfile.write("\n\n") @@ -190,7 +181,7 @@ def write_entry(filename): ] raw = [] - rawfile = open(os.path.join(DATA, filename), "r") + rawfile = open(os.path.join(config.USER_DATA, filename), "r") for line in rawfile: raw.append(line) @@ -244,7 +235,7 @@ def write_global_feed(blogList): ## docs outfile.write("""\
""") - outfile.write(mistune.markdown(open(os.path.join(SOURCE, "..", "README.md"), "r").read())) + outfile.write(mistune.markdown(open(os.path.join(config.INSTALL_PATH, "..", "README.md"), "r").read())) outfile.write("""\
""") @@ -354,14 +345,14 @@ def find_ttbps(): return users -def publishing(username = USER): +def publishing(username=config.USER): ''' checks .ttbprc for whether or not user opted for www publishing ''' ttbprc = {} - if username == USER: + if username == config.USER: ttbprc = SETTINGS else: @@ -384,7 +375,7 @@ def www_neighbors(): url = "" if userRC["publish dir"]: - url = LIVE+user+"/"+userRC["publish dir"] + url = config.LIVE+user+"/"+userRC["publish dir"] lastfile = "" files = os.listdir(os.path.join("/home", user, ".ttbp", "entries")) @@ -418,8 +409,8 @@ def nopub(filename): exclude = [] - if os.path.isfile(NOPUB): - for line in open(NOPUB, "r"): + if os.path.isfile(config.NOPUB): + for line in open(config.NOPUB, "r"): exclude.append(line.rstrip()) return os.path.basename(filename) in exclude diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index 28b8231..85bbdf5 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -44,6 +44,7 @@ import re import inflect +from . import config from . import core from . import chatter from . import util @@ -51,33 +52,16 @@ from . import util __version__ = "0.10.0" __author__ = "endorphant to begin, or to get out of here. quit() ## record user in source list - users = open(USERFILE, 'a') - users.write(USER+"\n") + users = open(config.USERFILE, 'a') + users.write(config.USER+"\n") users.close() ## make .ttbp directory structure - subprocess.call(["mkdir", PATH]) - subprocess.call(["mkdir", CONFIG]) - subprocess.call(["mkdir", DATA]) + subprocess.call(["mkdir", config.PATH]) + subprocess.call(["mkdir", config.USER_CONFIG]) + subprocess.call(["mkdir", config.USER_DATA]) - versionFile = os.path.join(PATH, "version") + versionFile = os.path.join(config.PATH, "version") open(versionFile, "w").write(__version__) ## create header file header = gen_header() - headerfile = open(os.path.join(CONFIG, "header.txt"), 'w') + headerfile = open(os.path.join(config.USER_CONFIG, "header.txt"), 'w') for line in header: headerfile.write(line) headerfile.close() ## copy footer and default stylesheet - subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "footer.txt"), CONFIG]) - subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "style.css"), CONFIG]) + with open(os.path.join(config.USER_CONFIG, 'footer.txt', 'w')) as f: + f.write(config.DEFAULT_FOOTER) + with open(os.path.join(config.USER_CONFIG, 'style.css', 'w')) as f: + f.write(config.DEFAULT_STYLE) ## run user-interactive setup and load core engine setup() @@ -323,12 +309,12 @@ def gen_header(): - ~"""+USER+""" on TTBP + ~"""+config.USER+""" on TTBP @@ -347,11 +333,11 @@ def valid_setup(): global SETTINGS - if not os.path.isfile(TTBPRC): + if not os.path.isfile(config.TTBPRC): return False try: - SETTINGS = json.load(open(TTBPRC)) + SETTINGS = json.load(open(config.TTBPRC)) except ValueError: return False @@ -359,10 +345,10 @@ def valid_setup(): if not SETTINGS.get("publish dir"): return False - if not os.path.exists(WWW): + if not os.path.exists(config.WWW): return False - if not os.path.exists(os.path.join(WWW, SETTINGS.get("pubish dir"))): + if not os.path.exists(os.path.join(config.WWW, SETTINGS.get("pubish dir"))): return False return True @@ -398,7 +384,7 @@ def setup(): print("\n\ttext editor:\t" +SETTINGS.get("editor")) if core.publishing(): - print("\tpublish dir:\t" +os.path.join(PUBLIC, str(SETTINGS.get("publish dir")))) + print("\tpublish dir:\t" +os.path.join(config.PUBLIC, str(SETTINGS.get("publish dir")))) print("\tpubishing:\t"+str(SETTINGS.get("publishing"))+"\n") # editor selection @@ -412,10 +398,10 @@ def setup(): redraw("blog publishing: "+str(core.publishing())) if core.publishing(): - print("publish directory: ~"+USER+"/public_html/"+SETTINGS.get("publish dir")) + print("publish directory: ~"+config.USER+"/public_html/"+SETTINGS.get("publish dir")) # save settings - ttbprc = open(TTBPRC, "w") + ttbprc = open(config.TTBPRC, "w") ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':'))) ttbprc.close() @@ -454,7 +440,7 @@ def main_menu(): if choice == '0': redraw() today = time.strftime("%Y%m%d") - write_entry(os.path.join(DATA, today+".txt")) + write_entry(os.path.join(config.USER_DATA, today+".txt")) core.www_neighbors() elif choice == '1': if core.publishing(): @@ -465,7 +451,7 @@ def main_menu(): core.write("index.html") else: redraw("your recorded feels, listed by date:") - view_feels(USER) + view_feels(config.USER) elif choice == '2': users = core.find_ttbps() prompt = "the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:" @@ -490,7 +476,7 @@ def main_menu(): redraw() show_credits() elif choice == '8': - subprocess.call(["lynx", os.path.join(SOURCE, "..", "README.html")]) + subprocess.call(["lynx", os.path.join(config.INSTALL_PATH, "..", "README.html")]) redraw() elif choice in QUITS: return stop() @@ -543,7 +529,7 @@ def review_menu(intro=""): if choice is not False: if choice == 0: redraw("your recorded feels, listed by date:") - view_feels(USER) + view_feels(config.USER) elif choice == 1: redraw("here's your current nopub status:") set_nopubs() @@ -570,7 +556,7 @@ def view_neighbors(users, prompt): ## retrieve publishing url, if it exists url="\t\t\t" if userRC.get("publish dir"): - url = LIVE+user+"/"+userRC.get("publish dir") + url = config.LIVE+user+"/"+userRC.get("publish dir") ## find last entry files = os.listdir(os.path.join("/home", user, ".ttbp", "entries")) @@ -630,8 +616,8 @@ def view_feels(townie): filenames = [] showpub = False - if townie == USER: - entryDir = DATA + if townie == config.USER: + entryDir = config.USER_DATA owner = "your" if core.publishing(): showpub = True @@ -685,7 +671,7 @@ thanks to everyone who reads, listens, writes, and feels.\ ## handlers -def write_entry(entry=os.path.join(DATA, "test.txt")): +def write_entry(entry=os.path.join(config.USER_DATA, "test.txt")): ''' main feels-recording handler ''' @@ -715,7 +701,7 @@ editor. if core.publishing(): core.load_files() core.write("index.html") - left = "posted to "+LIVE+USER+"/"+str(SETTINGS.get("publish dir"))+"/index.html\n\n>" + left = "posted to "+config.LIVE+config.USER+"/"+str(SETTINGS.get("publish dir"))+"/index.html\n\n>" redraw(left + " thanks for sharing your feels!") return @@ -745,8 +731,8 @@ def send_feedback(entered, subject="none"): if message: id = "#"+util.genID(3) mail = MIMEText(message) - mail['To'] = FEEDBOX - mail['From'] = USER+"@tilde.town" + mail['To'] = config.FEEDBOX + mail['From'] = config.USER+"@tilde.town" mail['Subject'] = " ".join(["[ttbp]", subject, id]) m = os.popen("/usr/sbin/sendmail -t -oi", 'w') m.write(mail.as_string()) @@ -838,10 +824,10 @@ def graffiti_handler(): Main graffiti handler. ''' - if os.path.isfile(WALL_LOCK): + if os.path.isfile(config.WALL_LOCK): redraw("sorry, "+chatter.say("friend")+", but someone's there right now. try again in a few!") else: - subprocess.call(["touch", WALL_LOCK]) + subprocess.call(["touch", config.WALL_LOCK]) redraw() print("""\ the graffiti wall is a world-writeable text file. anyone can @@ -855,8 +841,8 @@ your changes by exiting without saving. """) raw_input("press to visit the wall\n\n") - subprocess.call([SETTINGS.get("editor"), WALL]) - subprocess.call(["rm", WALL_LOCK]) + subprocess.call([SETTINGS.get("editor"), config.WALL]) + subprocess.call(["rm", config.WALL_LOCK]) redraw("thanks for visiting the graffiti wall!") @@ -886,14 +872,14 @@ def select_publish_dir(): republish = False if current: - print("\ncurrent publish dir:\t"+os.path.join(PUBLIC, SETTINGS["publish dir"])) + print("\ncurrent publish dir:\t"+os.path.join(config.PUBLIC, SETTINGS["publish dir"])) republish = True choice = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ") if not choice: choice = "blog" - publishDir = os.path.join(PUBLIC, choice) + publishDir = os.path.join(config.PUBLIC, choice) while os.path.exists(publishDir): second = raw_input("\n"+publishDir+"""\ already exists! @@ -907,7 +893,7 @@ otherwise, pick another location: """) if second == "": break choice = second - publishDir = os.path.join(PUBLIC, choice) + publishDir = os.path.join(config.PUBLIC, choice) return choice @@ -939,9 +925,9 @@ def unpublish(): remove user's published directory, if it exists. this should only remove the symlink in public_html. ''' - dir = SETTINGS.get("publish dir") + directory = SETTINGS.get("publish dir") if dir: - publishDir = os.path.join(PUBLIC, dir) + publishDir = os.path.join(config.PUBLIC, directory) subprocess.call(["rm", publishDir]) def update_publishing(): @@ -956,7 +942,7 @@ def update_publishing(): newDir = select_publish_dir() SETTINGS.update({"publish dir": newDir}) if oldDir: - subprocess.call(["rm", os.path.join(PUBLIC, oldDir)]) + subprocess.call(["rm", os.path.join(config.PUBLIC, oldDir)]) make_publish_dir(newDir) core.load_files() core.write("index.html") @@ -971,21 +957,21 @@ def make_publish_dir(dir): setup helper to create publishing directory ''' - if not os.path.exists(WWW): - subprocess.call(["mkdir", WWW]) - subprocess.call(["ln", "-s", os.path.join(CONFIG, "style.css"), os.path.join(WWW, "style.css")]) - subprocess.call(["touch", os.path.join(WWW, "index.html")]) - index = open(os.path.join(WWW, "index.html"), "w") + if not os.path.exists(config.WWW): + subprocess.call(["mkdir", config.WWW]) + subprocess.call(["ln", "-s", os.path.join(config.USER_CONFIG, "style.css"), os.path.join(config.WWW, "style.css")]) + subprocess.call(["touch", os.path.join(config.WWW, "index.html")]) + index = open(os.path.join(config.WWW, "index.html"), "w") index.write("

ttbp blog placeholder

") index.close() - publishDir = os.path.join(PUBLIC, dir) + publishDir = os.path.join(config.PUBLIC, dir) if os.path.exists(publishDir): subprocess.call(["rm", publishDir]) - subprocess.call(["ln", "-s", WWW, publishDir]) + subprocess.call(["ln", "-s", config.WWW, publishDir]) - print("\n\tpublishing to "+LIVE+USER+"/"+SETTINGS.get("publish dir")+"/\n\n") + print("\n\tpublishing to "+config.LIVE+config.USER+"/"+SETTINGS.get("publish dir")+"/\n\n") ##### PATCHING UTILITIES @@ -994,7 +980,7 @@ def build_mismatch(): checks to see if user's last run build is the same as this session ''' - versionFile = os.path.join(PATH, "version") + versionFile = os.path.join(config.PATH, "version") if not os.path.exists(versionFile): return False @@ -1020,7 +1006,7 @@ def switch_build(ver): print("\nswitching you over to the "+build+" version...\n") time.sleep(1) print("...") - versionFile = os.path.join(PATH, "version") + versionFile = os.path.join(config.PATH, "version") open(versionFile, "w").write(ver) time.sleep(1) #print("\nall good!\n") @@ -1030,7 +1016,7 @@ def updated(): checks to see if current user is up to the same version as system ''' - versionFile = os.path.join(PATH, "version") + versionFile = os.path.join(config.PATH, "version") if not os.path.exists(versionFile): return False @@ -1048,7 +1034,7 @@ def update_version(): global SETTINGS - versionFile = os.path.join(PATH, "version") + versionFile = os.path.join(config.PATH, "version") print("ttbp had some updates!") @@ -1065,22 +1051,22 @@ def update_version(): # change style.css location if core.publishing(): - if os.path.isfile(os.path.join(WWW, "style.css")): - subprocess.call(["mv", os.path.join(WWW, "style.css"), CONFIG]) + if os.path.isfile(os.path.join(config.WWW, "style.css")): + subprocess.call(["mv", os.path.join(config.WWW, "style.css"), config.USER_CONFIG]) # change www symlink - if os.path.exists(WWW): - subprocess.call(["rm", WWW]) + if os.path.exists(config.WWW): + subprocess.call(["rm", config.WWW]) - subprocess.call(["mkdir", WWW]) + subprocess.call(["mkdir", config.WWW]) - subprocess.call(["ln", "-s", os.path.join(CONFIG, "style.css"), os.path.join(WWW, "style.css")]) + subprocess.call(["ln", "-s", os.path.join(config.USER_CONFIG, "style.css"), os.path.join(config.WWW, "style.css")]) - publishDir = os.path.join(PUBLIC, SETTINGS.get("publish dir")) + publishDir = os.path.join(config.PUBLIC, SETTINGS.get("publish dir")) if os.path.exists(publishDir): subprocess.call(["rm", "-rf", publishDir]) - subprocess.call(["ln", "-s", WWW, os.path.join(PUBLIC, SETTINGS.get("publish dir"))]) + subprocess.call(["ln", "-s", config.WWW, os.path.join(config.PUBLIC, SETTINGS.get("publish dir"))]) # repopulate html files core.load_files() @@ -1090,7 +1076,7 @@ def update_version(): print("\nnew feature!\n") SETTINGS.update({"publishing":select_publishing()}) update_publishing() - ttbprc = open(TTBPRC, "w") + ttbprc = open(config.TTBPRC, "w") ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':'))) ttbprc.close() @@ -1102,7 +1088,7 @@ def update_version(): print("\nresetting your publishing settings...\n") SETTINGS.update({"publishing":select_publishing()}) update_publishing() - ttbprc = open(TTBPRC, "w") + ttbprc = open(config.TTBPRC, "w") ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':'))) ttbprc.close() diff --git a/ttbp/util.py b/ttbp/util.py index 269e692..567fa8c 100644 --- a/ttbp/util.py +++ b/ttbp/util.py @@ -23,11 +23,11 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' - -import inflect -import time import random +import time + import colorama +import inflect ## misc globals BACKS = ['back', 'b', 'q'] From bcb98bc8cbe97b784e2406a56d28acc0fb526199 Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Mon, 20 Nov 2017 22:03:34 -0800 Subject: [PATCH 5/8] add colorama to setup.py --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index da9d421..125194f 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,8 @@ setup( packages=['ttbp'], install_requires = [ 'inflect==0.2.5', - 'mistune==0.8.1' + 'mistune==0.8.1', + 'colorama==0.3.9', ], include_package_data = True, entry_points = { From 2e010088387383ab991aa89b92b0230e9ecfb0de Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Mon, 20 Nov 2017 22:08:13 -0800 Subject: [PATCH 6/8] fix version so version check conditionals don't break --- setup.py | 2 +- ttbp/ttbp.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 125194f..7ffc3dc 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup setup( name='ttbp', - version='0.10.0', + version='0.9.3', description='command line social blogging tool used on tilde.town', url='https://github.com/modgethanc/ttbp', author='~endorphant', diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index 85bbdf5..cfd0f01 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -49,7 +49,7 @@ from . import core from . import chatter from . import util -__version__ = "0.10.0" +__version__ = "0.9.3" __author__ = "endorphant Date: Mon, 20 Nov 2017 22:39:38 -0800 Subject: [PATCH 7/8] flurry of bugfixes --- ttbp/config/__init__.py | 14 +++++++++----- ttbp/ttbp.py | 9 ++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ttbp/config/__init__.py b/ttbp/config/__init__.py index 6d8639d..e363efe 100644 --- a/ttbp/config/__init__.py +++ b/ttbp/config/__init__.py @@ -1,13 +1,14 @@ from __future__ import absolute_import import os +import sys -from . import util +from .. import util ## System config # We refer to some package files (ie .css stuff), so we save a reference to the # path. -INSTALL_PATH = dirname(sys.modules['ttbp'].__file__) +INSTALL_PATH = os.path.dirname(sys.modules['ttbp'].__file__) # We use this to store any persisted, global state. VAR = '/var/global/ttbp' @@ -29,6 +30,9 @@ GRAFF_DIR = os.path.join(VAR, "graffiti") WALL = os.path.join(GRAFF_DIR, "wall.txt") WALL_LOCK = os.path.join(GRAFF_DIR, ".lock") +if not os.path.isdir(GRAFF_DIR): + os.mkdir(GRAFF_DIR) + ## Defaults DEFAULT_HEADER = ''' @@ -44,13 +48,13 @@ DEFAULT_HEADER = '''
-'''.ltrim() +'''.lstrip() DEFAULT_FOOTER = '''
-'''.ltrim() +'''.lstrip() with open(os.path.join(INSTALL_PATH, 'config', 'defaults', 'style.css')) as f: DEFAULT_STYLE = f.read() @@ -79,4 +83,4 @@ __________________________________________________________ | | |___ |___ |___ ___] |___ | \| |__] | | \| |___ | | ver 0.10.0 (almost stable) | |__________________________________________________________| -'''.ltrim() +'''.lstrip() diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index cfd0f01..271b355 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -285,9 +285,9 @@ press to begin, or to get out of here. headerfile.close() ## copy footer and default stylesheet - with open(os.path.join(config.USER_CONFIG, 'footer.txt', 'w')) as f: + with open(os.path.join(config.USER_CONFIG, 'footer.txt'), 'w') as f: f.write(config.DEFAULT_FOOTER) - with open(os.path.join(config.USER_CONFIG, 'style.css', 'w')) as f: + with open(os.path.join(config.USER_CONFIG, 'style.css'), 'w') as f: f.write(config.DEFAULT_STYLE) ## run user-interactive setup and load core engine @@ -924,9 +924,8 @@ def unpublish(): ''' remove user's published directory, if it exists. this should only remove the symlink in public_html. ''' - directory = SETTINGS.get("publish dir") - if dir: + if directory: publishDir = os.path.join(config.PUBLIC, directory) subprocess.call(["rm", publishDir]) @@ -1138,7 +1137,7 @@ ver 0.9.2 features: * things should otherwise be the same! * check out https://github.com/modgethanc/ttbp if you'd like to contribute. * takes advantage of new /var/global - """.ltrim()) + """.lstrip()) ##### From 5121650d23bc15abf6f152a1afe3df27ea4d15bc Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Mon, 20 Nov 2017 22:49:36 -0800 Subject: [PATCH 8/8] update changelog --- changelog.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.txt b/changelog.txt index f08e329..9ea9f65 100644 --- a/changelog.txt +++ b/changelog.txt @@ -25,6 +25,10 @@ TO-DO: ------ CHANGELOG: +ver 0.9.3 + -packaging + -easier to contribute to + ver 0.9.2 -paginated scrolling