Code cleanup for delpkg and make use of map() for del_pkgfile()
This commit is contained in:
parent
e0f564dea6
commit
574415b3d8
40
bin/delpkg
40
bin/delpkg
@ -3,12 +3,13 @@
|
|||||||
|
|
||||||
Functions:
|
Functions:
|
||||||
==========
|
==========
|
||||||
del_pkgfiles(cachedir, pkgs)
|
* del_pkgfiles(cachedir, pkgs)
|
||||||
repo_remove(db, pkgs, opts=None)
|
* repo_remove(db, pkgs, opts=None)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -19,6 +20,9 @@ import packaging_scripts.pkgfiles as pkgfiles
|
|||||||
REPO_REMOVE_CMD = '/usr/bin/repo-remove'
|
REPO_REMOVE_CMD = '/usr/bin/repo-remove'
|
||||||
DB_EXT = 'db.tar.xz'
|
DB_EXT = 'db.tar.xz'
|
||||||
|
|
||||||
|
# ========== Exit codes ==========
|
||||||
|
E_REPO_REMOVEERR = 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__)
|
||||||
@ -37,23 +41,14 @@ syslog.addHandler(stderr_handler)
|
|||||||
|
|
||||||
|
|
||||||
# ========== Functions ==========
|
# ========== Functions ==========
|
||||||
def del_pkgfiles(cachedir, pkgs):
|
def del_pkgfile(pkg):
|
||||||
"""Remove package files from the repository directory.
|
"""Remove package file.
|
||||||
|
|
||||||
:param cachedir: directory to operate on
|
:param pkg: path of package to remove
|
||||||
:type cachedir: str, bytes, or path-like object
|
:type pkg: str, bytes, or path-like object
|
||||||
:param pkgs: names of packages to remove
|
|
||||||
:type pkgs: any container object
|
|
||||||
"""
|
"""
|
||||||
syslog.info(f"Removing package files from {cachedir}")
|
shutil.remove(pkg)
|
||||||
syslog.debug(f"Packages: {pkgs}")
|
syslog.info(f"Removed {pkg}")
|
||||||
|
|
||||||
for pkg in pkgs:
|
|
||||||
for pkgfile in pkgfiles.get_pkgfiles(pkg, directory=cachedir) +\
|
|
||||||
pkgfiles.get_pkgfiles(pkg, directory=cachedir,
|
|
||||||
signatures_only=True):
|
|
||||||
pkgfile.unlink()
|
|
||||||
syslog.info(f"Removed {pkgfile}")
|
|
||||||
|
|
||||||
|
|
||||||
def repo_remove(db, pkgs, opts=None):
|
def repo_remove(db, pkgs, opts=None):
|
||||||
@ -119,15 +114,18 @@ 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)
|
||||||
|
|
||||||
del_pkgfiles(cachedir, pkgs)
|
pkglist = pkgfiles.get_pkgfiles(directory=cachedir) +\
|
||||||
|
pkgfiles.get_pkgfiles(directory=cachedir, signatures_only=True)
|
||||||
|
|
||||||
|
map(lambda pkg: del_pkgfile(pkg), pkglist)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
repo_remove(repo, pkgs, opts)
|
repo_remove(repo, pkglist, opts)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
syslog.error(e)
|
syslog.error(e)
|
||||||
exit(2)
|
exit(E_REPO_REMOVEERR)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user