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 glob
import os
import os.path
2019-01-27 20:26:50 -08:00
2019-01-28 10:53:56 -08:00
# ========== Constants ==========
PKGEXT = "pkg.tar.xz"
2019-01-27 20:26:50 -08:00
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
2019-02-20 15:49:18 -08:00
:type directory: str
: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: list
2019-01-27 20:26:50 -08:00
"""
if directory is not None:
path = directory
2019-01-27 20:26:50 -08:00
else:
path = os.getcwd()
2019-01-27 20:26:50 -08:00
2019-02-20 15:49:18 -08:00
if signatures_only and query is not None:
return glob.glob(f"{path}/*{query}*.{SIGEXT}")
elif signatures_only and query is None:
return glob.glob(f"{path}/*.{SIGEXT}")
elif not signatures_only and query is not None:
return glob.glob(f"{path}/*{query}*.{PKGEXT}")
elif not signatures_only and query is None:
return glob.glob(f"{path}/*.{PKGEXT}")