Intermediate commit.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user