some improvements

This commit is contained in:
JerryXiao 2019-04-02 22:29:38 +08:00
parent 1509183847
commit 3984d68a6a
Signed by: Jerry
GPG key ID: 9D9CE43650FF2BAA
2 changed files with 16 additions and 8 deletions

18
repo.py
View file

@ -53,10 +53,13 @@ def checkenv():
checkenv() checkenv()
def repo_add(fpath): def repo_add(fpaths):
assert issubclass(type(fpath), os.PathLike) and fpath.name.endswith(f'.pkg.tar.{PKG_COMPRESSION}') assert type(fpaths) is list
for fpath in fpaths:
assert issubclass(type(fpath), os.PathLike) and \
fpath.name.endswith(f'.pkg.tar.{PKG_COMPRESSION}')
dbpath = fpath.parent / f'{REPO_NAME}.db.tar.gz' dbpath = fpath.parent / f'{REPO_NAME}.db.tar.gz'
return bash(f'{REPO_CMD} {dbpath} {fpath}') return bash(f'{REPO_CMD} {dbpath} {" ".join([str(fpath for fpath in fpaths)])}')
def throw_away(fpath): def throw_away(fpath):
assert issubclass(type(fpath), os.PathLike) assert issubclass(type(fpath), os.PathLike)
@ -91,6 +94,7 @@ def _check_repo():
for arch in ARCHS: for arch in ARCHS:
basedir = Path('www') / arch basedir = Path('www') / arch
repo_files_count = list() repo_files_count = list()
pkg_to_add = list()
if not basedir.exists(): if not basedir.exists():
logger.error(f'{arch} dir does not exist!') logger.error(f'{arch} dir does not exist!')
continue continue
@ -119,12 +123,16 @@ def _check_repo():
assert not newSigpath.exists() assert not newSigpath.exists()
sigfile.rename(newSigpath) sigfile.rename(newSigpath)
logger.info(f'Moving {pkgfile} to {newpath}, {sigfile} to {newSigpath}') logger.info(f'Moving {pkgfile} to {newpath}, {sigfile} to {newSigpath}')
logger.debug("repo-add: %s", repo_add(newpath)) pkg_to_add.append(newpath)
else: else:
logger.debug("repo-add: %s", repo_add(pkgfile)) pkg_to_add.append(pkgfile)
else: else:
logger.warning(f"{pkgfile} is garbage!") logger.warning(f"{pkgfile} is garbage!")
throw_away(pkgfile) throw_away(pkgfile)
if pkg_to_add:
logger.info("repo-add: %s", repo_add(pkg_to_add))
else:
logger.warning('repo-add: Nothing to do in %s', arch)
for rfile in repo_files_essential: for rfile in repo_files_essential:
if rfile not in repo_files_count: if rfile not in repo_files_count:
logger.error(f'{rfile} does not exist in {arch}!') logger.error(f'{rfile} does not exist in {arch}!')

View file

@ -101,8 +101,8 @@ class Pkg:
def get_pkg_details_from_name(name): def get_pkg_details_from_name(name):
if name.endswith(f'pkg.tar.{PKG_COMPRESSION}'): if name.endswith(f'pkg.tar.{PKG_COMPRESSION}'):
arch = re.match(r'(.+)-([^-]+)-([^-]+)-([^-]+)\.pkg\.tar\.\w+', name) m = re.match(r'(.+)-([^-]+)-([^-]+)-([^-]+)\.pkg\.tar\.\w+', name)
assert arch and arch.groups() and len(arch.groups()) == 4 assert m and m.groups() and len(m.groups()) == 4
(pkgname, pkgver, pkgrel, arch) = arch.groups() (pkgname, pkgver, pkgrel, arch) = m.groups()
return Pkg(pkgname, pkgver, pkgrel, arch) return Pkg(pkgname, pkgver, pkgrel, arch)