implemented feels deletion, this clears a big chunk of issue #26

master
Vincent Zeng 2018-03-16 00:39:27 -04:00
parent fc08cfbfde
commit 8aa0492811
2 changed files with 10 additions and 19 deletions

View File

@ -85,19 +85,10 @@ def get_files(feelsdir=config.MAIN_FEELS):
for filename in os.listdir(feelsdir): for filename in os.listdir(feelsdir):
if nopub(filename): if nopub(filename):
unpublish_feel(filename) unpublish_feel(filename)
continue else:
''' filename = os.path.join(feelsdir, filename)
link = os.path.join(config.WWW, if os.path.isfile(filename) and valid(filename):
os.path.splitext( files.append(filename)
os.path.basename(filename))[0]+".html")
if os.path.exists(link):
subprocess.call(["rm", link])
continue
'''
filename = os.path.join(feelsdir, filename)
if os.path.isfile(filename) and valid(filename):
files.append(filename)
files.sort() files.sort()
files.reverse() files.reverse()
@ -110,7 +101,7 @@ def load_files(feelsdir=config.MAIN_FEELS):
* reads user's nopub file * reads user's nopub file
* calls get_files() to load all files for given directory * calls get_files() to load all files for given directory
* re-renders main html file * re-renders main html file and/or gopher if needed
''' '''
global FILES global FILES
@ -465,8 +456,6 @@ def toggle_nopub(filename):
nopub_file.close() nopub_file.close()
load_files() load_files()
#write_html("index.html")
#gopher.publish_gopher('feels', FILES)
return action return action
@ -480,7 +469,10 @@ def delete_feel(filename):
"""deletes given filename; removes the feel from publicly-readable """deletes given filename; removes the feel from publicly-readable
locations, then deletes the original file.""" locations, then deletes the original file."""
pass feel = os.path.join(config.MAIN_FEELS, filename)
if os.path.exists(feel):
subprocess.call(["rm", feel])
load_files(config.MAIN_FEELS)
def unpublish_feel(filename): def unpublish_feel(filename):
"""takes given filename and removes it from public_html and gopher_html, if """takes given filename and removes it from public_html and gopher_html, if
@ -488,9 +480,7 @@ def unpublish_feel(filename):
live_html = os.path.join(config.WWW, live_html = os.path.join(config.WWW,
os.path.splitext(os.path.basename(filename))[0]+".html") os.path.splitext(os.path.basename(filename))[0]+".html")
#live_html = os.path.join(config.WWW, filename.split(".")[0]+".html")
if os.path.exists(live_html): if os.path.exists(live_html):
print(live_html)
subprocess.call(["rm", live_html]) subprocess.call(["rm", live_html])
live_gopher = os.path.join(config.GOPHER_PATH, filename) live_gopher = os.path.join(config.GOPHER_PATH, filename)
if os.path.exists(live_gopher): if os.path.exists(live_gopher):

View File

@ -853,6 +853,7 @@ type the date again to confirm, or q to cancel.""")
if confirm == feel: if confirm == feel:
print("...") print("...")
time.sleep(1) time.sleep(1)
core.delete_feel(feel+".txt")
print("feels deleted!") print("feels deleted!")
else: else:
print("deletion canceled!") print("deletion canceled!")