Mercurial > repos > cathywise > truststore_import
view PythonTrustStore-0.2.0/py_ts/ts_utils.py @ 3:6de426d89bb9
Uploaded
author | cathywise |
---|---|
date | Wed, 11 Dec 2013 21:05:53 -0500 |
parents | ff126718bdc5 |
children |
line wrap: on
line source
from parts import * class ts_utils(object): @staticmethod def recurseToChildNamed(thisDir, name): if thisDir and thisDir.children and len(thisDir.children) > 0: for child in thisDir.children: if child.name == name: return child else: try: if child.children and len(child.children) > 0: found = ts_utils.recurseToChildNamed(child, name) if found: return found else: pass except AttributeError: pass else: return None @staticmethod def dirAtPath(root, path, createIfMissing=False): location = root for part in path.split('/'): if part: found = ts_utils.recurseToChildNamed(location, part) if found: location = found elif createIfMissing: found = Directory() found.name = part children = location.children if len(children) > 0: children.append(found) else: location.children = [found] location = found return location