diff --git a/README.rst b/README.rst index 02f229c..301bc8f 100644 --- a/README.rst +++ b/README.rst @@ -91,6 +91,19 @@ Other ----- More to come. Send me a patch or pull request if you can't wait and have written one yourself :-) +Config File +=========== +``nvchecker`` supports a config file, which contains whatever you would give on commandline every time. This file is at ``~/.nvcheckerrc`` by default, and can be changed by the ``-c`` option. You can specify ``-c /dev/null`` to disable the default config file temporarily. + +A typical config file looks like this:: + --oldver ~/.nvchecker/versionlist.txt --newver ~/.nvchecker/versionlist_new.txt + +``~`` and environmental variables will be expanded. Options given on commandline override those in a config file. + Bugs ----- +==== * Finish writing results even on Ctrl-C or other interruption. + +TODO +==== +* ``nvtake`` command diff --git a/nvchecker/config.py b/nvchecker/config.py deleted file mode 100644 index 82aa734..0000000 --- a/nvchecker/config.py +++ /dev/null @@ -1,3 +0,0 @@ -# vim:fileencoding=utf-8 - - diff --git a/nvchecker/main.py b/nvchecker/main.py index ee41948..363e771 100755 --- a/nvchecker/main.py +++ b/nvchecker/main.py @@ -95,7 +95,7 @@ def main(): help='show desktop notifications when a new version is available') util.add_common_arguments(parser) - args = parser.parse_args() + args = util.parse_args(parser) if util.process_common_arguments(args): return diff --git a/nvchecker/util.py b/nvchecker/util.py index 1c5d7ae..4d95cee 100644 --- a/nvchecker/util.py +++ b/nvchecker/util.py @@ -1,22 +1,52 @@ +import os +import sys import logging from .lib import nicelogger from . import __version__ +_DEFAULT_CONFIG = os.path.expanduser('~/.nvcheckerrc') + def add_common_arguments(parser): parser.add_argument('-i', '--oldver', help='read an existing version record file') parser.add_argument('-o', '--newver', help='write a new version record file') - # parser.add_argument('-r', '--rc', default=os.path.expanduser('~/.nvcheckerrc'), - # help='specify the nvcheckerrc file to use') + parser.add_argument('-c', default=_DEFAULT_CONFIG, + help='specify the nvcheckerrc file to use') parser.add_argument('-l', '--logging', choices=('debug', 'info', 'warning', 'error'), default='info', help='logging level (default: info)') parser.add_argument('-V', '--version', action='store_true', help='show version and exit') +def _get_rcargs(): + args = sys.argv[1:] + args.reverse() + it = iter(args) + + try: + f = next(it) + while True: + j = next(it) + if j == '-c': + break + f = j + except StopIteration: + if os.path.exists(_DEFAULT_CONFIG): + f = _DEFAULT_CONFIG + else: + return [] + + return [os.path.expandvars(os.path.expanduser(x)) + for x in open(f, 'r').read().split()] + +def parse_args(parser): + args = _get_rcargs() + args += sys.argv[1:] + return parser.parse_args(args) + def process_common_arguments(args): '''return True if should stop''' nicelogger.enable_pretty_logging(getattr(logging, args.logging.upper()))