Move add and delete functionality to pkgfiles module, add tests
This commit is contained in:
@ -1,18 +1,24 @@
|
||||
"""Helper functions for dealing with package files."""
|
||||
|
||||
import logging
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# ========== Constants ==========
|
||||
# Match any pkgfile of any name with the .pkg.tar.* extension
|
||||
PKGREGEX = "^[\w]+[.]pkg[.]tar([.][\w]+)?$"
|
||||
PKGREGEX = r"^\w+[.]pkg[.]tar([.]\w+)?$"
|
||||
# Match any sigfile of any name with the .pkg.tar.*.sig extension
|
||||
SIGREGEX = "^[\w]+[.]pkg[.]tar[.][\w]*[.]sig$"
|
||||
SIGREGEX = r"^\w+[.]pkg[.]tar([.]\w+)?[.]sig$"
|
||||
|
||||
|
||||
# ========== Logging Setup ===========
|
||||
syslog = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# ========== Functions ==========
|
||||
def get_pkgfiles(query=None, *, directory=None, signatures_only=False):
|
||||
def get(query=None, *, directory=None, signatures_only=False):
|
||||
"""Return a list of package files in the current working directory.
|
||||
|
||||
:param query: names of package files to search for
|
||||
@ -33,6 +39,28 @@ def get_pkgfiles(query=None, *, directory=None, signatures_only=False):
|
||||
yield from _filter_by_regex(filequery, PKGREGEX, path)
|
||||
|
||||
|
||||
def add(pkgfile, cachedir):
|
||||
"""Add package file to the repository directory.
|
||||
|
||||
:param pkg: path of package to add
|
||||
:type pkg: path-like object
|
||||
:param cachedir: cache directory to move package to
|
||||
:type cachedir: path-like object
|
||||
"""
|
||||
syslog.info(f"Adding {pkgfile} to {cachedir}")
|
||||
shutil.move(pkgfile, cachedir / pkgfile.name)
|
||||
|
||||
|
||||
def delete(pkg):
|
||||
"""Remove package file.
|
||||
|
||||
:param pkg: path of package to remove
|
||||
:type pkg: path-like object
|
||||
"""
|
||||
pkg.unlink()
|
||||
syslog.info(f"Removed {pkg}")
|
||||
|
||||
|
||||
def _filter_by_regex(query, regex_expression, path):
|
||||
"""Filter package files only.
|
||||
|
||||
|
Reference in New Issue
Block a user