consolidate variables in config module
parent
e910ce5518
commit
ab17642361
|
@ -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 = '''
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>$USER on TTBP</title>
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="meta">
|
||||
<h1><a href="#">~$USER</a>@<a href="/~endorphant/ttbp">TTBP</a></h1>
|
||||
</div>
|
||||
|
||||
<div id="tlogs">
|
||||
'''.ltrim()
|
||||
|
||||
DEFAULT_FOOTER = '''
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
'''.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()
|
|
@ -1,8 +0,0 @@
|
|||
__________________________________________________________
|
||||
| |
|
||||
| the tilde.town |
|
||||
| ____ ____ ____ _ ____ ____ _ _ ____ _ _ _ ____ |
|
||||
| |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ |
|
||||
| | |___ |___ |___ ___] |___ | \| |__] | | \| |___ |
|
||||
| ver 0.9.2 (almost stable) |
|
||||
|__________________________________________________________|
|
45
ttbp/core.py
45
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("<!--generated by the tilde.town blogging platform on "+time.strftime("%d %B %y")+"\nhttp://tilde.town/~endorphant/ttbp/-->\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("<!--generated by the tilde.town blogging platform on "+time.strftime("%d %B %y")+"\nhttp://tilde.town/~endorphant/ttbp/-->\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("""\
|
||||
<div class="docs">""")
|
||||
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("""\
|
||||
</div>""")
|
||||
|
||||
|
@ -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
|
||||
|
|
150
ttbp/ttbp.py
150
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 <endorphant@tilde.town)"
|
||||
|
||||
## system globals
|
||||
SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin")
|
||||
LIVE = "http://tilde.town/~"
|
||||
FEEDBACK = os.path.join("/home", "endorphant", "ttbp-mail")
|
||||
FEEDBOX = "endorphant@tilde.town"
|
||||
USERFILE = os.path.join("/home", "endorphant", "projects", "ttbp", "users.txt")
|
||||
GRAFF_DIR = os.path.join(SOURCE, "graffiti")
|
||||
WALL = os.path.join(GRAFF_DIR, "wall.txt")
|
||||
WALL_LOCK = os.path.join(GRAFF_DIR, ".lock")
|
||||
|
||||
p = inflect.engine()
|
||||
|
||||
## user globals
|
||||
USER = os.path.basename(os.path.expanduser("~"))
|
||||
PATH = os.path.join("/home", USER, ".ttbp")
|
||||
PUBLIC = os.path.join("/home", USER, "public_html")
|
||||
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": "none",
|
||||
"publish dir": False
|
||||
}
|
||||
|
||||
## ui globals
|
||||
BANNER = util.attach_rainbow()+open(os.path.join(SOURCE, "config", "banner.txt")).read()+util.attach_reset()
|
||||
BANNER = util.attach_rainbow() + config.BANNER + util.attach_reset()
|
||||
SPACER = "\n"
|
||||
INVALID = "please pick a number from the list of options!\n\n"
|
||||
DUST = "sorry about the dust, but this part is still under construction. check back later!\n\n"
|
||||
|
@ -231,14 +215,14 @@ def check_init():
|
|||
|
||||
print("\n\n")
|
||||
if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")):
|
||||
print(chatter.say("greet")+", "+USER+".\n")
|
||||
print(chatter.say("greet")+", "+config.USER+".\n")
|
||||
|
||||
'''
|
||||
## ttbprc validation
|
||||
while not os.path.isfile(TTBPRC):
|
||||
while not os.path.isfile(config.TTBPRC):
|
||||
setup_repair()
|
||||
try:
|
||||
SETTINGS = json.load(open(TTBPRC))
|
||||
SETTINGS = json.load(open(config.TTBPRC))
|
||||
except ValueError:
|
||||
setup_repair()
|
||||
'''
|
||||
|
@ -281,28 +265,30 @@ press <enter> to begin, or <ctrl-c> 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():
|
|||
<html>
|
||||
<head>
|
||||
<!--- this header automatically generated by ttbp initialization on """+time.strftime("%Y-%m-%d %h:m")+""" --->
|
||||
<title>~"""+USER+""" on TTBP</title>
|
||||
<title>~"""+config.USER+""" on TTBP</title>
|
||||
<link rel=\"stylesheet\" href=\"style.css\" />
|
||||
</head>
|
||||
<body>
|
||||
<div id=\"meta\">
|
||||
<h1><a href=\"index.html#\">~"""+USER+"""</a>@<a href=\"/~endorphant/ttbp\">TTBP</a></h1>
|
||||
<h1><a href=\"index.html#\">~"""+config.USER+"""</a>@<a href=\"/~endorphant/ttbp\">TTBP</a></h1>
|
||||
</div>
|
||||
|
||||
<!---put your custom html here-->
|
||||
|
@ -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 <enter> 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("<h1>ttbp blog placeholder</h1>")
|
||||
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()
|
||||
|
||||
|
|
|
@ -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']
|
||||
|
|
Loading…
Reference in New Issue