2019-01-27 20:26:50 -08:00
|
|
|
"""Helper functions for dealing with package files."""
|
|
|
|
|
2019-02-20 15:44:37 -08:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import os.path
|
2019-01-27 20:26:50 -08:00
|
|
|
|
2019-01-28 10:53:56 -08:00
|
|
|
# ========== Constants ==========
|
2019-03-06 23:41:05 -08:00
|
|
|
PKGEXT = "pkg.tar.xz"
|
2019-01-27 20:26:50 -08:00
|
|
|
SIGEXT = f"{PKGEXT}.sig"
|
|
|
|
|
2019-01-29 14:33:51 -08:00
|
|
|
|
2019-01-28 10:53:56 -08:00
|
|
|
# ========== Functions ==========
|
2019-01-29 14:33:51 -08:00
|
|
|
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
|
2019-01-28 10:59:18 -08:00
|
|
|
:param signatures_only: include only signature files
|
|
|
|
:type signatures_only: bool
|
2019-01-27 20:26:50 -08:00
|
|
|
:returns: paths of package files
|
2019-02-20 15:44:37 -08:00
|
|
|
:rtype: list
|
2019-01-27 20:26:50 -08:00
|
|
|
"""
|
2019-01-28 08:08:23 -08:00
|
|
|
if directory is not None:
|
2019-02-20 15:44:37 -08:00
|
|
|
path = directory
|
2019-01-27 20:26:50 -08:00
|
|
|
else:
|
2019-02-20 15:44:37 -08:00
|
|
|
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}")
|