diff --git a/NEW b/NEW
index a32414f..e2e87d1 100644
--- a/NEW
+++ b/NEW
@@ -1,4 +1,3 @@
TODO:
* update README
* create source plugin documentation
-* a script to convert old ini into new toml files
diff --git a/README.rst b/README.rst
index 3a1a9aa..230fb94 100644
--- a/README.rst
+++ b/README.rst
@@ -59,12 +59,13 @@ Contents
Dependency
==========
-- Python 3.5+
-- Python library: structlog
+- Python 3.7+
+- Python library: structlog, toml
- One of these Python library combinations (ordered by preference):
* tornado + pycurl
* aiohttp
+ * httpx with http2 support
* tornado
- All commands used in your version source files
@@ -83,9 +84,9 @@ To see available options::
nvchecker --help
-Run with one or more software version source files::
+Run with one or more software version files::
- nvchecker source_file
+ nvchecker -c config_file
You normally will like to specify some "version record files"; see below.
@@ -256,7 +257,7 @@ Check `Arch User Repository `_ for updates.
aur
The package name in AUR. If empty, use the name of software (the *section name*).
-strip-release
+strip_release
Strip the release part.
use_last_modified
@@ -447,7 +448,7 @@ This is used when you run ``nvchecker`` on an Arch Linux system and the program
pacman
The package name to reference to.
-strip-release
+strip_release
Strip the release part.
Check Arch Linux official packages
@@ -457,7 +458,7 @@ This enables you to track the update of `Arch Linux official packages , et al.
-
-from importlib import import_module
-
-import structlog
-
-logger = structlog.get_logger(logger_name=__name__)
-
-_handler_precedence = (
- 'github', 'aur', 'pypi', 'archpkg', 'debianpkg', 'ubuntupkg',
- 'gems', 'pacman',
- 'cmd', 'bitbucket', 'regex', 'manual', 'vcs',
- 'cratesio', 'npm', 'hackage', 'cpan', 'gitlab', 'packagist',
- 'repology', 'anitya', 'android_sdk', 'sparkle', 'gitea'
-)
-
-_Task = namedtuple('_Task', 'batch_mode main args names')
-
-class Dispatcher:
- def __init__(self):
- self.futures = []
- self.mods = {}
- self.tasks_dedupe = {}
-
- def add_task(self, name, conf, **kwargs):
- for key in _handler_precedence:
- if key not in conf:
- continue
-
- value = self.mods.get(key)
- if not value:
- mod = import_module(
- '.source.' + key, __package__)
- batch_mode = getattr(mod, 'BATCH_MODE', False)
- if batch_mode:
- main = mod.Batcher()
- else:
- main = mod.get_version
- get_cacheable_conf = getattr(mod, 'get_cacheable_conf', lambda name, conf: conf)
- self.mods[key] = batch_mode, main, get_cacheable_conf
- else:
- batch_mode, main, get_cacheable_conf = value
-
- cacheable_conf = get_cacheable_conf(name, conf)
- cache_key = tuple(sorted(cacheable_conf.items()))
- task = self.tasks_dedupe.get(cache_key)
- if task is None:
- self.tasks_dedupe[cache_key] = _Task(
- batch_mode, main, (cacheable_conf, kwargs), [name])
- else:
- task.names.append(name)
-
- else:
- logger.error(
- 'no idea to get version info.', name=name)
-
diff --git a/nvchecker/__main__.py b/nvchecker/__main__.py
index 04f456f..d8fc160 100755
--- a/nvchecker/__main__.py
+++ b/nvchecker/__main__.py
@@ -8,6 +8,7 @@ import sys
import argparse
import asyncio
from typing import Coroutine
+from pathlib import Path
import structlog
@@ -22,7 +23,7 @@ def main() -> None:
metavar='FILE', type=str,
help='use specified keyfile')
parser.add_argument('-t', '--tries', default=1, type=int, metavar='N',
- help='try N times when errors occur')
+ help='try N times when network errors occur')
core.add_common_arguments(parser)
args = parser.parse_args()
if core.process_common_arguments(args):
@@ -40,7 +41,7 @@ def main() -> None:
file, use_keymanager=bool(args.keyfile))
if args.keyfile:
- keymanager = KeyManager(args.keyfile)
+ keymanager = KeyManager(Path(args.keyfile))
else:
keymanager = options.keymanager
diff --git a/nvchecker/core.py b/nvchecker/core.py
index b78d60a..4be2fc0 100644
--- a/nvchecker/core.py
+++ b/nvchecker/core.py
@@ -53,7 +53,7 @@ def add_common_arguments(parser: argparse.ArgumentParser) -> None:
help='show version and exit')
parser.add_argument('-c', '--file',
metavar='FILE', type=open,
- help='software version configuration file [default: %s]' % get_default_config)
+ help='software version configuration file [default: %s]' % get_default_config())
def process_common_arguments(args: argparse.Namespace) -> bool:
'''return True if should stop'''
diff --git a/nvchecker_source/vcs.py b/nvchecker_source/vcs.py
index 8ba0bb7..974be18 100644
--- a/nvchecker_source/vcs.py
+++ b/nvchecker_source/vcs.py
@@ -25,7 +25,7 @@ def _parse_oldver(oldver):
return PROT_VER, count, ver
async def get_version(name, conf, *, cache, **kwargs):
- vcs = conf['vcs'] or ''
+ vcs = conf.get('vcs', '')
use_max_tag = conf.get('use_max_tag', False)
oldver = conf.get('oldver')
cmd = _cmd_prefix + [name, vcs]
diff --git a/sample_source.ini b/sample_source.ini
deleted file mode 100644
index 90563ee..0000000
--- a/sample_source.ini
+++ /dev/null
@@ -1,37 +0,0 @@
-[__config__]
-oldver = old_ver.txt
-newver = new_ver.txt
-
-[vim]
-url = http://ftp.vim.org/pub/vim/patches/7.3/
-regex = 7\.3\.\d+
-
-; [badone]
-; url = http://www.baidu.com/
-; regex = baidu (\d+)
-
-[google-chrome]
-cmd = wget -qO- http://dl.google.com/linux/chrome/rpm/stable/x86_64/repodata/other.xml.gz | zgrep "google-chrome-stable" | awk -F\" '{print $10"-"$12}'
-
-[fbcat]
-aur
-
-[winterpy]
-github = lilydjwg/winterpy
-
-[nvchecker]
-github = lilydjwg/nvchecker
-
-[ssed]
-url = http://sed.sourceforge.net/grabbag/ssed/
-regex = The current version is ([\d.]+)\.
-proxy = http://localhost:8087
-
-[PySide]
-pypi = PySide
-
-[test]
-manual = 0.1
-
-[Sparkle Test App]
-sparkle = https://sparkle-project.org/files/sparkletestcast.xml
diff --git a/sample_source.toml b/sample_source.toml
new file mode 100644
index 0000000..fb9a526
--- /dev/null
+++ b/sample_source.toml
@@ -0,0 +1,41 @@
+[__config__]
+oldver = "old_ver.txt"
+newver = "new_ver.txt"
+
+[vim]
+source = "regex"
+regex = "7\\.3\\.\\d+"
+url = "http://ftp.vim.org/pub/vim/patches/7.3/"
+
+[google-chrome]
+source = "cmd"
+cmd = '''wget -qO- http://dl.google.com/linux/chrome/rpm/stable/x86_64/repodata/other.xml.gz | zgrep -A1 "google-chrome-stable" | awk -F\" '/version/ {print $4"-"$6}' '''
+
+[fbcat]
+source = "aur"
+
+[winterpy]
+source = "github"
+github = "lilydjwg/winterpy"
+
+[nvchecker]
+source = "github"
+github = "lilydjwg/nvchecker"
+
+[ssed]
+source = "regex"
+regex = "The current version is ([\\d.]+)\\."
+url = "http://sed.sourceforge.net/grabbag/ssed/"
+proxy = "http://localhost:8087"
+
+[PySide]
+source = "pypi"
+pypi = "PySide"
+
+[test]
+source = "manual"
+manual = "0.1"
+
+["Sparkle Test App"]
+source = "sparkle"
+sparkle = "https://sparkle-project.org/files/sparkletestcast.xml"
diff --git a/scripts/ini2toml b/scripts/ini2toml
new file mode 100755
index 0000000..e91c03e
--- /dev/null
+++ b/scripts/ini2toml
@@ -0,0 +1,85 @@
+#!/usr/bin/python3
+# MIT licensed
+# Copyright (c) 2020 lilydjwg , et al.
+
+import argparse
+
+import configparser
+import toml
+
+_handler_precedence = (
+ 'github', 'aur', 'pypi', 'archpkg', 'debianpkg', 'ubuntupkg',
+ 'gems', 'pacman',
+ 'cmd', 'bitbucket', 'regex', 'manual', 'vcs',
+ 'cratesio', 'npm', 'hackage', 'cpan', 'gitlab', 'packagist',
+ 'repology', 'anitya', 'android_sdk', 'sparkle', 'gitea'
+)
+
+BOOL_KEYS = [
+ 'strip_release', 'use_last_modified',
+ 'use_latest_release', 'use_latest_tag',
+ 'use_max_tag', 'use_pre_release',
+]
+
+INT_KEYS = [
+ 'max_page',
+]
+
+def main():
+ parser = argparse.ArgumentParser(description='convert 1.x ini file to 2.x toml file')
+ parser.add_argument('ini', type=argparse.FileType(),
+ help='the old ini file')
+ parser.add_argument('toml', type=argparse.FileType(mode='w'),
+ help='the new ini file')
+ args = parser.parse_args()
+
+ old = configparser.ConfigParser(
+ dict_type=dict, allow_no_value=True, interpolation=None,
+ )
+ old.read_file(args.ini)
+
+ if '__config__' in old:
+ c = old['__config__']
+ newconf = dict(c)
+ x = newconf.pop('max_concurrent', None)
+ if x is not None:
+ newconf['max_concurrency'] = x
+ confs = {'__config__': newconf}
+ else:
+ confs = {}
+
+ for section in old.sections():
+ if section == '__config__':
+ continue
+
+ conf = old[section]
+ newconf = {}
+
+ for key in _handler_precedence:
+ if key not in conf:
+ continue
+ newconf['source'] = key
+ if conf.get(key):
+ newconf[key] = conf.get(key)
+ break
+
+ dconf = dict(conf)
+
+ for k, v in dconf.items():
+ if '-' in k:
+ k = k.replace('-', '_')
+
+ if k in BOOL_KEYS:
+ newconf[k] = conf.getboolean(k)
+ elif k in INT_KEYS:
+ newconf[k] = conf.getint(k)
+ elif v != '':
+ newconf[k] = v
+
+ confs[section] = newconf
+
+ toml.dump(confs, args.toml)
+ args.toml.flush()
+
+if __name__ == '__main__':
+ main()