mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Using upsert_file to handle Zim file download.
This commit is contained in:
parent
15f6e7ed5c
commit
c82baa1ad8
2 changed files with 11 additions and 10 deletions
|
|
@ -7,7 +7,7 @@ from wrolpi.downloader import Downloader, Download, DownloadResult
|
|||
|
||||
__all__ = ['KiwixCatalogDownloader', 'KiwixZimDownloader', 'kiwix_zim_downloader', 'kiwix_catalog_downloader']
|
||||
|
||||
from wrolpi.files.lib import refresh_files
|
||||
from wrolpi.files.lib import refresh_files, upsert_file
|
||||
from wrolpi.vars import PYTEST
|
||||
|
||||
logger = logger.getChild(__name__)
|
||||
|
|
@ -79,17 +79,16 @@ class KiwixZimDownloader(Downloader):
|
|||
# Notify the maintainer if outdated Zim files are lying around.
|
||||
lib.flag_outdated_zim_files()
|
||||
|
||||
return_code = await lib.check_zim(output_path)
|
||||
if return_code == 127:
|
||||
try:
|
||||
return_code = await lib.check_zim(output_path)
|
||||
if return_code > 0:
|
||||
# zimcheck ran, but the file is invalid.
|
||||
return DownloadResult(success=False, error=f'Zim file is invalid')
|
||||
except FileNotFoundError:
|
||||
logger.warning(f'Not validating {output_path} because zimcheck is not installed')
|
||||
elif return_code > 0:
|
||||
return DownloadResult(success=False, error=f'Zim file is invalid')
|
||||
|
||||
# Add the new Zim to the FileGroups, model it.
|
||||
if PYTEST:
|
||||
await refresh_files([output_path, ])
|
||||
else:
|
||||
background_task(refresh_files([output_path, ]))
|
||||
await upsert_file(output_path)
|
||||
|
||||
# Restart Kiwix serve, so it finds the new zim file.
|
||||
return_code = await lib.restart_kiwix()
|
||||
|
|
|
|||
|
|
@ -472,7 +472,9 @@ async def check_zim(path: pathlib.Path) -> int:
|
|||
|
||||
@warning: Only performs the checksum check!
|
||||
"""
|
||||
cmd = ['zimcheck', '-C', path.absolute()]
|
||||
cmd = ('zimcheck', '-C', path.absolute())
|
||||
cmd_str = " ".join(str(i) for i in cmd)
|
||||
logger.debug(f'check_zim: {cmd_str}')
|
||||
result = await run_command(cmd)
|
||||
logger.debug(f'zimcheck returned {result.return_code}')
|
||||
if result.return_code != 0 and result.stderr:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue