.\" Man page generated from reStructuredText. . .TH "PATHTOOLS" "3" "February 13, 2015" "0.1.2" "pathtools" .SH NAME pathtools \- pathtools Documentation . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .sp Python API library for common path and pattern functionality. .SH EASY INSTALLATION .sp You can use \fI\%pip\fP to install \fBpathtools\fP quickly and easily: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ pip install pathtools .ft P .fi .UNINDENT .UNINDENT .SH API REFERENCE .SS \fIpathtools.path\fP .INDENT 0.0 .TP .B module pathtools.path .TP .B synopsis Directory walking, listing, and path sanitizing functions. .TP .B author Yesudeep Mangalapilly <\fI\%yesudeep@gmail.com\fP> .UNINDENT .SS Functions .INDENT 0.0 .TP .B pathtools.path.get_dir_walker(recursive, topdown=True, followlinks=False) Returns a recursive or a non\-recursive directory walker. .INDENT 7.0 .TP .B Parameters \fBrecursive\fP \-\- \fBTrue\fP produces a recursive walker; \fBFalse\fP produces a non\-recursive walker. .TP .B Returns A walker function. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B pathtools.path.walk(dir_pathname, recursive=True, topdown=True, followlinks=False) Walks a directory tree optionally recursively. Works exactly like \fBos.walk()\fP only adding the \fIrecursive\fP argument. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBdir_pathname\fP \-\- The directory to traverse. .IP \(bu 2 \fBrecursive\fP \-\- \fBTrue\fP for walking recursively through the directory tree; \fBFalse\fP otherwise. .IP \(bu 2 \fBtopdown\fP \-\- Please see the documentation for \fBos.walk()\fP .IP \(bu 2 \fBfollowlinks\fP \-\- Please see the documentation for \fBos.walk()\fP .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B pathtools.path.listdir(dir_pathname, recursive=True, topdown=True, followlinks=False) Enlists all items using their absolute paths in a directory, optionally recursively. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBdir_pathname\fP \-\- The directory to traverse. .IP \(bu 2 \fBrecursive\fP \-\- \fBTrue\fP for walking recursively through the directory tree; \fBFalse\fP otherwise. .IP \(bu 2 \fBtopdown\fP \-\- Please see the documentation for \fBos.walk()\fP .IP \(bu 2 \fBfollowlinks\fP \-\- Please see the documentation for \fBos.walk()\fP .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B pathtools.path.list_directories(dir_pathname, recursive=True, topdown=True, followlinks=False) Enlists all the directories using their absolute paths within the specified directory, optionally recursively. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBdir_pathname\fP \-\- The directory to traverse. .IP \(bu 2 \fBrecursive\fP \-\- \fBTrue\fP for walking recursively through the directory tree; \fBFalse\fP otherwise. .IP \(bu 2 \fBtopdown\fP \-\- Please see the documentation for \fBos.walk()\fP .IP \(bu 2 \fBfollowlinks\fP \-\- Please see the documentation for \fBos.walk()\fP .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B pathtools.path.list_files(dir_pathname, recursive=True, topdown=True, followlinks=False) Enlists all the files using their absolute paths within the specified directory, optionally recursively. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBdir_pathname\fP \-\- The directory to traverse. .IP \(bu 2 \fBrecursive\fP \-\- \fBTrue\fP for walking recursively through the directory tree; \fBFalse\fP otherwise. .IP \(bu 2 \fBtopdown\fP \-\- Please see the documentation for \fBos.walk()\fP .IP \(bu 2 \fBfollowlinks\fP \-\- Please see the documentation for \fBos.walk()\fP .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B pathtools.path.absolute_path(path) Returns the absolute path for the given path and normalizes the path. .INDENT 7.0 .TP .B Parameters \fBpath\fP \-\- Path for which the absolute normalized path will be found. .TP .B Returns Absolute normalized path. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B pathtools.path.real_absolute_path(path) Returns the real absolute normalized path for the given path. .INDENT 7.0 .TP .B Parameters \fBpath\fP \-\- Path for which the real absolute normalized path will be found. .TP .B Returns Real absolute normalized path. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B pathtools.path.parent_dir_path(path) Returns the parent directory path. .INDENT 7.0 .TP .B Parameters \fBpath\fP \-\- Path for which the parent directory will be obtained. .TP .B Returns Parent directory path. .UNINDENT .UNINDENT .SS \fIpathtools.patterns\fP .INDENT 0.0 .TP .B module pathtools.patterns .TP .B synopsis Wildcard pattern matching and filtering functions for paths. .TP .B author Yesudeep Mangalapilly <\fI\%yesudeep@gmail.com\fP> .UNINDENT .SS Functions .INDENT 0.0 .TP .B pathtools.patterns.match_path(pathname, included_patterns=None, excluded_patterns=None, case_sensitive=True) Matches a pathname against a set of acceptable and ignored patterns. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBpathname\fP \-\- A pathname which will be matched against a pattern. .IP \(bu 2 \fBincluded_patterns\fP \-\- Allow filenames matching wildcard patterns specified in this list. If no pattern is specified, the function treats the pathname as a match_path. .IP \(bu 2 \fBexcluded_patterns\fP \-\- Ignores filenames matching wildcard patterns specified in this list. If no pattern is specified, the function treats the pathname as a match_path. .IP \(bu 2 \fBcase_sensitive\fP \-\- \fBTrue\fP if matching should be case\-sensitive; \fBFalse\fP otherwise. .UNINDENT .TP .B Returns \fBTrue\fP if the pathname matches; \fBFalse\fP otherwise. .TP .B Raises ValueError if included patterns and excluded patterns contain the same pattern. .UNINDENT .INDENT 7.0 .TP .B Doctests:: .sp .nf .ft C >>> 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 \(gaset([\(aq*.py\(aq])\(ga included and excluded .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B pathtools.patterns.match_path_against(pathname, patterns, case_sensitive=True) Determines whether the pathname matches any of the given wildcard patterns, optionally ignoring the case of the pathname and patterns. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBpathname\fP \-\- A path name that will be matched against a wildcard pattern. .IP \(bu 2 \fBpatterns\fP \-\- A list of wildcard patterns to match_path the filename against. .IP \(bu 2 \fBcase_sensitive\fP \-\- \fBTrue\fP if the matching should be case\-sensitive; \fBFalse\fP otherwise. .UNINDENT .TP .B Returns \fBTrue\fP if the pattern matches; \fBFalse\fP otherwise. .UNINDENT .INDENT 7.0 .TP .B Doctests:: .sp .nf .ft C >>> 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:\ewindows\eblah\eBLAH.PY", ["*.py", "*.txt"], True) False >>> match_path_against("C:\ewindows\eblah\eBLAH.PY", ["*.py", "*.txt"], False) True .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B pathtools.patterns.filter_paths(pathnames, included_patterns=None, excluded_patterns=None, case_sensitive=True) Filters from a set of paths based on acceptable patterns and ignorable patterns. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBpathnames\fP \-\- A list of path names that will be filtered based on matching and ignored patterns. .IP \(bu 2 \fBincluded_patterns\fP \-\- Allow filenames matching wildcard patterns specified in this list. If no pattern list is specified, ["*"] is used as the default pattern, which matches all files. .IP \(bu 2 \fBexcluded_patterns\fP \-\- Ignores filenames matching wildcard patterns specified in this list. If no pattern list is specified, no files are ignored. .IP \(bu 2 \fBcase_sensitive\fP \-\- \fBTrue\fP if matching should be case\-sensitive; \fBFalse\fP otherwise. .UNINDENT .TP .B Returns A list of pathnames that matched the allowable patterns and passed through the ignored patterns. .UNINDENT .INDENT 7.0 .TP .B Doctests:: .sp .nf .ft C >>> 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 .ft P .fi .UNINDENT .UNINDENT .sp Found a bug in or want a feature added to \fBpathtools\fP? You can fork the official \fI\%code repository\fP or file an issue ticket at the \fI\%issue tracker\fP\&. .INDENT 0.0 .IP \(bu 2 \fIgenindex\fP .IP \(bu 2 \fImodindex\fP .IP \(bu 2 \fIsearch\fP .UNINDENT .SH AUTHOR Yesudeep Mangalapilly .SH COPYRIGHT 2010, Yesudeep Mangalapilly .\" Generated by docutils manpage writer. .