Home | Trees | Indices | Help |
|
---|
|
Encapsulate a file name that might look differently in different environments depending on environment settings. The file name has an absolute (original) variant but parts of it can be looked up from environment or Biskit settings variables (if the original path doesn't exist in the current environment).
Creating a LocalPath:
Creating a LocalPath is simple. By default, LocalPath takes a normal filename and browses the local Biskit.settings and run-time environment for variables that can replace part of that path.
Variable values must be at least 3 char long and contain at least one '/' in order to avoid substitution of single letters or '/a' etc. $PYTHONPATH, $PATH and $PWD are ignored.
Variables from Biskit.settings (thus also .biskit/settings.cfg) have priority over normal environment variables both during the construction of LocalPath instances and during the reconstruction of a locally valid path.
Using a LocalPath:
LocalPath tries behaving like the simple absolute path string when it comes to slicing etc:l = LocalPath( '{/home/raik|$USER}/data/x.txt' ) l[:] == '/home/raik/data/x.txt' == l.local() l[-4:] == '.txt' str( l ) == l.local() l.formatted() == '{/home/raik|$USER}/data/x.txt'
To Do: input: allow multiple or overlapping substitutions output: only substitute what is necessary until path exists
|
|||
|
__init__(self,
path=None,
checkEnv=1,
minLen=3,
maxSub=1,
absolute=1,
resolveLinks=0,
**vars) Create a new environment-dependent path from either a list of fragments and their substitution variable names or from a path or from a formatted string (not implemented). |
||
|
__setstate__(self,
state) called for unpickling the object. |
||
str
|
get_local(self,
existing=0) Return a valid, absolute path. |
||
str
|
local(self,
existing=0,
force=1) Cached variant of get_local. |
||
str
|
formatted(self) Get a string representation that describes the original path and all possible substitutions by environment variables. |
||
str
|
original(self) Get the original path (also non-absolute) that is used if the file exists or if there are no environment variables for any of the substitutions. |
||
|
set(self,
v,
checkEnv=1,
minLen=3,
maxSub=1,
absolute=1,
resolveLinks=0,
**vars) Assign a new file name. |
||
|
set_fragments(self,
*fragments) Set new path from list of path fragments and their possible environment variable substitutions. |
||
|
set_string(self,
s) Set a new path and its substitutable parts from a formatted string. |
||
| absfile(self, fname, resolveLinks=0) | ||
|
set_path(self,
fname,
minLen=3,
absolute=1,
resolveLinks=0,
maxSub=1,
**vars) Set a new path and try to identify settings/environment variables that could substitute parts of it. |
||
1|0
|
exists(self) Check if path exists |
||
any
|
load(self) Try to unpickle an object from the currently valid path. |
||
str
|
dump(self,
o) Try to pickle an object to the currently valid path. |
||
| __find_subpath(self, path, subpath) | ||
[ (str, str) ]
|
__substitute(self,
fragments,
name,
value) Look in all not yet substituted fragments for parts that can be substituted by value and, if successful, create a new fragment |
||
int
|
__is_path(self,
o,
minLen=3) Check whether an object is a path string (existing or not). |
||
[ (str,str) ]
|
__path_vars(self,
d,
minLen=3,
vars={},
exclude=[]) @see __paths_in_settings and __paths_in_env |
||
[ (str,str) ]
|
__paths_in_settings(self,
minLen=3,
vars={},
exclude=[]) Get all setting variables looking like a path, sorted by length |
||
[ (str,str) ]
|
__paths_in_env(self,
minLen=3,
vars={},
exclude=[]) Get all environment variables with at least one '/' sorted by length. |
||
[ (str,str) ]
|
get_substitution_pairs(self,
minLen=3,
vars={},
exclude=[]) Get all variable/value pairs that are available for path substitutions. |
||
| get_substitution_dict(self, minLen=3, vars={}, exclude=[]) | ||
str
|
__str__(self) Returns Same as local(). |
||
str
|
__repr__(self) Returns formatted output (Python representation) |
||
int
|
__len__(self) Time costly when repeated many times. |
||
| __getslice__(self, a, b) | ||
| __getitem__(self, i) | ||
|
__eq__(self,
other) supports this == other -> 0|1 |
||
|
__ne__(self,
other) supports this != other -> 0|1 |
||
|
__hash__(self) if __eq__ or __cmp__ are defined hash has to be defined too, otherwise the objects cannot be used as keys in dictionaries (needed for Complex- ModelRegistry). |
||
Inherited from |
|
|||
|
ex_fragment = re.compile('\{([a-zA-Z0-9_~/ ]+)\|\$([a-zA-Z0-9_]+)\}')
|
||
|
ex_minpath = re.compile('/|~[a-zA-Z0-9_~/ ]+')
|
||
|
exclude_vars = ['PWD', 'OLDPWD', 'PYTHONPATH', 'PATH']
|
|
|||
Inherited from |
|
Create a new environment-dependent path from either a list of fragments and their substitution variable names or from a path or from a formatted string (not implemented). A path will be analyzed to substitute as big chunks as possible by environment variables. ~ and ../../ will be expanded both in the given path and in the environment variables.
|
called for unpickling the object. |
Return a valid, absolute path. Either the existing original or with all substitutions for which environment variables exist. This function is time consuming (absfile - os.realpath is the culprit).
|
Cached variant of get_local. Return a valid, absolute path. Either the existing original or with all substitutions for which environment variables exist. This function is time consuming (absfile - os.realpath is the culprit).
|
Get a string representation that describes the original path and all possible substitutions by environment variables.
|
Get the original path (also non-absolute) that is used if the file exists or if there are no environment variables for any of the substitutions.
|
Assign a new file name. checkEnv, minLen, resolve*, maxSub are only considered for path name input.
|
Set new path from list of path fragments and their possible environment variable substitutions. Fragments that can not be substituted are given as (str, None).
|
Set a new path and its substitutable parts from a formatted string.
|
|
Set a new path and try to identify settings/environment variables that could substitute parts of it.
|
Check if path exists
|
Try to unpickle an object from the currently valid path.
|
Try to pickle an object to the currently valid path.
|
|
Look in all not yet substituted fragments for parts that can be substituted by value and, if successful, create a new fragment
|
Check whether an object is a path string (existing or not).
|
@see __paths_in_settings and __paths_in_env
|
Get all setting variables looking like a path, sorted by length
|
Get all environment variables with at least one '/' sorted by length.
|
Get all variable/value pairs that are available for path substitutions.
|
|
str(x)
|
repr(x)
|
Time costly when repeated many times.
|
|
|
supports this == other -> 0|1 |
supports this != other -> 0|1 |
if __eq__ or __cmp__ are defined hash has to be defined too, otherwise the objects cannot be used as keys in dictionaries (needed for Complex- ModelRegistry).
|
|
ex_fragment
|
ex_minpath
|
exclude_vars
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0alpha3 on Tue May 1 22:34:55 2007 | http://epydoc.sourceforge.net |