From bc1f9df8c6b5a37e94ea742043e348a63d083787 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Mon, 31 Aug 2020 17:33:55 +0800 Subject: [PATCH] use appdirs for the default configuration file closes #97. --- README.rst | 4 ++-- nvchecker/core.py | 5 +++-- setup.py | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index f32baf6..eeb7e01 100644 --- a/README.rst +++ b/README.rst @@ -64,7 +64,7 @@ Contents Dependency ========== - Python 3.7+ -- Python library: structlog, toml +- Python library: structlog, toml, appdirs - One of these Python library combinations (ordered by preference): * tornado + pycurl @@ -124,7 +124,7 @@ Upgrade from 1.x version There are several backward-incompatible changes from the previous 1.x version. 1. Version 2.x requires Python 3.7+ to run. -2. The command syntax changes a bit. You need to use a ``-c`` switch to specify your software version configuration file. +2. The command syntax changes a bit. You need to use a ``-c`` switch to specify your software version configuration file (or use the default). 3. The configuration file format has been changed from ini to `toml`_. You can use the ``nvchecker-ini2toml`` script in this repo to convert your old configuration files. However, comments and formatting will be lost. 4. Several options have been renamed. ``max_concurrent`` to ``max_concurrency``, and all option names have their ``-`` be replaced with ``_``. 5. All software configuration tables need a ``source`` option to specify which source is to be used rather than being figured out from option names in use. This enables additional source plugins to be discovered. diff --git a/nvchecker/core.py b/nvchecker/core.py index 9666001..e753eeb 100644 --- a/nvchecker/core.py +++ b/nvchecker/core.py @@ -22,6 +22,7 @@ import json import structlog import toml +import appdirs from .lib import nicelogger from . import slogconf @@ -36,8 +37,8 @@ from .ctxvars import tries as ctx_tries logger = structlog.get_logger(logger_name=__name__) def get_default_config() -> str: - confdir = os.environ.get('XDG_CONFIG_DIR', os.path.expanduser('~/.config')) - file = os.path.join(confdir, 'nvchecker/nvchecker.toml') + confdir = appdirs.user_config_dir(appname='nvchecker') + file = os.path.join(confdir, 'nvchecker.toml') return file def add_common_arguments(parser: argparse.ArgumentParser) -> None: diff --git a/setup.py b/setup.py index 4e0e58d..798ffb3 100755 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( zip_safe = True, packages = find_namespace_packages(exclude=['tests', 'build*']), - install_requires = ['setuptools', 'toml', 'structlog', 'tornado>=6', 'pycurl'], + install_requires = ['setuptools', 'toml', 'structlog', 'appdirs', 'tornado>=6', 'pycurl'], extras_require = { 'vercmp': ['pyalpm'], }, @@ -39,7 +39,6 @@ setup( ], }, scripts=['scripts/nvchecker-ini2toml'], - package_data = {'nvchecker_source': ['vcs.sh']}, classifiers = [ "Development Status :: 5 - Production/Stable",