mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
add --failures
cmdline flag to indicate there are errors during checking
closes #205.
This commit is contained in:
parent
83286263d2
commit
112c916a6d
2 changed files with 11 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
# MIT licensed
|
||||
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
# Copyright (c) 2013-2022 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
@ -25,6 +25,8 @@ def main() -> None:
|
|||
help='use specified keyfile (override the one in configuration file)')
|
||||
parser.add_argument('-t', '--tries', default=1, type=int, metavar='N',
|
||||
help='try N times when network errors occur')
|
||||
parser.add_argument('--failures', action='store_true',
|
||||
help='exit with code 3 if failures / errors happen during checking')
|
||||
parser.add_argument('-e', '--entry', type=str,
|
||||
help='only execute on specified entry (useful for debugging)')
|
||||
core.add_common_arguments(parser)
|
||||
|
@ -76,11 +78,14 @@ def main() -> None:
|
|||
result_coro = core.process_result(oldvers, result_q, entry_waiter)
|
||||
runner_coro = core.run_tasks(futures)
|
||||
|
||||
newvers = asyncio.run(run(result_coro, runner_coro))
|
||||
newvers, has_failures = asyncio.run(run(result_coro, runner_coro))
|
||||
|
||||
if options.ver_files is not None:
|
||||
core.write_verfile(options.ver_files[1], newvers)
|
||||
|
||||
if args.failures and has_failures:
|
||||
sys.exit(3)
|
||||
|
||||
async def run(
|
||||
result_coro: Coroutine[None, None, VersData],
|
||||
runner_coro: Coroutine[None, None, None],
|
||||
|
|
|
@ -360,20 +360,22 @@ async def process_result(
|
|||
oldvers: VersData,
|
||||
result_q: Queue[RawResult],
|
||||
entry_waiter: EntryWaiter,
|
||||
) -> VersData:
|
||||
) -> Tuple[VersData, bool]:
|
||||
ret = {}
|
||||
has_failures = False
|
||||
try:
|
||||
while True:
|
||||
r = await result_q.get()
|
||||
r1 = _process_result(r)
|
||||
if isinstance(r1, Exception):
|
||||
entry_waiter.set_exception(r.name, r1)
|
||||
has_failures = True
|
||||
continue
|
||||
check_version_update(oldvers, r1.name, r1.version)
|
||||
entry_waiter.set_result(r1.name, r1.version)
|
||||
ret[r1.name] = r1.version
|
||||
except asyncio.CancelledError:
|
||||
return ret
|
||||
return ret, has_failures
|
||||
|
||||
async def run_tasks(
|
||||
futures: Sequence[Awaitable[None]]
|
||||
|
|
Loading…
Add table
Reference in a new issue