Intermediate commit.

This commit is contained in:
Michael Lazar
2015-09-27 16:23:34 -07:00
parent cb2de5965a
commit dfc5ddef1a
7 changed files with 171 additions and 28 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,5 @@
.* .*
*.pyc *.pyc
scripts
build build
dist dist
rtv.egg-info rtv.egg-info

6
rtv.1
View File

@@ -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 .SH NAME
rtv - Browse Reddit from your terminal rtv - Browse Reddit from your terminal
.SH SYNOPSIS .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 .SH DESCRIPTION
.B Reddit Terminal Viewer .B Reddit Terminal Viewer
is a lightweight browser for www.reddit.com built into a is a lightweight browser for www.reddit.com built into a
@@ -24,7 +24,7 @@ enable ascii\-only mode
\fB\-\-log\fR FILE \fB\-\-log\fR FILE
Log HTTP requests Log HTTP requests
.PP .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. 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 .PP
.SH FILES .SH FILES

View File

@@ -1,6 +1,5 @@
import os import os
import sys import sys
import argparse
import locale import locale
import logging import logging
@@ -14,7 +13,7 @@ from .exceptions import SubmissionError, SubredditError, SubscriptionError, Prog
from .curses_helpers import curses_session, LoadScreen from .curses_helpers import curses_session, LoadScreen
from .submission import SubmissionPage from .submission import SubmissionPage
from .subreddit import SubredditPage from .subreddit import SubredditPage
from .docs import * from .docs import AGENT
from .oauth import OAuthTool from .oauth import OAuthTool
from .__version__ import __version__ from .__version__ import __version__
@@ -27,23 +26,6 @@ __all__ = []
# ptrace_scope to 0 in /etc/sysctl.d/10-ptrace.conf. # ptrace_scope to 0 in /etc/sysctl.d/10-ptrace.conf.
# http://blog.mellenthin.de/archives/2010/10/18/gdb-attach-fails # 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(): def main():
"Main entry point" "Main entry point"
@@ -60,7 +42,9 @@ def main():
# Fill in empty arguments with config file values. Parameters explicitly # Fill in empty arguments with config file values. Parameters explicitly
# typed on the command line will take priority over config file params. # 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() local_config = config.load_config()
for key, val in local_config.items(): for key, val in local_config.items():
if getattr(args, key, None) is None: if getattr(args, key, None) is None:

View File

@@ -2,8 +2,11 @@
Global configuration settings Global configuration settings
""" """
import os import os
import argparse
from six.moves import configparser from six.moves import configparser
from . import docs
HOME = os.path.expanduser('~') HOME = os.path.expanduser('~')
XDG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.join(HOME, '.config')) XDG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.join(HOME, '.config'))
CONFIG = os.path.join(XDG_HOME, 'rtv', 'rtv.cfg') CONFIG = os.path.join(XDG_HOME, 'rtv', 'rtv.cfg')
@@ -21,6 +24,34 @@ oauth_redirect_port = 65000
oauth_scope = ['edit', 'history', 'identity', 'mysubreddits', 'privatemessages', oauth_scope = ['edit', 'history', 'identity', 'mysubreddits', 'privatemessages',
'read', 'report', 'save', 'submit', 'subscribe', 'vote'] '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(): def load_config():
""" """
Attempt to load settings from the local config file. Attempt to load settings from the local config file.

29
scripts/build_manpage.py Normal file
View File

@@ -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

View File

@@ -1,7 +1,7 @@
from setuptools import setup
from version import __version__ as version
import sys import sys
import setuptools
from version import __version__ as version
requirements = ['tornado', 'praw>=3.1.0', 'six', 'requests', 'kitchen'] 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: if sys.version_info.major <= 2:
requirements.append('futures') requirements.append('futures')
setup( setuptools.setup(
name='rtv', name='rtv',
version=version, version=version,
description='A simple terminal viewer for Reddit (Reddit Terminal Viewer)', description='A simple terminal viewer for Reddit (Reddit Terminal Viewer)',

100
templates/rtv.1 Normal file
View File

@@ -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 <twodopeshaggy@gmail.com> (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