mirror of
https://github.com/lilydjwg/nvchecker
synced 2024-12-27 00:52:12 +00:00
add config file support
This commit is contained in:
parent
e1457aadd3
commit
fd99a076e9
15
README.rst
15
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
|
||||
|
@ -1,3 +0,0 @@
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()))
|
||||
|
Loading…
Reference in New Issue
Block a user