Simplify add_pkgfile and general code cleanup
This commit is contained in:
parent
62a80b5dbf
commit
c0e2aab5a7
47
bin/addpkg
47
bin/addpkg
@ -17,9 +17,12 @@ import packaging_scripts.pacmanconf as pacmanconf
|
|||||||
import packaging_scripts.pkgfiles as pkgfiles
|
import packaging_scripts.pkgfiles as pkgfiles
|
||||||
|
|
||||||
# ========== Constants ==========
|
# ========== Constants ==========
|
||||||
REPO_ADD_CMD = '/usr/bin/repo-remove'
|
REPO_ADD_CMD = '/usr/bin/repo-add'
|
||||||
DB_EXT = 'db.tar.xz'
|
DB_EXT = 'db.tar.xz'
|
||||||
|
|
||||||
|
# ========== Exit codes ==========
|
||||||
|
E_REPO_ADDERR = 2
|
||||||
|
|
||||||
# ========== Logging setup ==========
|
# ========== Logging setup ==========
|
||||||
console_formatter = logging.Formatter('==> %(levelname)s %(message)s')
|
console_formatter = logging.Formatter('==> %(levelname)s %(message)s')
|
||||||
syslog = logging.getLogger(__name__)
|
syslog = logging.getLogger(__name__)
|
||||||
@ -38,24 +41,16 @@ syslog.addHandler(stderr_handler)
|
|||||||
|
|
||||||
|
|
||||||
# ========== Functions ==========
|
# ========== Functions ==========
|
||||||
def add_pkgfiles(cachedir, pkgs=None):
|
def add_pkgfile(pkg, cachedir):
|
||||||
"""Add package files to the repository directory.
|
"""Add package file to the repository directory.
|
||||||
|
|
||||||
:param pkgs: names of packages to add
|
:param pkg: path of package to add
|
||||||
:type pkgs: any container object
|
:type pkg: str, bytes, or path-like object
|
||||||
|
:param cachedir: cache directory to move package to
|
||||||
|
:type cachedir: str, bytes, or path-like object
|
||||||
"""
|
"""
|
||||||
syslog.info(f"Adding package files to {cachedir}")
|
syslog.info(f"Adding {pkg} to {cachedir}")
|
||||||
syslog.debug(f"Packages: {pkgs}")
|
shutil.move(pkg, cachedir)
|
||||||
|
|
||||||
if pkgs is not None:
|
|
||||||
pkglist = pkgs
|
|
||||||
else:
|
|
||||||
pkglist = pkgfiles.get_pkgfiles() +\
|
|
||||||
pkgfiles.get_pkgfiles(signatures_only=True)
|
|
||||||
|
|
||||||
for pkg in pkglist:
|
|
||||||
shutil.move(pkg, cachedir)
|
|
||||||
syslog.info(f"Added {pkg}")
|
|
||||||
|
|
||||||
|
|
||||||
def repo_add(db, pkgs, opts=None):
|
def repo_add(db, pkgs, opts=None):
|
||||||
@ -65,9 +60,9 @@ def repo_add(db, pkgs, opts=None):
|
|||||||
:type repo: str
|
:type repo: str
|
||||||
:param pkgs: the names of the packages to remove
|
:param pkgs: the names of the packages to remove
|
||||||
:type pkgs: any iterable
|
:type pkgs: any iterable
|
||||||
:param opts: extra options to pass to repo-remove
|
:param opts: extra options to pass to repo-add
|
||||||
:type opts: list
|
:type opts: list
|
||||||
:raises: subprocess.CalledProcessError if repo-remove failed
|
:raises: subprocess.CalledProcessError if repo-add failed
|
||||||
"""
|
"""
|
||||||
syslog.info('Adding packages to database')
|
syslog.info('Adding packages to database')
|
||||||
syslog.debug(f"Options: {opts}")
|
syslog.debug(f"Options: {opts}")
|
||||||
@ -121,15 +116,21 @@ if __name__ == '__main__':
|
|||||||
cachedir = f"/var/cache/pacman/{repo}"
|
cachedir = f"/var/cache/pacman/{repo}"
|
||||||
# this assumes that the db file for the repo
|
# this assumes that the db file for the repo
|
||||||
# has the same name as that repo
|
# has the same name as that repo
|
||||||
db = f"{cachedir}/{repo}/.{DB_EXT}"
|
db = f"{cachedir}/{repo}.{DB_EXT}"
|
||||||
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
stdout_handler.setLevel(logging.DEBUG)
|
stdout_handler.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
add_pkgfiles(cachedir, pkgs)
|
if pkgs:
|
||||||
|
pkglist = pkgs
|
||||||
|
else:
|
||||||
|
pkglist = pkgfiles.get_pkgfiles() +\
|
||||||
|
pkgfiles.get_pkgfiles(signatures_only=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
repo_add(repo, pkgs, opts)
|
repo_add(db, pkglist, opts)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
syslog.error(e)
|
syslog.error(e)
|
||||||
exit(2)
|
exit(E_REPO_ADDERR)
|
||||||
|
|
||||||
|
map(lambda pkg: add_pkgfile(pkg, cachedir), pkglist)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user