Warning
This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.
galaxy.util.path package¶
Path manipulation functions.
-
galaxy.util.path.
safe_contains
(prefix, path, whitelist=None, real=None)[source]¶ Ensure a path is contained within another path.
Given any two filesystem paths, ensure that
path
is contained inprefix
. Ifpath
exists (either as an absolute path or relative toprefix
), it is canonicalized withos.path.realpath()
to ensure it is not a symbolic link that points outside ofprefix
. If it is a symbolic link andwhitelist
is set, the symbolic link may also point inside awhitelist
path.The
path
is checked againstwhitelist
using either its absolute pathname (if passed in as absolute) or relative toprefix
and canonicalized (if applicable). It is notos.path.join()``ed with each ``whitelist
directory.Parameters: Return type: Returns: True
ifpath
is contained withinprefix
orwhitelist
,False
otherwise.
-
galaxy.util.path.
safe_makedirs
(path)[source]¶ Safely make a directory, do not fail if it already exists or is created during execution.
Parameters: path (string) – a directory to create
-
galaxy.util.path.
safe_relpath
(path)[source]¶ Determine whether a relative path references a path outside its root.
This is a path computation: the filesystem is not accessed to confirm the existence or nature of
path
.Parameters: path (string) – a path to check Return type: bool Returns: True
if path is relative and does not reference a path in a parent directory,False
otherwise.
-
galaxy.util.path.
safe_walk
(path, whitelist=None)[source]¶ Walk a path and return only the contents that are not symlinks outside the path.
Symbolic links are followed if a whitelist is provided. The path itself cannot be a symbolic link unless the pointed to location is in the whitelist.
Parameters: - path (string) – a directory to check for unsafe contents
- whitelist (list of strings) – list of additional paths under which contents may be located
Return type: iterator
Returns: Iterator of “safe”
os.walk()
tuples found underpath
-
galaxy.util.path.
unsafe_walk
(path, whitelist=None, username=None)[source]¶ Walk a path and ensure that none of its contents are symlinks outside the path.
It is assumed that
path
itself has already been validated e.g. withsafe_relpath()
orsafe_contains()
. This function is most useful for the case where you want to test whether a directory contains safe paths, but do not want to actually walk the safe contents.Parameters: - path (string) – a directory to check for unsafe contents
- whitelist (list of strings) – list of additional paths under which contents may be located
Return type: list of strings
Returns: A list of “bad” files found under
path
-
galaxy.util.path.
joinext
(root, ext)[source]¶ Roughly the reverse of os.path.splitext.
Parameters: - root (string) – part of the filename before the extension
- ext – the extension
Return type: Returns: root
joined withext
separated by a singleos.extsep
-
galaxy.util.path.
has_ext
(path, ext, aliases=False, ignore=None)[source]¶ Determine whether
path
has extensionext
Parameters: Return type: Returns: True
if path is a YAML file,False
otherwise.
-
galaxy.util.path.
get_ext
(path, ignore=None, canonicalize=True)[source]¶ Return the extension of
path
Parameters: Return type:
Submodules¶
galaxy.util.path.ntpath module¶
Galaxy “safe” path functions forced to work with Windows-style paths regardless of current platform
galaxy.util.path.posixpath module¶
Galaxy “safe” path functions forced to work with POSIX-style paths regardless of current platform