2016-05-15 03:44:03 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2016-05-22 02:18:25 +00:00
|
|
|
'''
|
|
|
|
ttbp: tilde town blogging platform
|
|
|
|
(also known as the feels engine)
|
|
|
|
a console-based blogging program developed for tilde.town
|
|
|
|
copyright (c) 2016 ~endorphant (endorphant@tilde.town)
|
|
|
|
|
|
|
|
_ttbp.py:
|
|
|
|
the beta version of the main console interface
|
|
|
|
|
|
|
|
GNU GPL BOILERPLATE:
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
the complete codebase is available at:
|
|
|
|
https://github.com/modgethanc/ttbp
|
|
|
|
'''
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import tempfile
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
import json
|
|
|
|
from email.mime.text import MIMEText;
|
|
|
|
|
|
|
|
import core
|
|
|
|
import chatter
|
|
|
|
import inflect
|
|
|
|
import util
|
|
|
|
|
2016-05-27 18:08:45 +00:00
|
|
|
__version__ = "0.9.1b"
|
2016-05-22 05:12:47 +00:00
|
|
|
__author__ = "endorphant <endorphant@tilde.town)"
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
## system globals
|
|
|
|
SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin")
|
2016-06-02 07:46:19 +00:00
|
|
|
LIVE = "https://tilde.town/~"
|
2016-05-15 03:44:03 +00:00
|
|
|
FEEDBACK = os.path.join("/home", "endorphant", "ttbp-mail")
|
|
|
|
FEEDBOX = "endorphant@tilde.town"
|
|
|
|
USERFILE = os.path.join("/home", "endorphant", "projects", "ttbp", "users.txt")
|
2016-05-27 18:08:45 +00:00
|
|
|
GRAFF_DIR = os.path.join(SOURCE, "graffiti")
|
|
|
|
WALL = os.path.join(GRAFF_DIR, "wall.txt")
|
|
|
|
WALL_LOCK = os.path.join(GRAFF_DIR, ".lock")
|
2016-05-17 01:42:32 +00:00
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
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
|
2016-05-27 18:08:45 +00:00
|
|
|
BANNER = util.attach_rainbow()+open(os.path.join(SOURCE, "config", "banner-beta.txt")).read()+util.rainbow("\t~potentially volatile beta version~")+util.attach_reset()
|
2016-05-20 03:19:02 +00:00
|
|
|
SPACER = "\n"
|
2016-06-02 07:46:19 +00:00
|
|
|
INVALID = "please pick a number from the list of options!"
|
|
|
|
DUST = "sorry about the dust, but this part is still under construction. check back later!"
|
2016-05-15 03:44:03 +00:00
|
|
|
QUITS = ['exit', 'quit', 'q', 'x']
|
|
|
|
EJECT = "eject button fired! going home now."
|
2016-05-27 07:21:11 +00:00
|
|
|
RAINBOW = True
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
## ref
|
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
EDITORS = ["vim", "vi", "emacs", "pico", "nano", "ed"]
|
2016-05-15 03:44:03 +00:00
|
|
|
SUBJECTS = ["help request", "bug report", "feature suggestion", "general comment"]
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
def redraw(leftover=""):
|
2016-05-22 03:36:21 +00:00
|
|
|
'''
|
|
|
|
screen clearing
|
|
|
|
|
|
|
|
* clears the screen and reprints the banner, plus whatever leftover text to be hilights
|
|
|
|
'''
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
os.system("clear")
|
|
|
|
print(BANNER)
|
2016-06-01 02:42:03 +00:00
|
|
|
print("\t\ttoday is "+ time.strftime("%d %B %Y"))
|
2016-05-15 03:44:03 +00:00
|
|
|
print(SPACER)
|
|
|
|
if leftover:
|
|
|
|
print("> "+leftover+"\n")
|
|
|
|
|
|
|
|
def start():
|
2016-05-22 03:36:21 +00:00
|
|
|
'''
|
|
|
|
main engine head
|
|
|
|
|
|
|
|
* called on program start
|
|
|
|
* calls config check
|
|
|
|
* proceeds to main menu
|
|
|
|
* handles ^c and ^d ejects
|
|
|
|
'''
|
|
|
|
|
2016-05-16 04:49:36 +00:00
|
|
|
redraw()
|
|
|
|
print("""
|
2016-05-15 04:19:05 +00:00
|
|
|
if you don't want to be here at any point, press <ctrl-d> and it'll all go away.
|
|
|
|
just keep in mind that you might lose anything you've started here.\
|
|
|
|
""")
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
try:
|
2016-05-16 04:49:36 +00:00
|
|
|
print(check_init())
|
2016-05-15 03:44:03 +00:00
|
|
|
except EOFError:
|
|
|
|
print(stop())
|
2016-05-16 04:49:36 +00:00
|
|
|
return
|
|
|
|
|
2016-05-17 01:42:32 +00:00
|
|
|
##
|
2016-05-16 04:49:36 +00:00
|
|
|
redraw()
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
try:
|
|
|
|
print(main_menu())
|
|
|
|
except EOFError:
|
|
|
|
print(stop())
|
|
|
|
break
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
redraw(EJECT)
|
|
|
|
else:
|
|
|
|
break
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
def stop():
|
2016-05-22 03:36:21 +00:00
|
|
|
'''
|
|
|
|
closer
|
|
|
|
|
|
|
|
* prints ending text
|
|
|
|
'''
|
|
|
|
|
2016-05-16 04:49:36 +00:00
|
|
|
return "\n\n\t"+chatter.say("bye")+"\n\n"
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
def check_init():
|
2016-05-22 03:36:21 +00:00
|
|
|
'''
|
|
|
|
user handler
|
|
|
|
|
|
|
|
* checks for presence of ttbprc
|
|
|
|
* checks for last run version
|
|
|
|
'''
|
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
global SETTINGS
|
2016-05-22 03:36:21 +00:00
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
print("\n\n")
|
|
|
|
if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")):
|
|
|
|
print(chatter.say("greet")+", "+USER+".\n")
|
2016-05-22 03:36:21 +00:00
|
|
|
|
2016-06-10 02:42:08 +00:00
|
|
|
'''
|
2016-05-22 03:36:21 +00:00
|
|
|
## ttbprc validation
|
2016-05-20 03:19:02 +00:00
|
|
|
while not os.path.isfile(TTBPRC):
|
2016-05-27 07:21:11 +00:00
|
|
|
setup_repair()
|
2016-05-20 03:19:02 +00:00
|
|
|
try:
|
|
|
|
SETTINGS = json.load(open(TTBPRC))
|
|
|
|
except ValueError:
|
2016-05-27 07:21:11 +00:00
|
|
|
setup_repair()
|
2016-06-10 02:42:08 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
## ttbp env validation
|
|
|
|
if not valid_setup():
|
|
|
|
setup_repair()
|
2016-05-20 03:19:02 +00:00
|
|
|
|
2016-05-27 18:08:45 +00:00
|
|
|
## version checker
|
|
|
|
mismatch = build_mismatch()
|
|
|
|
if mismatch is not False:
|
|
|
|
switch_build(mismatch)
|
2016-05-20 03:19:02 +00:00
|
|
|
if not updated():
|
2016-05-23 02:30:59 +00:00
|
|
|
update_version()
|
2016-05-20 03:19:02 +00:00
|
|
|
|
2016-05-22 03:36:21 +00:00
|
|
|
## when ready, enter main program and load core engine
|
2016-05-20 03:19:02 +00:00
|
|
|
raw_input("press <enter> to explore your feels.\n\n")
|
2016-05-27 07:21:11 +00:00
|
|
|
core.load(SETTINGS)
|
2016-05-20 03:19:02 +00:00
|
|
|
|
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
return init()
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
def init():
|
2016-05-22 03:36:21 +00:00
|
|
|
'''
|
|
|
|
new user creation
|
|
|
|
|
|
|
|
* introduces user
|
|
|
|
* calls setup functinos
|
|
|
|
'''
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
try:
|
2016-05-15 04:19:05 +00:00
|
|
|
raw_input("""
|
|
|
|
i don't recognize you, stranger. let's make friends.
|
|
|
|
|
2016-05-22 04:45:04 +00:00
|
|
|
press <enter> to begin, or <ctrl-c> to get out of here.
|
2016-05-15 04:19:05 +00:00
|
|
|
""")
|
2016-05-15 03:44:03 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("\n\nthanks for checking in! i'll always be here.\n\n")
|
|
|
|
quit()
|
|
|
|
|
2016-05-22 03:36:21 +00:00
|
|
|
## record user in source list
|
2016-05-15 03:44:03 +00:00
|
|
|
users = open(USERFILE, 'a')
|
|
|
|
users.write(USER+"\n")
|
|
|
|
users.close()
|
2016-05-22 03:36:21 +00:00
|
|
|
|
|
|
|
## make .ttbp directory structure
|
2016-05-15 03:44:03 +00:00
|
|
|
subprocess.call(["mkdir", PATH])
|
|
|
|
subprocess.call(["mkdir", CONFIG])
|
|
|
|
subprocess.call(["mkdir", DATA])
|
2016-05-15 04:19:05 +00:00
|
|
|
|
2016-05-22 03:36:21 +00:00
|
|
|
## create header file
|
2016-05-15 03:44:03 +00:00
|
|
|
header = gen_header()
|
|
|
|
headerfile = open(os.path.join(CONFIG, "header.txt"), 'w')
|
|
|
|
for line in header:
|
|
|
|
headerfile.write(line)
|
|
|
|
headerfile.close()
|
2016-05-15 04:19:05 +00:00
|
|
|
|
2016-05-22 03:36:21 +00:00
|
|
|
## copy footer and default stylesheet
|
2016-05-15 03:44:03 +00:00
|
|
|
subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "footer.txt"), CONFIG])
|
2016-05-17 01:42:32 +00:00
|
|
|
subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "style.css"), CONFIG])
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-22 03:36:21 +00:00
|
|
|
## run user-interactive setup and load core engine
|
2016-05-15 03:44:03 +00:00
|
|
|
setup()
|
2016-05-27 07:21:11 +00:00
|
|
|
core.load(SETTINGS)
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def gen_header():
|
2016-05-22 03:36:21 +00:00
|
|
|
'''
|
|
|
|
header generator
|
|
|
|
|
|
|
|
builds header to insert username
|
|
|
|
'''
|
|
|
|
|
2016-05-22 04:45:04 +00:00
|
|
|
header ="""
|
2016-05-15 04:19:05 +00:00
|
|
|
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
|
|
|
|
<html>
|
|
|
|
<head>
|
2016-05-22 03:36:21 +00:00
|
|
|
<!--- this header automatically generated by ttbp initialization on """+time.strftime("%Y-%m-%d %h:m")+""" --->
|
2016-05-15 04:19:05 +00:00
|
|
|
<title>~"""+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>
|
|
|
|
</div>
|
2016-05-17 01:42:32 +00:00
|
|
|
|
2016-05-15 04:19:05 +00:00
|
|
|
<!---put your custom html here-->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!---don't put anything after this line-->
|
|
|
|
<div id=\"tlogs\">\
|
|
|
|
"""
|
2016-05-15 03:44:03 +00:00
|
|
|
return header
|
|
|
|
|
2016-06-10 02:42:08 +00:00
|
|
|
def valid_setup():
|
|
|
|
'''
|
|
|
|
Checks to see if user has a sane ttbp environment.
|
|
|
|
'''
|
|
|
|
|
|
|
|
global SETTINGS
|
|
|
|
|
|
|
|
if not os.path.isfile(TTBPRC):
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
|
|
|
SETTINGS = json.load(open(TTBPRC))
|
|
|
|
except ValueError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
if core.publishing():
|
|
|
|
if not SETTINGS.get("publish dir"):
|
|
|
|
return False
|
|
|
|
|
|
|
|
if not os.path.exists(WWW):
|
|
|
|
return False
|
|
|
|
|
|
|
|
if not os.path.exists(os.path.join(WWW, SETTINGS.get("pubish dir"))):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
def setup_repair():
|
2016-05-22 03:36:21 +00:00
|
|
|
'''
|
2016-05-27 07:21:11 +00:00
|
|
|
setup repair function
|
2016-05-22 03:36:21 +00:00
|
|
|
|
|
|
|
* calls setup()
|
|
|
|
* handles ^c
|
|
|
|
'''
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
print("\nyour ttbp configuration doesn't look right. let's make you a fresh copy.\n\n")
|
|
|
|
try:
|
|
|
|
setup()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("\n\nsorry, trying again.\n\n")
|
|
|
|
setup()
|
|
|
|
|
|
|
|
def setup():
|
2016-05-22 03:36:21 +00:00
|
|
|
'''
|
|
|
|
master setup function
|
|
|
|
|
|
|
|
* editor selection
|
|
|
|
* publishing toggle
|
|
|
|
* publish/unpublish as needed
|
|
|
|
* directory selection
|
|
|
|
|
|
|
|
TODO: break this out better?
|
|
|
|
'''
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
global SETTINGS
|
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
print("\n\ttext editor:\t" +SETTINGS.get("editor"))
|
2016-05-27 07:21:11 +00:00
|
|
|
if core.publishing():
|
2016-05-23 02:14:16 +00:00
|
|
|
print("\tpublish dir:\t" +os.path.join(PUBLIC, SETTINGS.get("publish dir")))
|
|
|
|
print("\tpubishing:\t"+str(SETTINGS.get("publishing"))+"\n")
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
# editor selection
|
2016-05-15 22:15:53 +00:00
|
|
|
SETTINGS.update({"editor": select_editor()})
|
2016-05-15 03:44:03 +00:00
|
|
|
redraw("text editor set to: "+SETTINGS["editor"])
|
|
|
|
|
2016-05-16 04:49:36 +00:00
|
|
|
# publishing selection
|
2016-05-15 22:15:53 +00:00
|
|
|
SETTINGS.update({"publishing":select_publishing()})
|
2016-06-10 02:42:08 +00:00
|
|
|
core.reload_ttbprc(SETTINGS)
|
2016-05-20 03:19:02 +00:00
|
|
|
update_publishing()
|
2016-05-27 07:21:11 +00:00
|
|
|
redraw("blog publishing: "+str(core.publishing()))
|
2016-05-15 22:15:53 +00:00
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
if core.publishing():
|
2016-05-20 03:19:02 +00:00
|
|
|
print("publish directory: ~"+USER+"/public_html/"+SETTINGS.get("publish dir"))
|
2016-05-22 03:36:21 +00:00
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
# save settings
|
|
|
|
ttbprc = open(TTBPRC, "w")
|
|
|
|
ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':')))
|
|
|
|
ttbprc.close()
|
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
|
|
|
|
redraw()
|
2016-05-23 02:14:16 +00:00
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
return SETTINGS
|
|
|
|
|
|
|
|
## menus
|
|
|
|
|
|
|
|
def main_menu():
|
2016-05-22 03:36:21 +00:00
|
|
|
'''
|
|
|
|
main navigation menu
|
|
|
|
'''
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
menuOptions = [
|
|
|
|
"record your feels",
|
|
|
|
"review your feels",
|
|
|
|
"check out your neighbors",
|
|
|
|
"browse global feels",
|
2016-05-27 18:08:45 +00:00
|
|
|
"scribble some graffiti\t(new!)",
|
2016-05-15 03:44:03 +00:00
|
|
|
"change your settings",
|
|
|
|
"send some feedback",
|
2016-05-22 05:49:38 +00:00
|
|
|
"see credits",
|
|
|
|
"read documentation"]
|
2016-05-22 03:36:21 +00:00
|
|
|
|
2016-06-01 02:42:03 +00:00
|
|
|
print("you're at ttbp home. remember, you can always press <ctrl-c> to come back here.\n")
|
2016-05-27 07:21:11 +00:00
|
|
|
util.print_menu(menuOptions, RAINBOW)
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
choice = raw_input("\ntell me about your feels (or 'quit' to exit): ")
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
redraw(EJECT)
|
|
|
|
return main_menu()
|
|
|
|
|
|
|
|
if choice == '0':
|
|
|
|
redraw()
|
|
|
|
today = time.strftime("%Y%m%d")
|
|
|
|
write_entry(os.path.join(DATA, today+".txt"))
|
2016-05-27 07:21:11 +00:00
|
|
|
core.www_neighbors()
|
2016-05-15 03:44:03 +00:00
|
|
|
elif choice == '1':
|
2016-05-31 19:31:02 +00:00
|
|
|
if core.publishing():
|
2016-06-01 02:42:03 +00:00
|
|
|
intro = "here are some options for reviewing your feels:"
|
2016-05-31 22:27:07 +00:00
|
|
|
redraw(intro)
|
|
|
|
review_menu(intro)
|
2016-06-02 07:46:19 +00:00
|
|
|
core.load_files()
|
|
|
|
core.write("index.html")
|
2016-05-31 19:31:02 +00:00
|
|
|
else:
|
2016-06-01 02:42:03 +00:00
|
|
|
redraw("your recorded feels, listed by date:")
|
2016-05-31 19:31:02 +00:00
|
|
|
view_feels(USER)
|
2016-05-15 03:44:03 +00:00
|
|
|
elif choice == '2':
|
2016-05-27 07:21:11 +00:00
|
|
|
users = core.find_ttbps()
|
2016-06-01 02:42:03 +00:00
|
|
|
redraw("the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:")
|
2016-05-15 03:44:03 +00:00
|
|
|
view_neighbors(users)
|
|
|
|
elif choice == '3':
|
2016-06-01 02:42:03 +00:00
|
|
|
redraw("most recent global entries")
|
2016-05-15 03:44:03 +00:00
|
|
|
view_feed()
|
|
|
|
elif choice == '4':
|
2016-05-27 18:08:45 +00:00
|
|
|
graffiti_handler()
|
|
|
|
elif choice == '5':
|
2016-05-23 02:14:16 +00:00
|
|
|
redraw("now changing your settings. press <ctrl-c> if you didn't mean to do this.")
|
2016-05-15 03:44:03 +00:00
|
|
|
try:
|
2016-05-27 07:21:11 +00:00
|
|
|
core.load(setup()) # reload settings to core
|
2016-05-15 03:44:03 +00:00
|
|
|
except KeyboardInterrupt():
|
|
|
|
redraw(EJECT)
|
|
|
|
redraw()
|
2016-05-27 18:08:45 +00:00
|
|
|
elif choice == '6':
|
2016-06-01 02:42:03 +00:00
|
|
|
redraw("you're about to send mail to ~endorphant about ttbp")
|
2016-05-15 03:44:03 +00:00
|
|
|
feedback_menu()
|
2016-05-27 18:08:45 +00:00
|
|
|
elif choice == '7':
|
2016-05-15 03:44:03 +00:00
|
|
|
redraw()
|
|
|
|
show_credits()
|
2016-05-27 18:08:45 +00:00
|
|
|
elif choice == '8':
|
2016-05-23 02:52:48 +00:00
|
|
|
subprocess.call(["lynx", os.path.join(SOURCE, "..", "README.html")])
|
2016-05-22 05:49:38 +00:00
|
|
|
redraw()
|
2016-05-15 03:44:03 +00:00
|
|
|
elif choice in QUITS:
|
|
|
|
return stop()
|
|
|
|
else:
|
|
|
|
redraw(INVALID)
|
|
|
|
|
|
|
|
return main_menu()
|
|
|
|
|
|
|
|
def feedback_menu():
|
2016-05-22 03:36:21 +00:00
|
|
|
'''
|
|
|
|
feedback handling menu
|
|
|
|
|
|
|
|
* selects feedback type
|
|
|
|
* calls feedback writing function
|
|
|
|
'''
|
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
util.print_menu(SUBJECTS, RAINBOW)
|
2016-05-15 03:44:03 +00:00
|
|
|
choice = raw_input("\npick a category for your feedback: ")
|
|
|
|
|
|
|
|
cat = ""
|
|
|
|
if choice in ['0', '1', '2', '3']:
|
|
|
|
cat = SUBJECTS[int(choice)]
|
2016-05-15 04:19:05 +00:00
|
|
|
entered = raw_input("""
|
|
|
|
composing a """+cat+""" to ~endorphant.
|
|
|
|
|
|
|
|
press <enter> to open an external text editor. mail will be sent once you save and quit.
|
2016-05-15 04:22:05 +00:00
|
|
|
|
|
|
|
""")
|
2016-05-15 03:44:03 +00:00
|
|
|
redraw(send_feedback(entered, cat))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
redraw(INVALID)
|
|
|
|
|
|
|
|
return feedback_menu()
|
|
|
|
|
2016-06-01 02:42:03 +00:00
|
|
|
def review_menu(intro=""):
|
2016-05-31 19:31:02 +00:00
|
|
|
'''
|
|
|
|
submenu for reviewing feels.
|
|
|
|
'''
|
|
|
|
|
|
|
|
menuOptions = [
|
|
|
|
"read over feels",
|
|
|
|
"modify feels publishing"
|
|
|
|
]
|
|
|
|
|
|
|
|
util.print_menu(menuOptions, RAINBOW)
|
|
|
|
|
|
|
|
choice = util.list_select(menuOptions, "what would you like to do with your feels? (or 'back' to return home) ")
|
|
|
|
|
|
|
|
if choice is not False:
|
|
|
|
if choice == 0:
|
2016-06-01 02:42:03 +00:00
|
|
|
redraw("your recorded feels, listed by date:")
|
2016-05-31 19:31:02 +00:00
|
|
|
view_feels(USER)
|
|
|
|
elif choice == 1:
|
2016-06-01 02:42:03 +00:00
|
|
|
redraw("here's your current nopub status:")
|
2016-05-31 22:27:07 +00:00
|
|
|
set_nopubs()
|
2016-05-31 19:31:02 +00:00
|
|
|
else:
|
|
|
|
redraw()
|
|
|
|
return
|
|
|
|
|
2016-05-31 22:27:07 +00:00
|
|
|
redraw(intro)
|
2016-05-31 19:31:02 +00:00
|
|
|
return review_menu()
|
|
|
|
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
def view_neighbors(users):
|
2016-05-23 02:14:16 +00:00
|
|
|
'''
|
|
|
|
generates list of all users on ttbp, sorted by most recent post
|
|
|
|
|
|
|
|
* if user is publishing, list publish directory
|
|
|
|
'''
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
userList = []
|
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
## assumes list of users passed in all have valid config files
|
2016-05-15 03:44:03 +00:00
|
|
|
for user in users:
|
|
|
|
userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc")))
|
2016-05-23 02:14:16 +00:00
|
|
|
|
|
|
|
## retrieve publishing url, if it exists
|
2016-05-23 00:52:27 +00:00
|
|
|
url="\t\t\t"
|
2016-05-20 15:06:42 +00:00
|
|
|
if userRC.get("publish dir"):
|
|
|
|
url = LIVE+user+"/"+userRC.get("publish dir")
|
2016-05-23 02:14:16 +00:00
|
|
|
|
|
|
|
## find last entry
|
2016-05-15 03:44:03 +00:00
|
|
|
files = os.listdir(os.path.join("/home", user, ".ttbp", "entries"))
|
|
|
|
files.sort()
|
2016-05-23 02:14:16 +00:00
|
|
|
lastfile = ""
|
2016-05-15 03:44:03 +00:00
|
|
|
for filename in files:
|
|
|
|
if core.valid(filename):
|
|
|
|
lastfile = os.path.join("/home", user, ".ttbp", "entries", filename)
|
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
## generate human-friendly timestamp
|
2016-05-15 03:44:03 +00:00
|
|
|
ago = "never"
|
|
|
|
if lastfile:
|
|
|
|
last = os.path.getctime(lastfile)
|
|
|
|
since = time.time()-last
|
|
|
|
ago = util.pretty_time(int(since)) + " ago"
|
|
|
|
else:
|
|
|
|
last = 0
|
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
## some formatting handwavin
|
|
|
|
urlpad = ""
|
|
|
|
if ago == "never":
|
|
|
|
urlpad = "\t"
|
|
|
|
|
|
|
|
userpad = ""
|
|
|
|
if len(user) < 7:
|
|
|
|
userpad = "\t"
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
userList.append(["\t~"+user+userpad+"\t("+ago+")"+urlpad+"\t"+url, last, user])
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
# sort user by most recent entry for display
|
2016-05-15 03:44:03 +00:00
|
|
|
userList.sort(key = lambda userdata:userdata[1])
|
|
|
|
userList.reverse()
|
|
|
|
sortedUsers = []
|
2016-05-23 02:14:16 +00:00
|
|
|
userIndex = []
|
2016-05-15 03:44:03 +00:00
|
|
|
for user in userList:
|
|
|
|
sortedUsers.append(user[0])
|
2016-05-23 02:14:16 +00:00
|
|
|
userIndex.append(user[2])
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
util.print_menu(sortedUsers, RAINBOW)
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
#raw_input("\n\npress <enter> to go back home.\n\n")
|
2016-05-27 07:21:11 +00:00
|
|
|
choice = util.list_select(sortedUsers, "pick a townie to browse their feels, or type 'back' to go home: ")
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
if choice is not False:
|
|
|
|
redraw("~"+userIndex[choice]+"'s recorded feels, listed by date: \n")
|
|
|
|
view_feels(userIndex[choice])
|
|
|
|
view_neighbors(users)
|
|
|
|
else:
|
|
|
|
redraw()
|
|
|
|
return
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
def view_feels(townie):
|
|
|
|
'''
|
|
|
|
generates a list of all feels by given townie and displays in
|
|
|
|
date order
|
|
|
|
|
|
|
|
* calls list_entries() to select feel to read
|
|
|
|
'''
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
filenames = []
|
2016-05-31 19:03:34 +00:00
|
|
|
showpub = False
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
if townie == USER:
|
|
|
|
entryDir = DATA
|
|
|
|
owner = "your"
|
2016-05-31 19:03:34 +00:00
|
|
|
if core.publishing():
|
|
|
|
showpub = True
|
2016-05-23 02:14:16 +00:00
|
|
|
else:
|
|
|
|
owner = "~"+townie+"'s"
|
|
|
|
entryDir = os.path.join("/home", townie, ".ttbp", "entries")
|
|
|
|
|
|
|
|
for entry in os.listdir(entryDir):
|
|
|
|
filenames.append(os.path.join(entryDir, entry))
|
2016-05-15 03:44:03 +00:00
|
|
|
metas = core.meta(filenames)
|
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
if len(filenames) > 0:
|
|
|
|
entries = []
|
|
|
|
for entry in metas:
|
2016-05-31 19:08:54 +00:00
|
|
|
pub = ""
|
|
|
|
if core.nopub(entry[0]):
|
|
|
|
pub = "(nopub)"
|
2016-05-31 19:03:34 +00:00
|
|
|
entries.append(""+entry[4]+" ("+p.no("word", entry[2])+") "+"\t"+pub)
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
return list_entries(metas, entries, owner+" recorded feels, listed by date: \n")
|
|
|
|
else:
|
|
|
|
redraw("no feels recorded by ~"+townie)
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
def show_credits():
|
2016-05-23 02:14:16 +00:00
|
|
|
'''
|
|
|
|
prints author acknowledgements and commentary
|
|
|
|
'''
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
print("""
|
|
|
|
ttbp was written by ~endorphant in python. the codebase is
|
|
|
|
publicly available on github at https://github.com/modgethanc/ttbp
|
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
for the full changelog, see ~endorphant/projects/ttbp/changelog.txt
|
|
|
|
|
2016-05-15 04:22:05 +00:00
|
|
|
if you have ideas for ttbp, you are welcome to fork the repo and
|
|
|
|
work on it. i'm only a neophyte dev, so i apologize for any
|
2016-05-23 02:14:16 +00:00
|
|
|
bad style and practices of mine; i'm always open to suggestions for
|
|
|
|
improvement.
|
|
|
|
|
|
|
|
i'd love to hear about your ideas and brainstorm about new features!
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
thanks to everyone who reads, listens, writes, and feels.\
|
|
|
|
""")
|
|
|
|
|
|
|
|
raw_input("\n\npress <enter> to go back home.\n\n")
|
|
|
|
redraw()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
## handlers
|
|
|
|
|
|
|
|
def write_entry(entry=os.path.join(DATA, "test.txt")):
|
2016-05-23 02:14:16 +00:00
|
|
|
'''
|
|
|
|
main feels-recording handler
|
|
|
|
'''
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-15 04:19:05 +00:00
|
|
|
entered = raw_input("""
|
|
|
|
feels will be recorded for today, """+time.strftime("%d %B %Y")+""".
|
|
|
|
|
|
|
|
if you've already started recording feels for this day, you
|
|
|
|
can pick up where you left off.
|
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
you can write your feels in plaintext, markdown, html, or a mixture of
|
2016-05-23 02:42:31 +00:00
|
|
|
these.
|
2016-05-23 02:14:16 +00:00
|
|
|
|
|
|
|
press <enter> to begin recording your feels in your chosen text
|
|
|
|
editor.
|
2016-05-15 04:22:05 +00:00
|
|
|
|
|
|
|
""")
|
2016-05-15 04:19:05 +00:00
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
if entered:
|
|
|
|
entryFile = open(entry, "a")
|
|
|
|
entryFile.write("\n"+entered+"\n")
|
|
|
|
entryFile.close()
|
2016-05-27 18:08:45 +00:00
|
|
|
subprocess.call([SETTINGS.get("editor"), entry])
|
2016-05-16 05:02:06 +00:00
|
|
|
|
|
|
|
left = ""
|
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
if core.publishing():
|
2016-05-16 05:02:06 +00:00
|
|
|
core.load_files()
|
|
|
|
core.write("index.html")
|
2016-05-20 15:06:42 +00:00
|
|
|
left = "posted to "+LIVE+USER+"/"+SETTINGS["publish dir"]+"/index.html\n\n>"
|
2016-05-16 05:02:06 +00:00
|
|
|
redraw(left + " thanks for sharing your feels!")
|
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
return
|
|
|
|
|
2016-05-31 22:27:07 +00:00
|
|
|
def set_nopubs():
|
|
|
|
'''
|
|
|
|
handler for toggling nopub on individual entries
|
|
|
|
'''
|
|
|
|
|
|
|
|
raw_input(DUST)
|
|
|
|
|
2016-05-22 03:36:21 +00:00
|
|
|
def send_feedback(entered, subject="none"):
|
2016-05-23 02:14:16 +00:00
|
|
|
'''
|
|
|
|
main feedback/bug report handler
|
|
|
|
'''
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
message = ""
|
|
|
|
|
|
|
|
temp = tempfile.NamedTemporaryFile()
|
|
|
|
if entered:
|
|
|
|
msgFile = open(temp.name, "a")
|
|
|
|
msgFile.write(entered+"\n")
|
|
|
|
msgFile.close()
|
|
|
|
subprocess.call([SETTINGS["editor"], temp.name])
|
|
|
|
message = open(temp.name, 'r').read()
|
|
|
|
|
2016-06-01 02:42:03 +00:00
|
|
|
if message:
|
|
|
|
id = "#"+util.genID(3)
|
|
|
|
mail = MIMEText(message)
|
|
|
|
mail['To'] = FEEDBOX
|
|
|
|
mail['From'] = USER+"@tilde.town"
|
|
|
|
mail['Subject'] = " ".join(["[ttbp]", subject, id])
|
|
|
|
m = os.popen("/usr/sbin/sendmail -t -oi", 'w')
|
|
|
|
m.write(mail.as_string())
|
|
|
|
m.close()
|
|
|
|
|
|
|
|
exit = """\
|
2016-05-15 03:44:03 +00:00
|
|
|
thanks for writing! for your reference, it's been recorded
|
2016-05-15 04:22:05 +00:00
|
|
|
> as """+ " ".join([subject, id])+""". i'll try to respond to you soon.\
|
2016-06-01 02:42:03 +00:00
|
|
|
"""
|
|
|
|
else:
|
|
|
|
exit = """\
|
|
|
|
i didn't send your blank message. if you made a mistake, please try
|
|
|
|
running through the feedback option again!\
|
|
|
|
"""
|
|
|
|
|
|
|
|
return exit
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
def list_entries(metas, entries, prompt):
|
|
|
|
'''
|
|
|
|
displays a list of entries for reading selection
|
|
|
|
'''
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
util.print_menu(entries, RAINBOW)
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
choice = util.list_select(entries, "pick an entry from the list, or type 'back' to go back: ")
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
if choice is not False:
|
|
|
|
|
|
|
|
redraw("now reading ~"+metas[choice][5]+"'s feels on "+metas[choice][4]+"\n> press <q> to return to feels list.\n\n")
|
|
|
|
|
|
|
|
show_entry(metas[choice][0])
|
|
|
|
redraw(prompt)
|
|
|
|
|
2016-05-23 02:14:16 +00:00
|
|
|
return list_entries(metas, entries, prompt)
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
redraw()
|
|
|
|
return
|
|
|
|
|
|
|
|
def show_entry(filename):
|
2016-05-23 02:14:16 +00:00
|
|
|
'''
|
|
|
|
call less on passed in filename
|
|
|
|
'''
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
subprocess.call(["less", filename])
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
def view_feed():
|
2016-05-23 02:14:16 +00:00
|
|
|
'''
|
|
|
|
generate and display list of most recent global entries
|
|
|
|
'''
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
feedList = []
|
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
for townie in core.find_ttbps():
|
2016-05-15 03:44:03 +00:00
|
|
|
entryDir = os.path.join("/home", townie, ".ttbp", "entries")
|
|
|
|
filenames = os.listdir(entryDir)
|
2016-05-15 04:19:05 +00:00
|
|
|
|
2016-05-15 03:44:03 +00:00
|
|
|
for entry in filenames:
|
|
|
|
if core.valid(entry):
|
|
|
|
feedList.append(os.path.join(entryDir, entry))
|
|
|
|
|
|
|
|
metas = core.meta(feedList)
|
|
|
|
metas.sort(key = lambda entry:entry[3])
|
|
|
|
metas.reverse()
|
|
|
|
|
|
|
|
entries = []
|
|
|
|
for entry in metas[0:10]:
|
|
|
|
pad = ""
|
|
|
|
if len(entry[5]) < 8:
|
|
|
|
pad = "\t"
|
|
|
|
|
|
|
|
entries.append("~"+entry[5]+pad+"\ton "+entry[3]+" ("+p.no("word", entry[2])+") ")
|
|
|
|
|
2016-06-01 03:08:14 +00:00
|
|
|
list_entries(metas, entries, "most recent global entries:")
|
2016-05-15 03:44:03 +00:00
|
|
|
|
|
|
|
redraw()
|
|
|
|
|
|
|
|
return
|
2016-05-15 04:19:05 +00:00
|
|
|
|
2016-05-27 18:08:45 +00:00
|
|
|
def graffiti_handler():
|
|
|
|
'''
|
|
|
|
Main graffiti handler.
|
|
|
|
'''
|
|
|
|
|
|
|
|
if os.path.isfile(WALL_LOCK):
|
2016-06-01 02:42:03 +00:00
|
|
|
redraw("sorry, "+chatter.say("friend")+", but someone's there right now. try again in a few!")
|
2016-05-27 18:08:45 +00:00
|
|
|
else:
|
|
|
|
subprocess.call(["touch", WALL_LOCK])
|
|
|
|
redraw()
|
|
|
|
print("""\
|
|
|
|
the graffiti wall is a world-writeable text file. anyone can
|
|
|
|
scribble on it; anyone can move or delete things. please be
|
|
|
|
considerate of your neighbors when writing on it.
|
|
|
|
|
|
|
|
no one will be able to visit the wall while you are here, so don't
|
|
|
|
worry about overwriting someone else's work. anything you do to the
|
|
|
|
wall will be recorded if you save the file, and you can cancel
|
|
|
|
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])
|
|
|
|
redraw("thanks for visiting the graffiti wall!")
|
|
|
|
|
|
|
|
|
2016-05-23 02:30:59 +00:00
|
|
|
## misc helpers
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-15 22:15:53 +00:00
|
|
|
|
|
|
|
def select_editor():
|
2016-05-23 02:30:59 +00:00
|
|
|
'''
|
|
|
|
setup helper for editor selection
|
|
|
|
'''
|
2016-05-15 22:15:53 +00:00
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
util.print_menu(EDITORS, RAINBOW)
|
2016-05-31 22:27:07 +00:00
|
|
|
|
|
|
|
choice = util.list_select(EDITORS, "pick your favorite text editor: ")
|
|
|
|
#choice = raw_input("\npick your favorite text editor: ")
|
|
|
|
#while choice not in ['0', '1', '2', '3', '4', '5']:
|
|
|
|
# choice = raw_input("\nplease pick a number from the list: ")
|
|
|
|
|
|
|
|
if choice is False:
|
|
|
|
redraw("please pick a text editor!")
|
|
|
|
select_editor()
|
2016-05-15 22:15:53 +00:00
|
|
|
|
|
|
|
return EDITORS[int(choice)]
|
|
|
|
|
|
|
|
def select_publish_dir():
|
2016-05-23 02:30:59 +00:00
|
|
|
'''
|
|
|
|
setup helper for publish directory selection
|
|
|
|
'''
|
2016-05-15 22:15:53 +00:00
|
|
|
|
2016-05-16 04:49:36 +00:00
|
|
|
current = SETTINGS.get("publish dir")
|
|
|
|
republish = False
|
|
|
|
|
|
|
|
if current:
|
2016-05-20 03:19:02 +00:00
|
|
|
print("\ncurrent publish dir:\t"+os.path.join(PUBLIC, SETTINGS["publish dir"]))
|
2016-05-16 04:49:36 +00:00
|
|
|
republish = True
|
|
|
|
|
2016-05-15 22:15:53 +00:00
|
|
|
choice = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ")
|
|
|
|
if not choice:
|
|
|
|
choice = "blog"
|
|
|
|
|
2016-05-17 01:42:32 +00:00
|
|
|
publishDir = os.path.join(PUBLIC, choice)
|
|
|
|
while os.path.exists(publishDir):
|
2016-05-20 03:35:34 +00:00
|
|
|
second = raw_input("\n"+publishDir+"""\
|
2016-05-23 02:30:59 +00:00
|
|
|
already exists!
|
|
|
|
|
2016-05-20 03:35:34 +00:00
|
|
|
setting this as your publishing directory means this program may
|
|
|
|
delete or overwrite file there!
|
2016-05-23 02:30:59 +00:00
|
|
|
|
2016-05-20 03:35:34 +00:00
|
|
|
if you're sure you want to use it, hit <enter> to confirm.
|
2016-05-23 02:30:59 +00:00
|
|
|
otherwise, pick another location: """)
|
|
|
|
|
2016-05-15 22:15:53 +00:00
|
|
|
if second == "":
|
|
|
|
break
|
|
|
|
choice = second
|
2016-05-17 01:42:32 +00:00
|
|
|
publishDir = os.path.join(PUBLIC, choice)
|
2016-05-15 22:15:53 +00:00
|
|
|
|
|
|
|
return choice
|
|
|
|
|
|
|
|
def select_publishing():
|
2016-05-23 02:30:59 +00:00
|
|
|
'''
|
|
|
|
setup helper for toggling publishing
|
|
|
|
'''
|
2016-05-15 22:15:53 +00:00
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
publish = util.input_yn("""\
|
2016-05-15 22:15:53 +00:00
|
|
|
do you want to publish your feels online?
|
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
if yes, your feels will be published to a directory of your choice in
|
|
|
|
your public_html. i'll confirm the location of that directory in a
|
|
|
|
moment.
|
|
|
|
|
|
|
|
if not, your feels will only be readable from within the tilde.town
|
|
|
|
network. if you already have a publishing directory, i'll remove it for
|
|
|
|
you (don't worry, your written entries will still be saved!)
|
2016-05-15 22:15:53 +00:00
|
|
|
|
|
|
|
you can change this option any time.
|
|
|
|
|
|
|
|
please enter\
|
|
|
|
""")
|
|
|
|
|
2016-05-17 01:42:32 +00:00
|
|
|
return publish
|
2016-05-16 04:49:36 +00:00
|
|
|
|
|
|
|
def unpublish():
|
2016-05-23 02:30:59 +00:00
|
|
|
'''
|
2016-06-10 01:18:34 +00:00
|
|
|
remove user's published directory, if it exists. this should only remove the symlink in public_html.
|
2016-05-23 02:30:59 +00:00
|
|
|
'''
|
2016-05-15 22:15:53 +00:00
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
dir = SETTINGS.get("publish dir")
|
|
|
|
if dir:
|
|
|
|
publishDir = os.path.join(PUBLIC, dir)
|
|
|
|
subprocess.call(["rm", publishDir])
|
2016-05-16 04:49:36 +00:00
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
def update_publishing():
|
2016-05-23 02:30:59 +00:00
|
|
|
'''
|
|
|
|
updates publishing directory if user is publishing. otherwise, wipe it.
|
|
|
|
'''
|
2016-05-16 04:49:36 +00:00
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
global SETTINGS
|
|
|
|
|
2016-05-27 07:21:11 +00:00
|
|
|
if core.publishing():
|
2016-05-20 03:19:02 +00:00
|
|
|
oldDir = SETTINGS.get("publish dir")
|
|
|
|
newDir = select_publish_dir()
|
|
|
|
SETTINGS.update({"publish dir": newDir})
|
|
|
|
if oldDir:
|
2016-05-20 03:35:34 +00:00
|
|
|
subprocess.call(["rm", os.path.join(PUBLIC, oldDir)])
|
2016-05-20 03:19:02 +00:00
|
|
|
make_publish_dir(newDir)
|
|
|
|
core.load_files()
|
|
|
|
core.write("index.html")
|
|
|
|
else:
|
|
|
|
unpublish()
|
|
|
|
SETTINGS.update({"publish dir": None})
|
2016-05-16 04:49:36 +00:00
|
|
|
|
|
|
|
def make_publish_dir(dir):
|
2016-05-23 02:30:59 +00:00
|
|
|
'''
|
|
|
|
setup helper to create publishing directory
|
|
|
|
'''
|
2016-05-16 04:49:36 +00:00
|
|
|
|
2016-05-17 01:42:32 +00:00
|
|
|
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")
|
2016-05-15 22:15:53 +00:00
|
|
|
index.write("<h1>ttbp blog placeholder</h1>")
|
|
|
|
index.close()
|
2016-05-17 01:42:32 +00:00
|
|
|
|
|
|
|
publishDir = os.path.join(PUBLIC, dir)
|
|
|
|
if os.path.exists(publishDir):
|
|
|
|
subprocess.call(["rm", publishDir])
|
|
|
|
|
|
|
|
subprocess.call(["ln", "-s", WWW, publishDir])
|
|
|
|
|
2016-05-15 22:15:53 +00:00
|
|
|
print("\n\tpublishing to "+LIVE+USER+"/"+SETTINGS.get("publish dir")+"/\n\n")
|
|
|
|
|
2016-05-23 02:30:59 +00:00
|
|
|
##### PATCHING UTILITIES
|
2016-05-17 01:42:32 +00:00
|
|
|
|
2016-05-27 03:59:04 +00:00
|
|
|
def build_mismatch():
|
|
|
|
'''
|
|
|
|
checks to see if user's last run build is the same as this session
|
|
|
|
'''
|
|
|
|
|
|
|
|
versionFile = os.path.join(PATH, "version")
|
|
|
|
if not os.path.exists(versionFile):
|
|
|
|
return False
|
|
|
|
|
2016-05-27 18:08:45 +00:00
|
|
|
ver = open(versionFile, "r").read().rstrip()
|
2016-05-27 03:59:04 +00:00
|
|
|
if ver[-1] == __version__[-1]:
|
|
|
|
return False
|
|
|
|
|
2016-05-27 18:08:45 +00:00
|
|
|
return ver
|
2016-05-27 03:59:04 +00:00
|
|
|
|
2016-05-27 18:08:45 +00:00
|
|
|
def switch_build(ver):
|
2016-05-27 03:59:04 +00:00
|
|
|
'''
|
|
|
|
switches user between beta and stable builds
|
|
|
|
'''
|
|
|
|
|
|
|
|
if __version__[-1] == 'b':
|
|
|
|
build = "beta"
|
2016-05-27 18:08:45 +00:00
|
|
|
ver += "b"
|
2016-05-27 03:59:04 +00:00
|
|
|
else:
|
|
|
|
build = "stable"
|
2016-05-27 18:08:45 +00:00
|
|
|
ver = ver[0:-1]
|
2016-05-27 03:59:04 +00:00
|
|
|
|
2016-05-27 18:08:45 +00:00
|
|
|
# write user versionfile
|
|
|
|
print("\nswitching you over to the "+build+" version...\n")
|
2016-05-27 03:59:04 +00:00
|
|
|
time.sleep(1)
|
|
|
|
print("...")
|
|
|
|
versionFile = os.path.join(PATH, "version")
|
2016-05-27 18:08:45 +00:00
|
|
|
open(versionFile, "w").write(ver)
|
|
|
|
time.sleep(1)
|
|
|
|
#print("\nall good!\n")
|
2016-05-27 03:59:04 +00:00
|
|
|
|
2016-05-17 01:42:32 +00:00
|
|
|
def updated():
|
2016-05-23 02:30:59 +00:00
|
|
|
'''
|
|
|
|
checks to see if current user is up to the same version as system
|
|
|
|
'''
|
2016-05-17 01:42:32 +00:00
|
|
|
|
|
|
|
versionFile = os.path.join(PATH, "version")
|
|
|
|
if not os.path.exists(versionFile):
|
2016-05-27 03:59:04 +00:00
|
|
|
return False
|
2016-05-17 01:42:32 +00:00
|
|
|
|
|
|
|
ver = open(versionFile, "r").read()
|
|
|
|
|
2016-05-22 05:12:47 +00:00
|
|
|
if ver == __version__:
|
2016-05-17 01:42:32 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def update_version():
|
2016-05-23 02:30:59 +00:00
|
|
|
'''
|
|
|
|
updates user to current version
|
|
|
|
'''
|
2016-05-20 03:19:02 +00:00
|
|
|
|
|
|
|
global SETTINGS
|
2016-05-17 01:42:32 +00:00
|
|
|
|
|
|
|
versionFile = os.path.join(PATH, "version")
|
2016-05-20 03:19:02 +00:00
|
|
|
|
|
|
|
print("ttbp had some updates!")
|
2016-05-17 01:42:32 +00:00
|
|
|
|
2016-05-22 05:12:47 +00:00
|
|
|
print("\ngive me a second to update you to version "+__version__+"...\n")
|
2016-05-20 15:06:42 +00:00
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
print("...")
|
|
|
|
time.sleep(2)
|
2016-05-20 03:19:02 +00:00
|
|
|
|
2016-05-27 18:08:45 +00:00
|
|
|
userVersion = ""
|
|
|
|
|
2016-05-20 15:06:42 +00:00
|
|
|
if not os.path.isfile(versionFile):
|
|
|
|
# from 0.8.5 to 0.8.6:
|
2016-05-17 01:42:32 +00:00
|
|
|
|
|
|
|
# change style.css location
|
2016-05-20 03:19:02 +00:00
|
|
|
if os.path.isfile(os.path.join(WWW, "style.css")):
|
2016-05-17 01:42:32 +00:00
|
|
|
subprocess.call(["mv", os.path.join(WWW, "style.css"), CONFIG])
|
|
|
|
|
|
|
|
# change www symlink
|
|
|
|
if os.path.exists(WWW):
|
|
|
|
subprocess.call(["rm", WWW])
|
2016-06-10 01:18:34 +00:00
|
|
|
|
|
|
|
subprocess.call(["mkdir", WWW])
|
2016-05-17 01:42:32 +00:00
|
|
|
|
|
|
|
subprocess.call(["ln", "-s", os.path.join(CONFIG, "style.css"), os.path.join(WWW, "style.css")])
|
|
|
|
|
|
|
|
publishDir = os.path.join(PUBLIC, SETTINGS.get("publish dir"))
|
|
|
|
if os.path.exists(publishDir):
|
|
|
|
subprocess.call(["rm", "-rf", publishDir])
|
2016-06-10 01:18:34 +00:00
|
|
|
|
|
|
|
subprocess.call(["ln", "-s", WWW, os.path.join(PUBLIC, SETTINGS.get("publish dir"))])
|
2016-05-17 01:42:32 +00:00
|
|
|
|
|
|
|
# repopulate html files
|
|
|
|
core.load_files()
|
|
|
|
core.write("index.html")
|
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
# add publishing setting
|
|
|
|
print("\nnew feature!\n")
|
|
|
|
SETTINGS.update({"publishing":select_publishing()})
|
|
|
|
update_publishing()
|
2016-05-20 15:06:42 +00:00
|
|
|
ttbprc = open(TTBPRC, "w")
|
|
|
|
ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':')))
|
|
|
|
ttbprc.close()
|
|
|
|
|
|
|
|
else: # version at least 0.8.6
|
2016-05-27 18:08:45 +00:00
|
|
|
userVersion = open(versionFile, "r").read().rstrip()
|
2016-05-23 02:30:59 +00:00
|
|
|
|
2016-05-27 18:08:45 +00:00
|
|
|
# from 0.8.6
|
2016-05-23 02:30:59 +00:00
|
|
|
if userVersion == "0.8.6":
|
2016-05-20 15:06:42 +00:00
|
|
|
print("\nresetting your publishing settings...\n")
|
|
|
|
SETTINGS.update({"publishing":select_publishing()})
|
|
|
|
update_publishing()
|
|
|
|
ttbprc = open(TTBPRC, "w")
|
|
|
|
ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':')))
|
|
|
|
ttbprc.close()
|
2016-05-20 03:19:02 +00:00
|
|
|
|
2016-05-17 01:42:32 +00:00
|
|
|
# increment user versionfile
|
2016-05-23 00:52:27 +00:00
|
|
|
open(versionFile, "w").write(__version__)
|
2016-06-10 01:18:34 +00:00
|
|
|
print("""
|
|
|
|
you're all good to go, "+chatter.say("friend")+"! please contact ~endorphant if
|
|
|
|
somehing strange happened to you during this update.
|
|
|
|
""")
|
2016-05-17 01:42:32 +00:00
|
|
|
|
2016-05-27 18:08:45 +00:00
|
|
|
# show patch notes
|
2016-05-31 18:55:45 +00:00
|
|
|
#if userVersion != "0.9.0" and userVersion != "0.9.0b":
|
|
|
|
if userVersion[0:5] < "0.9.0":
|
2016-05-27 18:08:45 +00:00
|
|
|
# version 0.9.0 patch notes:
|
|
|
|
print("""
|
2016-05-23 02:30:59 +00:00
|
|
|
ver. 0.9.0 features:
|
|
|
|
* browsing other people's feels from neighbor view
|
|
|
|
* documentation browser
|
2016-05-27 18:08:45 +00:00
|
|
|
""")
|
|
|
|
|
2016-05-31 18:55:45 +00:00
|
|
|
if userVersion[0:5] < "0.9.1":
|
|
|
|
# version 0.9.1 patch notes
|
|
|
|
print("""
|
2016-05-27 18:08:45 +00:00
|
|
|
ver 0.9.1 features:
|
|
|
|
* graffiti wall
|
2016-05-31 18:55:45 +00:00
|
|
|
""")
|
2016-05-15 03:44:03 +00:00
|
|
|
|
2016-05-20 03:19:02 +00:00
|
|
|
#####
|
2016-05-17 01:42:32 +00:00
|
|
|
|
2016-05-22 03:36:21 +00:00
|
|
|
if __name__ == '__main__':
|
2016-05-31 22:27:07 +00:00
|
|
|
start()
|
|
|
|
#print("ttbp beta is out to lunch. bbl.")
|