38 lines
1.1 KiB
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=None, directory=None, signatures_only=False):
2019-01-27 20:26:50 -08:00
"""Return a list of package files in the current working directory.
2019-01-28 11:01:08 -08:00
:param query: names of package files to search for
:type query: str
2019-01-27 20:26:50 -08:00
:param directory: a directory to search in
:type directory: str, bytes, or path-like object
:param signatures_only: include only signature files
:type signatures_only: bool
2019-01-27 20:26:50 -08:00
:returns: paths of package files
:rtype: generator
2019-01-27 20:26:50 -08:00
"""
if directory is not None:
2019-01-27 20:26:50 -08:00
path = pathlib.Path(directory)
else:
path = pathlib.Path.cwd()
if signatures_only:
if query is not None:
return path.glob(f"{query}*.{SIGEXT}")
else:
return path.glob(f"*.{SIGEXT}")
else:
if query is not None:
return path.glob(f"{query}*.{PKGEXT}")
else:
return path.glob(f"*.{PKGEXT}")