more documentation updates
holy crap! here i am, about a decade and a half after my first Formal Instruction in programming, and i suddenly understand code documentation. part of this is that sometimes i stare at functions forgetting why they're there, or start writing a function with the distinct feeling that i'm typing code i've already typed before, and realize that maybe there's a better way. so i skimmed code from other people that i've used in my own repos, and lifted the general gist of their commenting style while doing things that feel right to me. i still don't know exactly how i like things, but i'm learning. this is the best way i learn things. then. then! i learned that i can just pydoc any of my modules and pydoc will generate literally the same thing that i read when i pydoc other module! what. WHAT. this is amazing. i feel like a real person. i understand where those docs come from now, and how to make them myself. i'm learning so much. why does this feel so amazing. all of this is in a commit message that i'm going to fire off into the sun but i just need to put this out there because this feels important.master
parent
1827d8467f
commit
dccb1570d8
103
bin/_ttbp.py
103
bin/_ttbp.py
|
@ -81,6 +81,12 @@ SUBJECTS = ["help request", "bug report", "feature suggestion", "general comment
|
||||||
##
|
##
|
||||||
|
|
||||||
def redraw(leftover=""):
|
def redraw(leftover=""):
|
||||||
|
'''
|
||||||
|
screen clearing
|
||||||
|
|
||||||
|
* clears the screen and reprints the banner, plus whatever leftover text to be hilights
|
||||||
|
'''
|
||||||
|
|
||||||
os.system("clear")
|
os.system("clear")
|
||||||
print(BANNER)
|
print(BANNER)
|
||||||
print(SPACER)
|
print(SPACER)
|
||||||
|
@ -88,9 +94,16 @@ def redraw(leftover=""):
|
||||||
print("> "+leftover+"\n")
|
print("> "+leftover+"\n")
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
|
'''
|
||||||
|
main engine head
|
||||||
|
|
||||||
|
* called on program start
|
||||||
|
* calls config check
|
||||||
|
* proceeds to main menu
|
||||||
|
* handles ^c and ^d ejects
|
||||||
|
'''
|
||||||
|
|
||||||
redraw()
|
redraw()
|
||||||
#print(chatter.say("greet")+", "+chatter.say("friend"))
|
|
||||||
#print("(remember, you can always press ctrl-c to come home)\n")
|
|
||||||
print("""
|
print("""
|
||||||
if you don't want to be here at any point, press <ctrl-d> and it'll all go away.
|
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.\
|
just keep in mind that you might lose anything you've started here.\
|
||||||
|
@ -117,13 +130,29 @@ just keep in mind that you might lose anything you've started here.\
|
||||||
break
|
break
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
|
'''
|
||||||
|
closer
|
||||||
|
|
||||||
|
* prints ending text
|
||||||
|
'''
|
||||||
|
|
||||||
return "\n\n\t"+chatter.say("bye")+"\n\n"
|
return "\n\n\t"+chatter.say("bye")+"\n\n"
|
||||||
|
|
||||||
def check_init():
|
def check_init():
|
||||||
|
'''
|
||||||
|
user handler
|
||||||
|
|
||||||
|
* checks for presence of ttbprc
|
||||||
|
* checks for last run version
|
||||||
|
'''
|
||||||
|
|
||||||
global SETTINGS
|
global SETTINGS
|
||||||
|
|
||||||
print("\n\n")
|
print("\n\n")
|
||||||
if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")):
|
if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")):
|
||||||
print(chatter.say("greet")+", "+USER+".\n")
|
print(chatter.say("greet")+", "+USER+".\n")
|
||||||
|
|
||||||
|
## ttbprc validation
|
||||||
while not os.path.isfile(TTBPRC):
|
while not os.path.isfile(TTBPRC):
|
||||||
setup_handler()
|
setup_handler()
|
||||||
try:
|
try:
|
||||||
|
@ -135,6 +164,7 @@ def check_init():
|
||||||
if not updated():
|
if not updated():
|
||||||
print(update_version())
|
print(update_version())
|
||||||
|
|
||||||
|
## when ready, enter main program and load core engine
|
||||||
raw_input("press <enter> to explore your feels.\n\n")
|
raw_input("press <enter> to explore your feels.\n\n")
|
||||||
core.load()
|
core.load()
|
||||||
|
|
||||||
|
@ -143,32 +173,45 @@ def check_init():
|
||||||
return init()
|
return init()
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
|
'''
|
||||||
|
new user creation
|
||||||
|
|
||||||
|
* introduces user
|
||||||
|
* calls setup functinos
|
||||||
|
'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
raw_input("""
|
raw_input("""
|
||||||
i don't recognize you, stranger. let's make friends.
|
i don't recognize you, stranger. let's make friends.
|
||||||
|
|
||||||
press <enter> to begin, or <ctrl-c> to get out of here.
|
press <enter> to begin, or <ctrl-c> to get out of here.\
|
||||||
""")
|
""")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\n\nthanks for checking in! i'll always be here.\n\n")
|
print("\n\nthanks for checking in! i'll always be here.\n\n")
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
|
## record user in source list
|
||||||
users = open(USERFILE, 'a')
|
users = open(USERFILE, 'a')
|
||||||
users.write(USER+"\n")
|
users.write(USER+"\n")
|
||||||
users.close()
|
users.close()
|
||||||
|
|
||||||
|
## make .ttbp directory structure
|
||||||
subprocess.call(["mkdir", PATH])
|
subprocess.call(["mkdir", PATH])
|
||||||
subprocess.call(["mkdir", CONFIG])
|
subprocess.call(["mkdir", CONFIG])
|
||||||
subprocess.call(["mkdir", DATA])
|
subprocess.call(["mkdir", DATA])
|
||||||
|
|
||||||
|
## create header file
|
||||||
header = gen_header()
|
header = gen_header()
|
||||||
headerfile = open(os.path.join(CONFIG, "header.txt"), 'w')
|
headerfile = open(os.path.join(CONFIG, "header.txt"), 'w')
|
||||||
for line in header:
|
for line in header:
|
||||||
headerfile.write(line)
|
headerfile.write(line)
|
||||||
headerfile.close()
|
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", "footer.txt"), CONFIG])
|
||||||
subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "style.css"), CONFIG])
|
subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "style.css"), CONFIG])
|
||||||
|
|
||||||
|
## run user-interactive setup and load core engine
|
||||||
setup()
|
setup()
|
||||||
core.load()
|
core.load()
|
||||||
|
|
||||||
|
@ -176,10 +219,17 @@ press <enter> to begin, or <ctrl-c> to get out of here.
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def gen_header():
|
def gen_header():
|
||||||
header ="""
|
'''
|
||||||
|
header generator
|
||||||
|
|
||||||
|
builds header to insert username
|
||||||
|
'''
|
||||||
|
|
||||||
|
header ="""\
|
||||||
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
|
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<!--- this header automatically generated by ttbp initialization on """+time.strftime("%Y-%m-%d %h:m")+""" --->
|
||||||
<title>~"""+USER+""" on TTBP</title>
|
<title>~"""+USER+""" on TTBP</title>
|
||||||
<link rel=\"stylesheet\" href=\"style.css\" />
|
<link rel=\"stylesheet\" href=\"style.css\" />
|
||||||
</head>
|
</head>
|
||||||
|
@ -198,6 +248,13 @@ def gen_header():
|
||||||
return header
|
return header
|
||||||
|
|
||||||
def setup_handler():
|
def setup_handler():
|
||||||
|
'''
|
||||||
|
setup wrapper function
|
||||||
|
|
||||||
|
* calls setup()
|
||||||
|
* handles ^c
|
||||||
|
'''
|
||||||
|
|
||||||
print("\nyour ttbp configuration doesn't look right. let's make you a fresh copy.\n\n")
|
print("\nyour ttbp configuration doesn't look right. let's make you a fresh copy.\n\n")
|
||||||
try:
|
try:
|
||||||
setup()
|
setup()
|
||||||
|
@ -206,6 +263,17 @@ def setup_handler():
|
||||||
setup()
|
setup()
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
|
'''
|
||||||
|
master setup function
|
||||||
|
|
||||||
|
* editor selection
|
||||||
|
* publishing toggle
|
||||||
|
* publish/unpublish as needed
|
||||||
|
* directory selection
|
||||||
|
|
||||||
|
TODO: break this out better?
|
||||||
|
'''
|
||||||
|
|
||||||
global SETTINGS
|
global SETTINGS
|
||||||
|
|
||||||
# editor selection
|
# editor selection
|
||||||
|
@ -219,6 +287,7 @@ def setup():
|
||||||
|
|
||||||
if publishing():
|
if publishing():
|
||||||
print("publish directory: ~"+USER+"/public_html/"+SETTINGS.get("publish dir"))
|
print("publish directory: ~"+USER+"/public_html/"+SETTINGS.get("publish dir"))
|
||||||
|
|
||||||
# save settings
|
# save settings
|
||||||
ttbprc = open(TTBPRC, "w")
|
ttbprc = open(TTBPRC, "w")
|
||||||
ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':')))
|
ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':')))
|
||||||
|
@ -231,6 +300,12 @@ def setup():
|
||||||
## menus
|
## menus
|
||||||
|
|
||||||
def print_menu(menu):
|
def print_menu(menu):
|
||||||
|
'''
|
||||||
|
pretty menu handler
|
||||||
|
|
||||||
|
* takes list of options and prints them
|
||||||
|
'''
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for x in menu:
|
for x in menu:
|
||||||
line = []
|
line = []
|
||||||
|
@ -244,6 +319,10 @@ def print_menu(menu):
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
def main_menu():
|
def main_menu():
|
||||||
|
'''
|
||||||
|
main navigation menu
|
||||||
|
'''
|
||||||
|
|
||||||
menuOptions = [
|
menuOptions = [
|
||||||
"record your feels",
|
"record your feels",
|
||||||
"review your feels",
|
"review your feels",
|
||||||
|
@ -252,8 +331,8 @@ def main_menu():
|
||||||
"change your settings",
|
"change your settings",
|
||||||
"send some feedback",
|
"send some feedback",
|
||||||
"see credits"]
|
"see credits"]
|
||||||
|
|
||||||
print("you're at ttbp home. remember, you can always press <ctrl-c> to come back here.\n\n")
|
print("you're at ttbp home. remember, you can always press <ctrl-c> to come back here.\n\n")
|
||||||
#print("you're at ttbp home.\n\n")
|
|
||||||
print_menu(menuOptions)
|
print_menu(menuOptions)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -301,9 +380,14 @@ def main_menu():
|
||||||
|
|
||||||
return main_menu()
|
return main_menu()
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
def feedback_menu():
|
def feedback_menu():
|
||||||
|
'''
|
||||||
|
feedback handling menu
|
||||||
|
|
||||||
|
* selects feedback type
|
||||||
|
* calls feedback writing function
|
||||||
|
'''
|
||||||
|
|
||||||
print("you're about to send mail to ~endorphant about ttbp\n\n")
|
print("you're about to send mail to ~endorphant about ttbp\n\n")
|
||||||
|
|
||||||
print_menu(SUBJECTS)
|
print_menu(SUBJECTS)
|
||||||
|
@ -443,7 +527,7 @@ press <enter> to begin recording your feels.
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def send_feedback(entered, subject="none", mailbox=os.path.join(FEEDBACK, USER+"-"+time.strftime("%Y%m%d-%H%M")+".msg")):
|
def send_feedback(entered, subject="none"):
|
||||||
|
|
||||||
message = ""
|
message = ""
|
||||||
|
|
||||||
|
@ -817,5 +901,6 @@ def update_version():
|
||||||
|
|
||||||
#####
|
#####
|
||||||
|
|
||||||
start()
|
if __name__ == '__main__':
|
||||||
|
start()
|
||||||
#print("ttbp beta is out to lunch. bbl.")
|
#print("ttbp beta is out to lunch. bbl.")
|
||||||
|
|
|
@ -27,7 +27,6 @@ the complete codebase is available at:
|
||||||
https://github.com/modgethanc/ttbp
|
https://github.com/modgethanc/ttbp
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
32
bin/util.py
32
bin/util.py
|
@ -33,6 +33,10 @@ lastcolor = colorama.Fore.RESET
|
||||||
p = inflect.engine()
|
p = inflect.engine()
|
||||||
|
|
||||||
def set_rainbow():
|
def set_rainbow():
|
||||||
|
'''
|
||||||
|
prints a random terminal color code
|
||||||
|
'''
|
||||||
|
|
||||||
global lastcolor
|
global lastcolor
|
||||||
|
|
||||||
color = lastcolor
|
color = lastcolor
|
||||||
|
@ -44,9 +48,17 @@ def set_rainbow():
|
||||||
print(color)
|
print(color)
|
||||||
|
|
||||||
def reset_color():
|
def reset_color():
|
||||||
|
'''
|
||||||
|
prints terminal color code reset
|
||||||
|
'''
|
||||||
|
|
||||||
print(colorama.Fore.RESET)
|
print(colorama.Fore.RESET)
|
||||||
|
|
||||||
def attach_rainbow():
|
def attach_rainbow():
|
||||||
|
'''
|
||||||
|
returns a random terminal color code, presumably to be 'attached' to a string
|
||||||
|
'''
|
||||||
|
|
||||||
global lastcolor
|
global lastcolor
|
||||||
|
|
||||||
color = lastcolor
|
color = lastcolor
|
||||||
|
@ -57,12 +69,28 @@ def attach_rainbow():
|
||||||
return color
|
return color
|
||||||
|
|
||||||
def attach_reset():
|
def attach_reset():
|
||||||
|
'''
|
||||||
|
returns terminal color code reset, presumably to be 'attached' to a string
|
||||||
|
'''
|
||||||
|
|
||||||
return colorama.Style.RESET_ALL
|
return colorama.Style.RESET_ALL
|
||||||
|
|
||||||
def hilight(text):
|
def hilight(text):
|
||||||
|
'''
|
||||||
|
takes a string and highlights it on return
|
||||||
|
'''
|
||||||
|
|
||||||
return colorama.Style.BRIGHT+text+colorama.Style.NORMAL
|
return colorama.Style.BRIGHT+text+colorama.Style.NORMAL
|
||||||
|
|
||||||
def pretty_time(time):
|
def pretty_time(time):
|
||||||
|
'''
|
||||||
|
human-friendly time formatter
|
||||||
|
|
||||||
|
takes an integer number of seconds and returns a phrase that describes it,
|
||||||
|
using the largest possible figure, rounded down (ie, time=604 returns '10
|
||||||
|
minutes', not '10 minutes, 4 seconds' or '604 seconds')
|
||||||
|
'''
|
||||||
|
|
||||||
m, s = divmod(time, 60)
|
m, s = divmod(time, 60)
|
||||||
if m > 0:
|
if m > 0:
|
||||||
h, m = divmod(m, 60)
|
h, m = divmod(m, 60)
|
||||||
|
@ -86,7 +114,9 @@ def pretty_time(time):
|
||||||
return p.no("second", s)
|
return p.no("second", s)
|
||||||
|
|
||||||
def genID(digits=5):
|
def genID(digits=5):
|
||||||
# makes a string of digits
|
'''
|
||||||
|
returns a string-friendly string of digits, which can start with 0
|
||||||
|
'''
|
||||||
|
|
||||||
id = ""
|
id = ""
|
||||||
x = 0
|
x = 0
|
||||||
|
|
|
@ -17,10 +17,12 @@ TO-DO:
|
||||||
(flair)
|
(flair)
|
||||||
|
|
||||||
-graffiti wall
|
-graffiti wall
|
||||||
-command line flags:
|
-command line flags
|
||||||
(maybe; not sure i want this to be a feature at all)
|
*maybe; not sure i want this to be a feature at all
|
||||||
-shortcut to most recent feels, writing entry, seeing own entry
|
-shortcut to most recent feels, writing entry, seeing own entry
|
||||||
-#hashtags
|
-#hashtags
|
||||||
|
-rainbow menu selection
|
||||||
|
-break out hardcoded globals into config files
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue