mirror of
https://github.com/lilydjwg/nvchecker
synced 2024-12-25 16:12:39 +00:00
add the ini2toml script
This commit is contained in:
parent
57626faecf
commit
e59766f839
1
NEW
1
NEW
@ -1,4 +1,3 @@
|
||||
TODO:
|
||||
* update README
|
||||
* create source plugin documentation
|
||||
* a script to convert old ini into new toml files
|
||||
|
19
README.rst
19
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 <https://aur.archlinux.org/>`_ 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 <https://w
|
||||
archpkg
|
||||
Name of the Arch Linux package.
|
||||
|
||||
strip-release
|
||||
strip_release
|
||||
Strip the release part, only return part before ``-``.
|
||||
|
||||
provided
|
||||
@ -473,7 +474,7 @@ debianpkg
|
||||
suite
|
||||
Name of the Debian release (jessie, wheezy, etc, defaults to sid)
|
||||
|
||||
strip-release
|
||||
strip_release
|
||||
Strip the release part.
|
||||
|
||||
Check Ubuntu Linux official packages
|
||||
@ -486,7 +487,7 @@ ubuntupkg
|
||||
suite
|
||||
Name of the Ubuntu release (xenial, zesty, etc, defaults to None, which means no limit on suite)
|
||||
|
||||
strip-release
|
||||
strip_release
|
||||
Strip the release part.
|
||||
|
||||
Check Repology
|
||||
|
@ -1,57 +0,0 @@
|
||||
# MIT licensed
|
||||
# Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, 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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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'''
|
||||
|
@ -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]
|
||||
|
@ -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
|
41
sample_source.toml
Normal file
41
sample_source.toml
Normal file
@ -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"
|
85
scripts/ini2toml
Executable file
85
scripts/ini2toml
Executable file
@ -0,0 +1,85 @@
|
||||
#!/usr/bin/python3
|
||||
# MIT licensed
|
||||
# Copyright (c) 2020 lilydjwg <lilydjwg@gmail.com>, 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()
|
Loading…
Reference in New Issue
Block a user