spacepy.datamanager.RePath¶
- class spacepy.datamanager.RePath(expression)[source]¶
A path based on a regular expression + time format
- Parameters:
- expressionstring
Regular expression that matches the files desired. Will also recognize strftime parameters %w %d %m %y %Y %H %M %s %j %U %W, all zero-pad. https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior Can have subdirectory reference, but separator should be unix-style, with no leading slash. Matching is normally done against entire string, anchors should NOT be included.
Methods
match
(string[, dt, where])Matches a string against a path or part thereof, optionally anchored at a particular date/time
path_slice
(path, start[, stop, step, native])Slice a path by elements, as in getitem or []
path_split
(path[, native])Break a path apart into a list for each path element.
Attributes
- match(string, dt=None, where=None)[source]¶
Matches a string against a path or part thereof, optionally anchored at a particular date/time
- Returns:
- outre.MatchObject
The result of the match.
- Other Parameters:
- dtdatetime.datetime
The time to specifically match; otherwise matches all files.
- wherestr
Where to match: None to match the string to the entire path (default);
'start'
to match entire string against the start of the path;'end'
to match entire path against end of string. Note this matches the last elements of the string, not just the last characters, i.e.,oo/bar
will not matchfoo/bar
. Similarly,'start'
matches the first elements of the path, i.e.,foo/ba
will not matchfoo/bar
start
matches subset of path, i.e., the string is a directory that may contain full matches further down the tree.end
matches a subset of the string, i.e, the string is a path to a file that would be a complete match except it has additional path elements leading. This is the order that tends to be useful.
- static path_slice(path, start, stop=None, step=None, native=False)[source]¶
Slice a path by elements, as in getitem or []
- Parameters:
- pathstr
Path to slice
- startint
First path element to return, or the only element if stop and step are not specified.
- Returns:
- outstr
Selection of the path
- Other Parameters:
- stopint
First path element to NOT return, i.e., one past the last. If
stop
is not specified butstep
is, return to end.- stepint
Increment between each.
- nativebool
Is this a native path or UNIX-style? (default False, UNIX)
Examples
>>> path = "foo/bar/baz" >>> spacepy.datamanager.DataManager.path_slice(path, 1) "bar" >>> spacepy.datamanager.DataManager.path_slice(path, 0, step=2) "foo/baz" >>> spacepy.datamanager.DataManager.path_slice(path, 1, 3) "bar/baz"
- static path_split(path, native=False)[source]¶
Break a path apart into a list for each path element.
- Parameters:
- pathstr
Path to split
- nativebool
Is this a native path or UNIX-style? (default False, UNIX)
- Returns:
- outlist of str
One path element (directory or file) per item
- fmt_to_re = {'H': '[0-5]\\d', 'M': '[0-5]\\d', 'U': '[0-5]\\d', 'W': '[0-5]\\d', 'Y': '\\d{4}', 'd': '[0-3]\\d', 'j': '[0-3]\\d\\d', 'm': '[0-2]\\d', 's': '[0-6]\\d', 'y': '\\d\\d'}¶