module: | pathtools.path |
---|---|
synopsis: | Directory walking, listing, and path sanitizing functions. |
author: | Gora Khargosh <gora.khargosh@gmail.com> |
Returns a recursive or a non-recursive directory walker.
Parameters: |
|
---|---|
Returns: | A walker function. |
Walks a directory tree optionally recursively. Works exactly like os.walk() only adding the recursive argument.
Parameters: |
|
---|
Enlists all items using their absolute paths in a directory, optionally recursively.
Parameters: |
|
---|
Enlists all the directories using their absolute paths within the specified directory, optionally recursively.
Parameters: |
|
---|
Enlists all the files using their absolute paths within the specified directory, optionally recursively.
Parameters: |
|
---|
Returns the absolute path for the given path and normalizes the path.
Parameters: |
|
---|---|
Returns: | Absolute normalized path. |
module: | pathtools.patterns |
---|---|
synopsis: | Wildcard pattern matching and filtering functions for paths. |
author: | Gora Khargosh <gora.khargosh@gmail.com> |
Matches a pathname against a set of acceptable and ignored patterns.
Parameters: |
|
---|---|
Returns: | True if the pathname matches; False otherwise. |
Raises : | ValueError if included patterns and excluded patterns contain the same pattern. |
>>> match_path("/Users/gorakhargosh/foobar.py")
True
>>> match_path("/Users/gorakhargosh/foobar.py", case_sensitive=False)
True
>>> match_path("/users/gorakhargosh/foobar.py", ["*.py"], ["*.PY"], True)
True
>>> match_path("/users/gorakhargosh/FOOBAR.PY", ["*.py"], ["*.PY"], True)
False
>>> match_path("/users/gorakhargosh/foobar/", ["*.py"], ["*.txt"], False)
False
>>> match_path("/users/gorakhargosh/FOOBAR.PY", ["*.py"], ["*.PY"], False)
Traceback (most recent call last):
...
ValueError: conflicting patterns `set(['*.py'])` included and excluded
Determines whether the pathname matches any of the given wildcard patterns, optionally ignoring the case of the pathname and patterns.
Parameters: |
|
---|---|
Returns: | True if the pattern matches; False otherwise. |
>>> match_path_against("/home/username/foobar/blah.py", ["*.py", "*.txt"], False)
True
>>> match_path_against("/home/username/foobar/blah.py", ["*.PY", "*.txt"], True)
False
>>> match_path_against("/home/username/foobar/blah.py", ["*.PY", "*.txt"], False)
True
>>> match_path_against("C:\windows\blah\BLAH.PY", ["*.py", "*.txt"], True)
False
>>> match_path_against("C:\windows\blah\BLAH.PY", ["*.py", "*.txt"], False)
True
Filters from a set of paths based on acceptable patterns and ignorable patterns.
Parameters: |
|
---|---|
Returns: | A list of pathnames that matched the allowable patterns and passed through the ignored patterns. |
>>> pathnames = set(["/users/gorakhargosh/foobar.py", "/var/cache/pdnsd.status", "/etc/pdnsd.conf", "/usr/local/bin/python"])
>>> set(filter_paths(pathnames)) == pathnames
True
>>> set(filter_paths(pathnames, case_sensitive=False)) == pathnames
True
>>> set(filter_paths(pathnames, ["*.py", "*.conf"], ["*.status"], case_sensitive=True)) == set(["/users/gorakhargosh/foobar.py", "/etc/pdnsd.conf"])
True