Merge pull request #33 from modgethanc/issues-30

implements default nopub feature
master
hvincent 2018-02-28 17:38:17 -05:00 committed by GitHub
commit 091240c489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 180 additions and 94 deletions

View File

@ -4,7 +4,7 @@ from setuptools import setup
setup(
name='ttbp',
version='0.10.2',
version='0.11.2',
description='command line social blogging tool used on tilde.town',
url='https://github.com/modgethanc/ttbp',
author='~endorphant',
@ -20,6 +20,7 @@ setup(
'inflect==0.2.5',
'mistune==0.8.1',
'colorama==0.3.9',
'six'
],
include_package_data = True,
entry_points = {

View File

@ -82,7 +82,7 @@ ___________________________________________________________
| ____ ____ ____ _ ____ ____ _ _ ____ _ _ _ ____ |
| |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ |
| | |___ |___ |___ ___] |___ | \| |__] | | \| |___ |
| ver 0.11.1 (rainbows) |
| ver 0.11.2 (rainbows) |
|__________________________________________________________|
'''.lstrip()
@ -146,4 +146,12 @@ version 0.9.3 features:
exciting
* general PSA: feel free to use the github repo for bugs/feature requests:
https://github.com/modgethanc/ttbp/issues""",
}
"0.11.2": """
~[version 0.11.2 update]~
* added a new option to allow setting entries to default to either public or
non-public on posting; this option only really makes sense if you're
already publishing to html/gopher, but is available either way!
you can find this option under 'settings' as 'post as nopub'."""
}

View File

@ -235,57 +235,60 @@ def write_global_feed(blogList):
prints to blog feed
'''
outfile = open(FEED, "w")
try:
outfile = open(FEED, "w")
## header
outfile.write("""\
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
<html>
<head>
<title>tilde.town feels engine</title>
<link rel=\"stylesheet\" href=\"style.css\" />
</head>
<body>
<div class="meta">
<h1>tilde.town feels engine</h1>
## header
outfile.write("""\
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
<html>
<head>
<title>tilde.town feels engine</title>
<link rel=\"stylesheet\" href=\"style.css\" />
</head>
<body>
<div class="meta">
<h1>tilde.town feels engine</h1>
<h2><a href="https://github.com/modgethanc/ttbp">github
repo</a> | <a
href="http://tilde.town/~endorphant/blog/20160510.html">state
of the ttbp</a></h2>
<!--<p>curious? run <b>~endorphant/bin/ttbp</b> while logged in to tilde.town.</p>
<p>it's still a little volatile. let me know if anything breaks.</p>---></div>
<p>&nbsp;</p>
""")
<h2><a href="https://github.com/modgethanc/ttbp">github
repo</a> | <a
href="http://tilde.town/~endorphant/blog/20160510.html">state
of the ttbp</a></h2>
<!--<p>curious? run <b>~endorphant/bin/ttbp</b> while logged in to tilde.town.</p>
<p>it's still a little volatile. let me know if anything breaks.</p>---></div>
<p>&nbsp;</p>
""")
## docs
outfile.write("""\
<div class="docs">""")
outfile.write(mistune.markdown(open(os.path.join(config.INSTALL_PATH, "..", "README.md"), "r").read()))
outfile.write("""\
</div>""")
## docs
outfile.write("""\
<div class="docs">""")
outfile.write(mistune.markdown(open(os.path.join(config.INSTALL_PATH, "..", "README.md"), "r").read()))
outfile.write("""\
</div>""")
## feed
outfile.write("""\
<p>&nbsp;</p>
<div class=\"feed\">
<h3>live feels-sharing:</h3>
<ul>""")
for blog in blogList:
## feed
outfile.write("""\
<p>&nbsp;</p>
<div class=\"feed\">
<h3>live feels-sharing:</h3>
<ul>""")
for blog in blogList:
outfile.write("""
<li>"""+blog+"""</li>\
""")
## footer
outfile.write("""
<li>"""+blog+"""</li>\
""")
</ul>
</div>
</body>
</html>
""")
## footer
outfile.write("""
</ul>
</div>
</body>
</html>
""")
outfile.close()
#subprocess.call(['chmod', 'a+w', FEED])
outfile.close()
#subprocess.call(['chmod', 'a+w', FEED])
except FileNotFoundError:
pass
## misc helpers
@ -309,7 +312,7 @@ def meta(entries = FILES):
for filename in entries:
mtime = os.path.getmtime(filename)
try:
wc = subprocess.check_output(["wc","-w",filename], stderr=subprocess.STDOUT).split()[0]
wc = int(subprocess.check_output(["wc","-w",filename], stderr=subprocess.STDOUT).split()[0])
except subprocess.CalledProcessError:
wc = "???"
timestamp = time.strftime("%Y-%m-%d at %H:%M", time.localtime(mtime))

View File

@ -40,6 +40,7 @@ import time
import json
from email.mime.text import MIMEText
import datetime
from six.moves import input
import inflect
@ -49,7 +50,7 @@ from . import chatter
from . import gopher
from . import util
__version__ = "0.11.1"
__version__ = "0.11.2"
__author__ = "endorphant <endorphant@tilde.town)"
p = inflect.engine()
@ -107,7 +108,7 @@ def menu_handler(options, prompt, pagify=10, rainbow=False, top=""):
return util.list_select(options, prompt)
else:
return page_helper(options, prompt, pagify, rainbow, page, total, top)
return page_helper(options, prompt, pagify, rainbow, page, int(total), top)
def page_helper(options, prompt, pagify, rainbow, page, total, top):
'''
@ -125,7 +126,7 @@ def page_helper(options, prompt, pagify, rainbow, page, total, top):
optPage = options[x:y]
util.print_menu(optPage, SETTINGS.get("rainbows", False))
print("\n\t( page {page} of {total}; type 'u' or 'd' to scroll up and down )").format(page=page+1, total=total+1)
print("\n\t( page {page} of {total}; type 'u' or 'd' to scroll up and down)".format(page=page+1, total=total+1))
ans = util.list_select(optPage, prompt)
@ -224,14 +225,16 @@ def check_init():
print("{greeting}, {user}".format(greeting=chatter.say("greet"),
user=config.USER))
load_settings = load_user_settings()
## ttbp env validation
if not user_up_to_date():
update_user_version()
if not valid_setup():
if not valid_setup(load_settings):
setup_repair()
else:
raw_input("press <enter> to explore your feels.\n\n")
input("press <enter> to explore your feels.\n\n")
core.load(SETTINGS)
@ -244,7 +247,7 @@ def init():
"""
try:
raw_input("""
input("""
i don't recognize you, stranger. let's make friends.
press <enter> to begin, or <ctrl-c> to get out of here.""")
@ -294,7 +297,7 @@ press <enter> to begin, or <ctrl-c> to get out of here.""")
setup()
core.load(SETTINGS)
raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
return ""
def gen_header():
@ -326,23 +329,14 @@ def gen_header():
"""
return header
def valid_setup():
def valid_setup(load_settings):
'''
Checks to see if user has a valid ttbp environment.
'''
global SETTINGS
if not os.path.isfile(config.TTBPRC):
if not load_settings:
return False
try:
SETTINGS = json.load(open(config.TTBPRC))
except ValueError:
return False
core.load(SETTINGS)
for option in iter(DEFAULT_SETTINGS):
if option != "publish dir" and SETTINGS.get(option, None) is None:
return False
@ -361,6 +355,24 @@ def valid_setup():
return True
def load_user_settings():
"""attempts to load user's ttbprc; returns settings dict if valie, otherwise
returns false"""
global SETTINGS
if not os.path.isfile(config.TTBPRC):
return False
try:
SETTINGS = json.load(open(config.TTBPRC))
except ValueError:
return False
core.load(SETTINGS)
return SETTINGS
def setup_repair():
'''
setup repair function
@ -380,7 +392,8 @@ def setup_repair():
"publishing": select_publishing,
"publish dir": select_publish_dir,
"gopher": gopher.select_gopher,
"rainbows": toggle_rainbows
"rainbows": toggle_rainbows,
"post as nopub": toggle_pub_default
}
for option in iter(settings_map):
@ -394,7 +407,7 @@ def setup_repair():
print("...")
time.sleep(1)
raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n")
def setup():
'''
@ -418,7 +431,7 @@ def setup():
util.print_menu(menuOptions, SETTINGS.get("rainbows", False))
try:
choice = raw_input("\npick a setting to change (or type 'q' to exit): ")
choice = input("\npick a setting to change (or type 'q' to exit): ")
except KeyboardInterrupt:
redraw(EJECT)
return SETTINGS
@ -473,7 +486,14 @@ def setup():
save_settings()
return setup()
raw_input("\nyou're all good to go, {friend}! hit <enter> to continue.\n\n".format(friend=chatter.say("friend")))
#nopub toggling
elif settingList[int(choice)] == "post as nopub":
SETTINGS.update({"post as nopub": toggle_pub_default()})
redraw("posting default set to {nopub}".format(nopub=SETTINGS.get("post as nopub")))
save_settings()
return setup()
input("\nyou're all good to go, {friend}! hit <enter> to continue.\n\n".format(friend=chatter.say("friend")))
redraw()
return SETTINGS
@ -509,7 +529,7 @@ def main_menu():
util.print_menu(menuOptions, SETTINGS.get("rainbows", False))
try:
choice = raw_input("\ntell me about your feels (or type 'q' to exit): ")
choice = input("\ntell me about your feels (or type 'q' to exit): ")
except KeyboardInterrupt:
redraw(EJECT)
return main_menu()
@ -569,12 +589,12 @@ def feedback_menu():
'''
util.print_menu(SUBJECTS, SETTINGS.get("rainbows", False))
choice = raw_input("\npick a category for your feedback: ")
choice = input("\npick a category for your feedback: ")
cat = ""
if choice in ['0', '1', '2', '3']:
cat = SUBJECTS[int(choice)]
entered = raw_input("""
entered = input("""
composing a {mail_category} to ~endorphant.
press <enter> to open an external text editor. mail will be sent once you save and quit.
@ -752,7 +772,7 @@ i'd love to hear about your ideas and brainstorm about new features!
thanks to everyone who reads, listens, writes, and feels.\
""")
raw_input("\n\npress <enter> to go back home.\n\n")
input("\n\npress <enter> to go back home.\n\n")
redraw()
return
@ -764,7 +784,7 @@ def write_entry(entry=os.path.join(config.USER_DATA, "test.txt")):
main feels-recording handler
'''
entered = raw_input("""
entered = input("""
feels will be recorded for today, {today}.
if you've already started recording feels for this day, you
@ -786,17 +806,21 @@ editor.
left = ""
if core.publishing():
core.load_files()
core.write("index.html")
left = "posted to {url}/index.html\n\n>".format(
url="/".join(
[config.LIVE+config.USER,
str(SETTINGS.get("publish dir"))]))
if SETTINGS.get("post as nopub"):
core.toggle_nopub(os.path.basename(entry))
else:
if core.publishing():
core.write("index.html")
left = "posted to {url}/index.html\n\n>".format(
url="/".join(
[config.LIVE+config.USER,
str(SETTINGS.get("publish dir"))]))
if SETTINGS.get('gopher'):
gopher.publish_gopher('feels', core.get_files())
left += " also posted to your ~/public_gopher!\n"
if SETTINGS.get('gopher'):
gopher.publish_gopher('feels', core.get_files())
left += " also posted to your ~/public_gopher!\n"
core.load_files()
redraw(left + " thanks for sharing your feels!")
return
@ -976,7 +1000,7 @@ 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")
input("press <enter> to visit the wall\n\n")
subprocess.call([SETTINGS.get("editor"), config.WALL])
subprocess.call(["rm", config.WALL_LOCK])
redraw("thanks for visiting the graffiti wall!")
@ -984,6 +1008,46 @@ your changes by exiting without saving.
## misc helpers
def toggle_pub_default():
"""setup helper for setting default publish privacy (does not apply
retroactively). """
if SETTINGS.get("post as nopub", False) is True:
(nopub, will) = ("(nopub)", "won't")
else:
(nopub, will) = ("public", "will")
if SETTINGS.get("publishing", False) is True:
publishing = ""
else:
publishing = """\
since you're currently not publishing your posts to html/gopher, this setting
won't affect the visibility of your posts. however, the option is still here if
you'd like to change it.
"""
print("""
DEFAULT POST PRIVACY
your entries are set to automatically post as {nopub}. this means they {will} be
posted to your world-visible pages at first (which you can always change after
the fact.)
this setting only affects subsequent posts; it does not apply retroactively.
{publishing}""".format(nopub=nopub, will=will, publishing=publishing))
ans = util.input_yn("""\
would you like to change this behavior?
please enter""")
if ans:
return not SETTINGS.get("post as nopub")
else:
return SETTINGS.get("post as nopub")
def toggle_rainbows():
"""setup helper for rainbow toggling
"""
@ -1037,13 +1101,13 @@ def select_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\") ")
choice = input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ")
if not choice:
choice = "blog"
publishDir = os.path.join(config.PUBLIC, choice)
while os.path.exists(publishDir):
second = raw_input("\n"+publishDir+"""\
second = input("\n"+publishDir+"""\
already exists!
setting this as your publishing directory means this program may
@ -1244,7 +1308,6 @@ def update_user_version():
ttbprc.close()
# from earlier than 0.10.1
if y < 10:
# select gopher
print("[ NEW FEATURE ]")
@ -1266,6 +1329,12 @@ def update_user_version():
print("[ NEW FEATURE ]")
SETTINGS.update({"rainbows": toggle_rainbows()})
if z < 2:
# set default option for 0.11.2
# print("default nopub: false")
SETTINGS.update({"post as nopub": False})
save_settings()
print("""
you're all good to go, """+chatter.say("friend")+"""! please contact ~endorphant if
something strange happened to you during this update.
@ -1283,10 +1352,14 @@ something strange happened to you during this update.
# version 0.11.1 patch notes
print(config.UPDATES["0.11.1"])
if y < 11 or z < 2:
# version 0.11.2 patch notes
print(config.UPDATES["0.11.2"])
confirm = ""
while confirm not in ("x", "<x>", "X", "<X>"):
confirm = raw_input("\nplease type <x> when you've finished reading about the updates! ")
confirm = input("\nplease type <x> when you've finished reading about the updates! ")
print("\n\n")

View File

@ -25,6 +25,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''
import random
import time
from six.moves import input
import colorama
import inflect
@ -179,7 +180,7 @@ def list_select(options, prompt):
ans = ""
invalid = True
choice = raw_input("\n"+prompt)
choice = input("\n"+prompt)
if choice in BACKS:
return False
@ -205,11 +206,11 @@ def input_yn(query):
'''
try:
ans = raw_input(query+" [y/n] ")
ans = input(query+" [y/n] ")
except KeyboardInterrupt:
input_yn(query)
while ans not in ["y", "n"]:
ans = raw_input("'y' or 'n' please: ")
ans = input("'y' or 'n' please: ")
return ans == "y"