29 lines
797 B
Python
Raw Normal View History

2019-01-27 20:26:50 -08:00
"""Helper functions for dealing with package files."""
import pathlib
2019-01-28 10:53:56 -08:00
# ========== Constants ==========
2019-01-27 20:26:50 -08:00
PKGEXT = 'pkg.tar.xz'
SIGEXT = f"{PKGEXT}.sig"
2019-01-28 10:53:56 -08:00
# ========== Functions ==========
def get_pkgfiles(query, directory=None, signatures=False):
2019-01-27 20:26:50 -08:00
"""Return a list of package files in the current working directory.
:param directory: a directory to search in
:type directory: str, bytes, or path-like object
:param signatures: include only signature files
:type signatures: bool
2019-01-27 20:26:50 -08:00
:returns: paths of package files
:rtype: list
"""
if directory is not None:
2019-01-27 20:26:50 -08:00
path = pathlib.Path(directory)
else:
path = pathlib.Path.cwd()
if signatures:
2019-01-28 10:53:56 -08:00
return list(path.glob(f"{query}*.{SIGEXT}"))
2019-01-27 20:26:50 -08:00
2019-01-28 10:53:56 -08:00
return list(path.glob(f"{query}*.{PKGEXT}"))