diff --git a/.gitignore b/.gitignore index 8d95405..526dedd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .* *.pyc -scripts build dist rtv.egg-info diff --git a/rtv.1 b/rtv.1 index 1b3e795..3343d54 100644 --- a/rtv.1 +++ b/rtv.1 @@ -1,8 +1,8 @@ -.TH "rtv" "1" "September 2015" "Version 20150919" "Usage and Commands" +.TH "RTV" "1" "September 2015" "Version 1.5" "Usage and Commands" .SH NAME rtv - Browse Reddit from your terminal .SH SYNOPSIS -rtv [-h] [-s SUBREDDIT] [-l LINK] [--ascii] [--log FILE] [-u USERNAME] +rtv [-h] [-s SUBREDDIT] [-l LINK] [--ascii] [--log FILE] [-u USERNAME] [--non-persistant] [--clear-auth] .SH DESCRIPTION .B Reddit Terminal Viewer is a lightweight browser for www.reddit.com built into a @@ -24,7 +24,7 @@ enable ascii\-only mode \fB\-\-log\fR FILE Log HTTP requests .PP -.SS "Controls" +.SH CONTROLS RTV has different commands to easily navigate through subreddits and individual submissions. These can all be viewed along with a short description by pressing the \fB?\fR key at any time while running rtv. .PP .SH FILES diff --git a/rtv/__main__.py b/rtv/__main__.py index 06d0e19..8982fd2 100644 --- a/rtv/__main__.py +++ b/rtv/__main__.py @@ -1,6 +1,5 @@ import os import sys -import argparse import locale import logging @@ -14,7 +13,7 @@ from .exceptions import SubmissionError, SubredditError, SubscriptionError, Prog from .curses_helpers import curses_session, LoadScreen from .submission import SubmissionPage from .subreddit import SubredditPage -from .docs import * +from .docs import AGENT from .oauth import OAuthTool from .__version__ import __version__ @@ -27,23 +26,6 @@ __all__ = [] # ptrace_scope to 0 in /etc/sysctl.d/10-ptrace.conf. # http://blog.mellenthin.de/archives/2010/10/18/gdb-attach-fails -def command_line(): - - parser = argparse.ArgumentParser( - prog='rtv', description=SUMMARY, - epilog=CONTROLS + HELP, - formatter_class=argparse.RawDescriptionHelpFormatter) - - parser.add_argument('-s', dest='subreddit', help='name of the subreddit that will be opened on start') - parser.add_argument('-l', dest='link', help='full URL of a submission that will be opened on start') - parser.add_argument('--ascii', action='store_true', help='enable ascii-only mode') - parser.add_argument('--log', metavar='FILE', action='store', help='log HTTP requests to a file') - parser.add_argument('--non-persistent', dest='persistent', action='store_false', help='Forget all authenticated users when the program exits') - parser.add_argument('--clear-auth', dest='clear_auth', action='store_true', help='Remove any saved OAuth tokens before starting') - args = parser.parse_args() - - return args - def main(): "Main entry point" @@ -60,7 +42,9 @@ def main(): # Fill in empty arguments with config file values. Parameters explicitly # typed on the command line will take priority over config file params. - args = command_line() + parser = config.build_parser() + args = parser.parse_args() + local_config = config.load_config() for key, val in local_config.items(): if getattr(args, key, None) is None: diff --git a/rtv/config.py b/rtv/config.py index 999dfce..d3a1beb 100644 --- a/rtv/config.py +++ b/rtv/config.py @@ -2,8 +2,11 @@ Global configuration settings """ import os +import argparse from six.moves import configparser +from . import docs + HOME = os.path.expanduser('~') XDG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.join(HOME, '.config')) CONFIG = os.path.join(XDG_HOME, 'rtv', 'rtv.cfg') @@ -21,6 +24,34 @@ oauth_redirect_port = 65000 oauth_scope = ['edit', 'history', 'identity', 'mysubreddits', 'privatemessages', 'read', 'report', 'save', 'submit', 'subscribe', 'vote'] +def build_parser(): + + parser = argparse.ArgumentParser( + prog='rtv', description=docs.SUMMARY, epilog=docs.CONTROLS+docs.HELP, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument( + '-V', '--version', action='version', version='rtv '+docs.__version__, + ) + parser.add_argument( + '-s', dest='subreddit', + help='name of the subreddit that will be opened on start') + parser.add_argument( + '-l', dest='link', + help='full URL of a submission that will be opened on start') + parser.add_argument( + '--ascii', action='store_true', + help='enable ascii-only mode') + parser.add_argument( + '--log', metavar='FILE', action='store', + help='log HTTP requests to a file') + parser.add_argument( + '--non-persistent', dest='persistent', action='store_false', + help='Forget all authenticated users when the program exits') + parser.add_argument( + '--clear-auth', dest='clear_auth', action='store_true', + help='Remove any saved OAuth tokens before starting') + return parser + def load_config(): """ Attempt to load settings from the local config file. diff --git a/scripts/build_manpage.py b/scripts/build_manpage.py new file mode 100644 index 0000000..114f97e --- /dev/null +++ b/scripts/build_manpage.py @@ -0,0 +1,29 @@ +""" +Internal tool used to automatically generate an up-to-date version of the rtv +man page. Currently this script should be manually ran after each version bump. +In the future, it would be nice to have this functionality built into setup.py. + +Usage: + $ python scripts/build_manpage.py +""" +from datetime import datetime + +from rtv import docs, config + +parser = config.build_parser() +help = parser.format_help() +help_sections = help.split('\n\n') + +data = {} +data['version'] = docs.__version__ +data['release_date'] = datetime.utcnow().strftime('%B %d, %Y') +data['synopsis'] = help_sections[0].replace('usage: ', '') +data['description'] = help_sections[1] + +options = '' +arguments = help_sections[2].split('\n')[:1] +for argument in arguments: + options += '' + + +pass diff --git a/setup.py b/setup.py index 2506e16..2fbeee4 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ -from setuptools import setup -from version import __version__ as version - import sys +import setuptools + +from version import __version__ as version requirements = ['tornado', 'praw>=3.1.0', 'six', 'requests', 'kitchen'] @@ -9,7 +9,7 @@ requirements = ['tornado', 'praw>=3.1.0', 'six', 'requests', 'kitchen'] if sys.version_info.major <= 2: requirements.append('futures') -setup( +setuptools.setup( name='rtv', version=version, description='A simple terminal viewer for Reddit (Reddit Terminal Viewer)', diff --git a/templates/rtv.1 b/templates/rtv.1 new file mode 100644 index 0000000..dc608ef --- /dev/null +++ b/templates/rtv.1 @@ -0,0 +1,100 @@ +.TH "RTV" "1" "{release_date}" "Version {version}" "Usage and Commands" +.SH NAME +RTV - Reddit Terminal Viewer +.SH SYNOPSIS +{synopsis} +.SH DESCRIPTION +{description} +.SH OPTIONS +.TP +\fB\-h\fR, \fB\-\-help\fR +show this help message and exit +.TP +\fB\-s\fR SUBREDDIT +subreddit name +.TP +\fB\-l\fR LINK +full link to a submission +.TP +\fB\-\-ascii\fR +enable ascii\-only mode +.TP +\fB\-\-log\fR FILE +Log HTTP requests +.PP +.SH CONTROLS +RTV has different commands to easily navigate through subreddits and individual submissions. These can all be viewed along with a short description by pressing the \fB?\fR key at any time while running rtv. +.PP +.SH FILES +.TP +All config files can make use of $XDG_CONFIG_HOME which allows you to place them in other places then the given example paths. +.TP +~/.config/rtv/rtv.cfg +Personal configuration file. +.TP +~/.config/rtv/refresh-token +Session token for OAuth login, if you do not wish to have a persistent login you can set the option \fBpersistent=False\fR in the config file. But some features will not be available. + +.SH CONFIG FILE EXAMPLE +.B RTV +has many options that can be set in a configuration file. Here is a simple example configuration. + +.nf +[rtv] +# Log file location +log=/tmp/rtv.log + +# Default subreddit +subreddit=CollegeBasketball + +# Default submission link - will be opened every time the program starts +link=http://www.reddit.com/r/CollegeBasketball/comments/31irjq + +# Turn on ascii-only mode and disable all unicode characters +# This may be necessary for compatibility with some terminal browsers +ascii=True + +# Enable persistent storage of your authentication token +# This allows you to remain logged in when you restart the program +persistent=True + +.SH ENVIROMENT VARIABLES +.B RTV +Supports enviroment variables that can help improve your experience. These options can be set in the current shell. Or placed in your configuration file for your shell of choice. Such as +.IR ~/.bashrc +or +.IR ~/.zshrc +, restarting your session will make these settings persistent for future use of +.B RTV. +.TP +.BR RTV_EDITOR +Setting +.IR export +.IR RTV_EDITOR=gedit +will open gedit as your editor when composing comments and replies. +If no editor is set, +.B RTV +will fall back to the environment's default +.IR $EDITOR +, and as an extra fall back nano. + +.TP +.BR BROWSER +.B RTV +can open links in any browser you wish to use. Most system's will open the default such as Firefox or Chrome. But if you prefer to enjoy a terminal only experience, you can use +.IR $BROWSER +to set a browser such as w3m, lynx, and elinks. For example w3m would be +.IR export +.IR BROWSER=w3m + + +.PP +.SH AUTHOR +Written by Johnathan "ShaggyTwoDope" Jenkins (2015). +.SH REPORTING BUGS +Report bugs to +.I https://github.com/michael-lazar/rtv/issues +.SH COPYRIGHT +Copyright \(co 2015 michael-lazar +License MIT. +.PP