Make use of glob and os.path modules for filename handling
This commit is contained in:
parent
c6bfaefff1
commit
6c49217b0b
@ -1,6 +1,8 @@
|
|||||||
"""Helper functions for dealing with package files."""
|
"""Helper functions for dealing with package files."""
|
||||||
|
|
||||||
import pathlib
|
import glob
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
|
||||||
# ========== Constants ==========
|
# ========== Constants ==========
|
||||||
PKGEXT = 'pkg.tar.xz'
|
PKGEXT = 'pkg.tar.xz'
|
||||||
@ -18,20 +20,20 @@ def get_pkgfiles(query=None, directory=None, signatures_only=False):
|
|||||||
:param signatures_only: include only signature files
|
:param signatures_only: include only signature files
|
||||||
:type signatures_only: bool
|
:type signatures_only: bool
|
||||||
:returns: paths of package files
|
:returns: paths of package files
|
||||||
:rtype: generator
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
if directory is not None:
|
if directory is not None:
|
||||||
path = pathlib.Path(directory)
|
path = directory
|
||||||
else:
|
else:
|
||||||
path = pathlib.Path.cwd()
|
path = os.getcwd()
|
||||||
|
|
||||||
if signatures_only:
|
if signatures_only:
|
||||||
if query is not None:
|
if query is not None:
|
||||||
return path.glob(f"{query}*.{SIGEXT}")
|
return glob.glob(f"{path}/{query}*.{SIGEXT}")
|
||||||
else:
|
else:
|
||||||
return path.glob(f"*.{SIGEXT}")
|
return glob.glob(f"{path}/*.{SIGEXT}")
|
||||||
else:
|
else:
|
||||||
if query is not None:
|
if query is not None:
|
||||||
return path.glob(f"{query}*.{PKGEXT}")
|
return glob.glob(f"{path}/{query}*.{PKGEXT}")
|
||||||
else:
|
else:
|
||||||
return path.glob(f"*.{PKGEXT}")
|
return glob.glob(f"{path}/*.{PKGEXT}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user