mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
support url in results
This commit is contained in:
parent
0fd35f4458
commit
cc4a0cd301
3 changed files with 34 additions and 9 deletions
|
@ -36,7 +36,7 @@ import platformdirs
|
||||||
from .lib import nicelogger
|
from .lib import nicelogger
|
||||||
from . import slogconf
|
from . import slogconf
|
||||||
from .util import (
|
from .util import (
|
||||||
Entry, Entries, KeyManager, RawResult, Result, VersData,
|
Entry, Entries, KeyManager, RawResult, RichResult, Result, VersData,
|
||||||
FunctionWorker, GetVersionError,
|
FunctionWorker, GetVersionError,
|
||||||
FileLoadError, EntryWaiter,
|
FileLoadError, EntryWaiter,
|
||||||
)
|
)
|
||||||
|
@ -76,6 +76,7 @@ def process_common_arguments(args: argparse.Namespace) -> bool:
|
||||||
processors = [
|
processors = [
|
||||||
slogconf.exc_info,
|
slogconf.exc_info,
|
||||||
slogconf.filter_exc,
|
slogconf.filter_exc,
|
||||||
|
slogconf.filter_nones,
|
||||||
]
|
]
|
||||||
logger_factory = None
|
logger_factory = None
|
||||||
|
|
||||||
|
@ -329,6 +330,7 @@ def _process_result(r: RawResult) -> Union[Result, Exception]:
|
||||||
conf = r.conf
|
conf = r.conf
|
||||||
name = r.name
|
name = r.name
|
||||||
|
|
||||||
|
url = None
|
||||||
if isinstance(version, GetVersionError):
|
if isinstance(version, GetVersionError):
|
||||||
kw = version.kwargs
|
kw = version.kwargs
|
||||||
kw['name'] = name
|
kw['name'] = name
|
||||||
|
@ -340,6 +342,9 @@ def _process_result(r: RawResult) -> Union[Result, Exception]:
|
||||||
return version
|
return version
|
||||||
elif isinstance(version, list):
|
elif isinstance(version, list):
|
||||||
version_str = apply_list_options(version, conf)
|
version_str = apply_list_options(version, conf)
|
||||||
|
elif isinstance(version, RichResult):
|
||||||
|
version_str = version.version
|
||||||
|
url = version.url
|
||||||
else:
|
else:
|
||||||
version_str = version
|
version_str = version
|
||||||
|
|
||||||
|
@ -348,7 +353,7 @@ def _process_result(r: RawResult) -> Union[Result, Exception]:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
version_str = substitute_version(version_str, conf)
|
version_str = substitute_version(version_str, conf)
|
||||||
return Result(name, version_str, conf)
|
return Result(name, version_str, conf, url)
|
||||||
except (ValueError, re.error) as e:
|
except (ValueError, re.error) as e:
|
||||||
logger.exception('error occurred in version substitutions', name=name)
|
logger.exception('error occurred in version substitutions', name=name)
|
||||||
return e
|
return e
|
||||||
|
@ -357,13 +362,19 @@ def _process_result(r: RawResult) -> Union[Result, Exception]:
|
||||||
return ValueError('no version returned')
|
return ValueError('no version returned')
|
||||||
|
|
||||||
def check_version_update(
|
def check_version_update(
|
||||||
oldvers: VersData, name: str, version: str,
|
oldvers: VersData, r: Result,
|
||||||
) -> None:
|
) -> None:
|
||||||
oldver = oldvers.get(name, None)
|
oldver = oldvers.get(r.name, None)
|
||||||
if not oldver or oldver != version:
|
if not oldver or oldver != r.version:
|
||||||
logger.info('updated', name=name, version=version, old_version=oldver)
|
logger.info(
|
||||||
|
'updated',
|
||||||
|
name = r.name,
|
||||||
|
version = r.version,
|
||||||
|
old_version = oldver,
|
||||||
|
url = r.url,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
logger.debug('up-to-date', name=name, version=version)
|
logger.debug('up-to-date', name=r.name, version=r.version, url=r.url)
|
||||||
|
|
||||||
async def process_result(
|
async def process_result(
|
||||||
oldvers: VersData,
|
oldvers: VersData,
|
||||||
|
@ -384,7 +395,7 @@ async def process_result(
|
||||||
entry_waiter.set_exception(r.name, r1)
|
entry_waiter.set_exception(r.name, r1)
|
||||||
has_failures = True
|
has_failures = True
|
||||||
continue
|
continue
|
||||||
check_version_update(oldvers, r1.name, r1.version)
|
check_version_update(oldvers, r1)
|
||||||
entry_waiter.set_result(r1.name, r1.version)
|
entry_waiter.set_result(r1.name, r1.version)
|
||||||
ret[r1.name] = r1.version
|
ret[r1.name] = r1.version
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
|
|
|
@ -39,6 +39,11 @@ def exc_info(logger, level, event):
|
||||||
event['exc_info'] = True
|
event['exc_info'] = True
|
||||||
return event
|
return event
|
||||||
|
|
||||||
|
def filter_nones(logger, level, event):
|
||||||
|
if 'url' in event and event['url'] is None:
|
||||||
|
del event['url']
|
||||||
|
return event
|
||||||
|
|
||||||
def filter_exc(logger, level, event):
|
def filter_exc(logger, level, event):
|
||||||
exc_info = event.get('exc_info')
|
exc_info = event.get('exc_info')
|
||||||
if not exc_info:
|
if not exc_info:
|
||||||
|
|
|
@ -13,6 +13,7 @@ from typing import (
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import contextvars
|
import contextvars
|
||||||
import abc
|
import abc
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import tomli as tomllib
|
import tomli as tomllib
|
||||||
|
@ -37,12 +38,19 @@ Entry = Dict[str, Any]
|
||||||
Entry.__doc__ = '''The configuration `dict` for an entry.'''
|
Entry.__doc__ = '''The configuration `dict` for an entry.'''
|
||||||
Entries = Dict[str, Entry]
|
Entries = Dict[str, Entry]
|
||||||
VersData = Dict[str, str]
|
VersData = Dict[str, str]
|
||||||
VersionResult = Union[None, str, List[str], Exception]
|
|
||||||
|
@dataclass(kw_only=True)
|
||||||
|
class RichResult:
|
||||||
|
version: str
|
||||||
|
url: Optional[str] = None
|
||||||
|
|
||||||
|
VersionResult = Union[None, str, List[str], RichResult, Exception]
|
||||||
VersionResult.__doc__ = '''The result of a `get_version` check.
|
VersionResult.__doc__ = '''The result of a `get_version` check.
|
||||||
|
|
||||||
* `None` - No version found.
|
* `None` - No version found.
|
||||||
* `str` - A single version string is found.
|
* `str` - A single version string is found.
|
||||||
* `List[str]` - Multiple version strings are found. :ref:`list options` will be applied.
|
* `List[str]` - Multiple version strings are found. :ref:`list options` will be applied.
|
||||||
|
* `RichResult` - A version string with additional information.
|
||||||
* `Exception` - An error occurred.
|
* `Exception` - An error occurred.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -110,6 +118,7 @@ class Result(NamedTuple):
|
||||||
name: str
|
name: str
|
||||||
version: str
|
version: str
|
||||||
conf: Entry
|
conf: Entry
|
||||||
|
url: Optional[str]
|
||||||
|
|
||||||
class BaseWorker:
|
class BaseWorker:
|
||||||
'''The base class for defining `Worker` classes for source plugins.
|
'''The base class for defining `Worker` classes for source plugins.
|
||||||
|
|
Loading…
Add table
Reference in a new issue