use appdirs for the default configuration file

closes #97.
This commit is contained in:
lilydjwg 2020-08-31 17:33:55 +08:00
parent 2a2c67090c
commit bc1f9df8c6
3 changed files with 6 additions and 6 deletions

View file

@ -64,7 +64,7 @@ Contents
Dependency Dependency
========== ==========
- Python 3.7+ - Python 3.7+
- Python library: structlog, toml - Python library: structlog, toml, appdirs
- One of these Python library combinations (ordered by preference): - One of these Python library combinations (ordered by preference):
* tornado + pycurl * tornado + pycurl
@ -124,7 +124,7 @@ Upgrade from 1.x version
There are several backward-incompatible changes from the previous 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. 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. 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 ``_``. 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. 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.

View file

@ -22,6 +22,7 @@ import json
import structlog import structlog
import toml import toml
import appdirs
from .lib import nicelogger from .lib import nicelogger
from . import slogconf from . import slogconf
@ -36,8 +37,8 @@ from .ctxvars import tries as ctx_tries
logger = structlog.get_logger(logger_name=__name__) logger = structlog.get_logger(logger_name=__name__)
def get_default_config() -> str: def get_default_config() -> str:
confdir = os.environ.get('XDG_CONFIG_DIR', os.path.expanduser('~/.config')) confdir = appdirs.user_config_dir(appname='nvchecker')
file = os.path.join(confdir, 'nvchecker/nvchecker.toml') file = os.path.join(confdir, 'nvchecker.toml')
return file return file
def add_common_arguments(parser: argparse.ArgumentParser) -> None: def add_common_arguments(parser: argparse.ArgumentParser) -> None:

View file

@ -21,7 +21,7 @@ setup(
zip_safe = True, zip_safe = True,
packages = find_namespace_packages(exclude=['tests', 'build*']), 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 = { extras_require = {
'vercmp': ['pyalpm'], 'vercmp': ['pyalpm'],
}, },
@ -39,7 +39,6 @@ setup(
], ],
}, },
scripts=['scripts/nvchecker-ini2toml'], scripts=['scripts/nvchecker-ini2toml'],
package_data = {'nvchecker_source': ['vcs.sh']},
classifiers = [ classifiers = [
"Development Status :: 5 - Production/Stable", "Development Status :: 5 - Production/Stable",