|
def | __init__ (self, template) |
|
def | walk (self, root, rules=None) |
|
A hierarchical scanner for paths matching a template, optionally
also restricting visited paths to those matching a list of dataId rules.
Definition at line 211 of file datasetScanner.py.
◆ __init__()
def lsst.datarel.datasetScanner.HfsScanner.__init__ |
( |
|
self, |
|
|
|
template |
|
) |
| |
Build an FsScanner for given a path template. The path template
should be a Python string with named format substitution
specifications, as used in mapper policy files. For example:
deepCoadd-results/%(filter)s/%(tract)d/%(patch)s/calexp-%(filter)s-%(tract)d-%(patch)s.fits
Note that a key may appear multiple times. If it does,
the value for each occurrence should be identical (the formatting
specs must be identical). Octal, binary, hexadecimal, and floating
point formats are not supported.
Definition at line 216 of file datasetScanner.py.
217 """Build an FsScanner for given a path template. The path template 218 should be a Python string with named format substitution 219 specifications, as used in mapper policy files. For example: 221 deepCoadd-results/%(filter)s/%(tract)d/%(patch)s/calexp-%(filter)s-%(tract)d-%(patch)s.fits 223 Note that a key may appear multiple times. If it does, 224 the value for each occurrence should be identical (the formatting 225 specs must be identical). Octal, binary, hexadecimal, and floating 226 point formats are not supported. 228 template = os.path.normpath(template)
229 if (len(template) == 0
or 230 template == os.curdir
or 231 template[0] == os.sep
or 232 template[-1] == os.sep):
234 'Path template is empty, absolute, or identifies a directory')
235 self._formatKeys = {}
236 self._pathComponents = []
237 fmt = re.compile(
r'%\((\w+)\).*?([diucrs])')
240 for component
in template.split(os.sep):
246 for m
in fmt.finditer(component):
250 seenBefore = k
in self._formatKeys
252 regex += re.escape(component[last:m.start(0)])
257 if m.group(2)
in 'crs':
264 regex +=
r'[+-]?\d+)' 267 if spec[-1] != self._formatKeys[k].spec[-1]:
269 'Path template contains inconsistent format type-codes ' 273 self._formatKeys[k] = _FormatKey(spec, typ, munge)
274 regex += re.escape(component[last:])
278 regex = re.compile(
'^' + regex +
'$')
279 self._pathComponents.
append(_PathComponent(newKeys, regex, simple))
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
def __init__(self, needLockOnRead=True, data=None, cond=None)
◆ walk()
def lsst.datarel.datasetScanner.HfsScanner.walk |
( |
|
self, |
|
|
|
root, |
|
|
|
rules = None |
|
) |
| |
Generator that descends the given root directory in top-down
fashion, matching paths corresponding to the template and satisfying
the given rule list. The generator yields tuples of the form
(path, dataId), where path is a dataset file name relative to root,
and dataId is a key value dictionary identifying the file.
Definition at line 281 of file datasetScanner.py.
281 def walk(self, root, rules=None):
282 """Generator that descends the given root directory in top-down 283 fashion, matching paths corresponding to the template and satisfying 284 the given rule list. The generator yields tuples of the form 285 (path, dataId), where path is a dataset file name relative to root, 286 and dataId is a key value dictionary identifying the file. 289 while os.path.exists(root)
and not oneFound:
290 stack = [(0, root, rules, {})]
292 depth, path, rules, dataId = stack.pop()
293 if os.path.isfile(path):
295 pc = self._pathComponents[depth]
299 if not os.path.exists(os.path.join(path, pc.regex)):
302 entries = os.listdir(path)
309 m = pc.regex.match(e)
314 for i, k
in enumerate(pc.keys):
315 subDataId = self._formatKeys[k].munge(k, m.group(i + 1), subDataId)
320 if subRules
and pc.keys:
325 if k
not in r
or subDataId[k]
in r[k]:
331 p = os.path.join(path, e)
332 if depth < len(self._pathComponents):
334 stack.append((depth, p, subRules, subDataId))
335 elif depth == len(self._pathComponents):
336 if os.path.isfile(p):
338 yield os.path.relpath(p, root), subDataId
341 root = os.path.join(root,
"_parent")
◆ _formatKeys
lsst.datarel.datasetScanner.HfsScanner._formatKeys |
|
private |
◆ _pathComponents
lsst.datarel.datasetScanner.HfsScanner._pathComponents |
|
private |
The documentation for this class was generated from the following file:
- /home/jenkins-slave/snowflake/release/lsstsw/stack/Linux64/datarel/14.0+77/python/lsst/datarel/datasetScanner.py