General code cleanup
This commit is contained in:
parent
a5eaa9380c
commit
9e8b3da405
50
bin/addpkg
50
bin/addpkg
@ -25,19 +25,19 @@ 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__)
|
logging.basicConfig(format='==> %(levelname)s %(message)s',
|
||||||
syslog.setLevel(logging.DEBUG)
|
level=logging.DEBUG)
|
||||||
|
|
||||||
stdout_handler = logging.StreamHandler(sys.stdout)
|
#stdout_handler = logging.StreamHandler(sys.stdout)
|
||||||
stdout_handler.setLevel(logging.INFO)
|
#stdout_handler.setLevel(logging.INFO)
|
||||||
stdout_handler.setFormatter(console_formatter)
|
#stdout_handler.setFormatter(console_formatter)
|
||||||
|
#
|
||||||
stderr_handler = logging.StreamHandler()
|
#stderr_handler = logging.StreamHandler()
|
||||||
stderr_handler.setLevel(logging.ERROR)
|
#stderr_handler.setLevel(logging.ERROR)
|
||||||
stderr_handler.setFormatter(console_formatter)
|
#stderr_handler.setFormatter(console_formatter)
|
||||||
|
#
|
||||||
syslog.addHandler(stdout_handler)
|
#logging.addHandler(stdout_handler)
|
||||||
syslog.addHandler(stderr_handler)
|
#logging.addHandler(stderr_handler)
|
||||||
|
|
||||||
|
|
||||||
# ========== Functions ==========
|
# ========== Functions ==========
|
||||||
@ -49,8 +49,8 @@ def add_pkgfile(pkg, cachedir):
|
|||||||
:param cachedir: cache directory to move package to
|
:param cachedir: cache directory to move package to
|
||||||
:type cachedir: str, bytes, or path-like object
|
:type cachedir: str, bytes, or path-like object
|
||||||
"""
|
"""
|
||||||
syslog.info(f"Adding {pkg} to {cachedir}")
|
logging.info(f"Adding {pkg} to {cachedir}")
|
||||||
shutil.move(pkg, cachedir)
|
shutil.move(str(pkg), cachedir)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -82,20 +82,24 @@ if __name__ == '__main__':
|
|||||||
# 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)
|
||||||
|
|
||||||
if pkgs:
|
if pkgs:
|
||||||
pkglist = pkgs
|
pkg_tarballs = pkgs
|
||||||
siglist = []
|
sigfiles = []
|
||||||
else:
|
else:
|
||||||
pkglist = pkgfiles.get_pkgfiles()
|
pkg_tarballs = list(pkgfiles.get_pkgfiles())
|
||||||
siglist = pkgfiles.get_pkgfiles(signatures_only=True)
|
sigfiles = list(pkgfiles.get_pkgfiles(signatures_only=True))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
repos.repo_add('add', db, *pkglist, opts=opts)
|
repos.repo_add('add', db, *pkg_tarballs, opts=opts)
|
||||||
except repos.RepoAddError as e:
|
except repos.RepoAddError as e:
|
||||||
syslog.error(e)
|
logging.error(e)
|
||||||
exit(E_REPO_ADDERR)
|
exit(E_REPO_ADDERR)
|
||||||
|
|
||||||
map(lambda pkg: add_pkgfile(pkg, cachedir), pkglist + siglist)
|
for pkg_tarball in pkg_tarballs:
|
||||||
|
add_pkgfile(pkg_tarball, cachedir)
|
||||||
|
|
||||||
|
for sigfile in sigfiles:
|
||||||
|
add_pkgfile(sigfile, cachedir)
|
||||||
|
61
bin/delpkg
61
bin/delpkg
@ -9,12 +9,11 @@ Functions:
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import shutil
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import packaging_scripts.pacmanconf as pacmanconf
|
import packaging_scripts.pacmanconf as pacmanconf
|
||||||
import packaging_scripts.pkgfiles as pkgfiles
|
import packaging_scripts.pkgfiles as pkgfiles
|
||||||
import packaging_scripts.pkgfiles as repos
|
import packaging_scripts.repos as repos
|
||||||
|
|
||||||
# ========== Constants ==========
|
# ========== Constants ==========
|
||||||
REPO_REMOVE_CMD = '/usr/bin/repo-remove'
|
REPO_REMOVE_CMD = '/usr/bin/repo-remove'
|
||||||
@ -25,19 +24,20 @@ 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__)
|
#logging = logging.getLogger(__name__)
|
||||||
syslog.setLevel(logging.DEBUG)
|
logging.basicConfig(format='==> %(levelname)s %(message)s',
|
||||||
|
level=logging.DEBUG)
|
||||||
|
|
||||||
stdout_handler = logging.StreamHandler(sys.stdout)
|
#stdout_handler = logging.StreamHandler(sys.stdout)
|
||||||
stdout_handler.setLevel(logging.INFO)
|
#stdout_handler.setLevel(logging.INFO)
|
||||||
stdout_handler.setFormatter(console_formatter)
|
#stdout_handler.setFormatter(console_formatter)
|
||||||
|
#
|
||||||
stderr_handler = logging.StreamHandler()
|
#stderr_handler = logging.StreamHandler()
|
||||||
stderr_handler.setLevel(logging.ERROR)
|
#stderr_handler.setLevel(logging.ERROR)
|
||||||
stderr_handler.setFormatter(console_formatter)
|
#stderr_handler.setFormatter(console_formatter)
|
||||||
|
#
|
||||||
syslog.addHandler(stdout_handler)
|
#logging.addHandler(stdout_handler)
|
||||||
syslog.addHandler(stderr_handler)
|
#logging.addHandler(stderr_handler)
|
||||||
|
|
||||||
|
|
||||||
# ========== Functions ==========
|
# ========== Functions ==========
|
||||||
@ -45,10 +45,10 @@ def del_pkgfile(pkg):
|
|||||||
"""Remove package file.
|
"""Remove package file.
|
||||||
|
|
||||||
:param pkg: path of package to remove
|
:param pkg: path of package to remove
|
||||||
:type pkg: str, bytes, or path-like object
|
:type pkg: pathlib.Path object
|
||||||
"""
|
"""
|
||||||
shutil.remove(pkg)
|
pkg.unlink()
|
||||||
syslog.info(f"Removed {pkg}")
|
logging.info(f"Removed {pkg}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -66,7 +66,6 @@ if __name__ == '__main__':
|
|||||||
help='the repository to operate on',
|
help='the repository to operate on',
|
||||||
metavar='repo')
|
metavar='repo')
|
||||||
parser.add_argument('packages',
|
parser.add_argument('packages',
|
||||||
default=None,
|
|
||||||
nargs='+',
|
nargs='+',
|
||||||
help='packages to remove')
|
help='packages to remove')
|
||||||
|
|
||||||
@ -80,16 +79,26 @@ if __name__ == '__main__':
|
|||||||
# 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)
|
||||||
|
|
||||||
pkglist = pkgfiles.get_pkgfiles(directory=cachedir) +\
|
logging.debug(f"Packages: {pkgs}")
|
||||||
pkgfiles.get_pkgfiles(directory=cachedir, signatures_only=True)
|
|
||||||
|
|
||||||
map(lambda pkg: del_pkgfile(pkg), pkglist)
|
for pkg in pkgs:
|
||||||
|
pkg_tarballs = pkgfiles.get_pkgfiles(query=pkg,
|
||||||
|
directory=cachedir)
|
||||||
|
sigfiles = pkgfiles.get_pkgfiles(query=pkg,
|
||||||
|
directory=cachedir,
|
||||||
|
signatures_only=True)
|
||||||
|
|
||||||
|
for pkg_tarball in pkg_tarballs:
|
||||||
|
del_pkgfile(pkg_tarball)
|
||||||
|
|
||||||
|
for sigfile in sigfiles:
|
||||||
|
del_pkgfile(sigfile)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
repos.repo_add('remove', db, *pkglist, opts=opts)
|
repos.repo_add('remove', db, pkg, opts=opts)
|
||||||
except repos.RepoAddError as e:
|
except repos.RepoAddError as e:
|
||||||
syslog.error(e)
|
logging.error(e)
|
||||||
exit(E_REPO_REMOVEERR)
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user