nopub option complete, closes #6
parent
75b224e2d1
commit
9f8cc02f6c
59
ttbp/core.py
59
ttbp/core.py
|
@ -48,6 +48,7 @@ SETTINGS = {}
|
||||||
HEADER = ""
|
HEADER = ""
|
||||||
FOOTER = ""
|
FOOTER = ""
|
||||||
FILES = []
|
FILES = []
|
||||||
|
NOPUBS = []
|
||||||
|
|
||||||
def load(ttbprc={}):
|
def load(ttbprc={}):
|
||||||
'''
|
'''
|
||||||
|
@ -62,6 +63,7 @@ def load(ttbprc={}):
|
||||||
FOOTER = open(os.path.join(config.USER_CONFIG, "footer.txt")).read()
|
FOOTER = open(os.path.join(config.USER_CONFIG, "footer.txt")).read()
|
||||||
SETTINGS = ttbprc
|
SETTINGS = ttbprc
|
||||||
|
|
||||||
|
load_nopubs()
|
||||||
load_files()
|
load_files()
|
||||||
|
|
||||||
def reload_ttbprc(ttbprc={}):
|
def reload_ttbprc(ttbprc={}):
|
||||||
|
@ -105,8 +107,23 @@ def load_files():
|
||||||
|
|
||||||
global FILES
|
global FILES
|
||||||
|
|
||||||
|
load_nopubs()
|
||||||
FILES = get_files()
|
FILES = get_files()
|
||||||
|
|
||||||
|
def load_nopubs():
|
||||||
|
"""Load a list of the user's nopub entries.
|
||||||
|
"""
|
||||||
|
|
||||||
|
global NOPUBS
|
||||||
|
|
||||||
|
NOPUBS = []
|
||||||
|
|
||||||
|
if os.path.isfile(config.NOPUB):
|
||||||
|
for line in open(config.NOPUB, "r"):
|
||||||
|
if not re.match("^# ", line):
|
||||||
|
NOPUBS.append(line.rstrip())
|
||||||
|
|
||||||
|
return len(NOPUBS)
|
||||||
|
|
||||||
## html outputting
|
## html outputting
|
||||||
|
|
||||||
|
@ -417,19 +434,45 @@ def nopub(filename):
|
||||||
checks to see if given filename is in user's NOPUB
|
checks to see if given filename is in user's NOPUB
|
||||||
'''
|
'''
|
||||||
|
|
||||||
exclude = []
|
return os.path.basename(filename) in NOPUBS
|
||||||
|
|
||||||
if os.path.isfile(config.NOPUB):
|
|
||||||
for line in open(config.NOPUB, "r"):
|
|
||||||
exclude.append(line.rstrip())
|
|
||||||
|
|
||||||
return os.path.basename(filename) in exclude
|
|
||||||
|
|
||||||
def toggle_nopub(filename):
|
def toggle_nopub(filename):
|
||||||
"""toggles pub/nopub status for the given filename
|
"""toggles pub/nopub status for the given filename
|
||||||
|
|
||||||
|
if the file is to be unpublished, delete it from published locations
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
global NOPUBS
|
||||||
|
|
||||||
|
action = "unpublishing"
|
||||||
|
|
||||||
|
if nopub(filename):
|
||||||
|
NOPUBS.remove(filename)
|
||||||
|
live_html = os.path.join(config.WWW, filename.split(".")[0]+".html")
|
||||||
|
if os.path.exists(live_html):
|
||||||
|
subprocess.call(["rm", live_html])
|
||||||
|
live_gopher = os.path.join(config.GOPHER_PATH, filename)
|
||||||
|
if os.path.exists(live_gopher):
|
||||||
|
subprocess.call(["rm", live_gopher])
|
||||||
|
else:
|
||||||
|
action = "publishing"
|
||||||
|
NOPUBS.append(filename)
|
||||||
|
|
||||||
|
nopub_file = open(config.NOPUB, 'w')
|
||||||
|
nopub_file.write("""\
|
||||||
|
# files that don't get published html/gopher. this file is
|
||||||
|
# generated by ttbp; editing it directly may result in unexpected
|
||||||
|
# behavior. if you have problems, back up this file, delete it, and
|
||||||
|
# rebuild it from ttbp.\n""")
|
||||||
|
for entry in NOPUBS:
|
||||||
|
nopub_file.write(entry+"\n")
|
||||||
|
nopub_file.close()
|
||||||
|
|
||||||
|
load_files()
|
||||||
|
write("index.html")
|
||||||
|
|
||||||
|
return action
|
||||||
|
|
||||||
|
|
||||||
#############
|
#############
|
||||||
#############
|
#############
|
||||||
|
|
11
ttbp/ttbp.py
11
ttbp/ttbp.py
|
@ -820,23 +820,24 @@ def list_nopubs(user):
|
||||||
pub = "(nopub)"
|
pub = "(nopub)"
|
||||||
entries.append(""+entry[4]+" ("+p.no("word", entry[2])+") "+"\t"+pub)
|
entries.append(""+entry[4]+" ("+p.no("word", entry[2])+") "+"\t"+pub)
|
||||||
|
|
||||||
return set_nopubs(metas, entries, "publishing status of your feels:")
|
return set_nopubs(metas, entries, user, "publishing status of your feels:")
|
||||||
else:
|
else:
|
||||||
redraw("no feels recorded by ~"+user)
|
redraw("no feels recorded by ~"+user)
|
||||||
|
|
||||||
def set_nopubs(metas, entries, prompt):
|
def set_nopubs(metas, entries, user, prompt):
|
||||||
"""displays a list of entries for pub/nopub toggling.
|
"""displays a list of entries for pub/nopub toggling.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
choice = menu_handler(entries, "pick an entry from the list, or type 'q' to go back: ", 10, SETTINGS.get("rainbows", False), prompt)
|
choice = menu_handler(entries, "pick an entry from the list, or type 'q' to go back: ", 10, SETTINGS.get("rainbows", False), prompt)
|
||||||
|
|
||||||
if choice is not False:
|
if choice is not False:
|
||||||
target = os.path.basename(metas[choice][0])
|
target = os.path.basename(metas[choice][0])
|
||||||
core.toggle_nopub(target)
|
action = core.toggle_nopub(target)
|
||||||
redraw(prompt)
|
redraw(prompt)
|
||||||
print("setting {entry}".format(entry=target))
|
#print("{action} {entry}".format(action=action, entry=target))
|
||||||
|
|
||||||
return set_nopubs(metas, entries, prompt)
|
return list_nopubs(user)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
redraw()
|
redraw()
|
||||||
|
|
Loading…
Reference in New Issue