summaryrefslogtreecommitdiff
path: root/cmd2/utils.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-07 00:00:21 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-07 00:00:21 -0400
commit069b181a887445fde7b66e27e537a9653d70e3dc (patch)
tree04d82f38d3f3276fecce9df833698c940cd9bdfd /cmd2/utils.py
parent16f6bee13c9b568c898a9997e2813b343ca98596 (diff)
downloadcmd2-git-069b181a887445fde7b66e27e537a9653d70e3dc.tar.gz
Moved a new helper function from cmd2.py to utils.py where it probably belonged
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r--cmd2/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py
index 0db61ca5..3500ba7a 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -332,6 +332,22 @@ def files_from_glob_pattern(pattern: str, access=os.F_OK) -> List[str]:
return [f for f in glob.glob(pattern) if os.path.isfile(f) and os.access(f, access)]
+def files_from_glob_patterns(patterns: List[str], access=os.F_OK) -> List[str]:
+ """Return a list of file paths based on a list of glob patterns.
+
+ Only files are returned, not directories, and optionally only files for which the user has a specified access to.
+
+ :param patterns: list of file names and/or glob patterns
+ :param access: file access type to verify (os.* where * is F_OK, R_OK, W_OK, or X_OK)
+ :return: list of files matching the names and/or glob patterns
+ """
+ files = []
+ for pattern in patterns:
+ matches = files_from_glob_pattern(pattern, access=access)
+ files.extend(matches)
+ return files
+
+
class StdSim(object):
"""
Class to simulate behavior of sys.stdout or sys.stderr.