walkers.py
Others:
Defines a generator used to walk files using given filters.
Usage:
>>> for file in filesWalker("./foundations/tests/testsFoundations/resources/standard/level_0"):
... print(file)
...
./foundations/tests/testsFoundations/resources/standard/level_0/level_1/level_2/standard.sIBLT
./foundations/tests/testsFoundations/resources/standard/level_0/level_1/loremIpsum.txt
./foundations/tests/testsFoundations/resources/standard/level_0/level_1/standard.rc
./foundations/tests/testsFoundations/resources/standard/level_0/standard.ibl
>>> for file in filesWalker("./foundations/tests/testsFoundations/resources/standard/level_0", ("\.sIBLT",)):
... print(file)
...
./foundations/tests/testsFoundations/resources/standard/level_0/level_1/level_2/standard.sIBLT
Parameters: | |
---|---|
Returns: | File. |
Return type: | unicode |
Defines a generator used to walk into directories using given maximum depth.
Usage:
>>> for item in depthWalker("./foundations/tests/testsFoundations/resources/standard/level_0"):
... print(item)
...
(u'./foundations/tests/testsFoundations/resources/standard/level_0', [u'level_1'], [u'standard.ibl'])
(u'./foundations/tests/testsFoundations/resources/standard/level_0/level_1', [u'level_2'], [u'loremIpsum.txt', u'standard.rc'])
>>> for item in depthWalker("./foundations/tests/testsFoundations/resources/standard/level_0", 2):
... print(item)
...
(u'./foundations/tests/testsFoundations/resources/standard/level_0', [u'level_1'], [u'standard.ibl'])
(u'./foundations/tests/testsFoundations/resources/standard/level_0/level_1', [u'level_2'], [u'loremIpsum.txt', u'standard.rc'])
(u'./foundations/tests/testsFoundations/resources/standard/level_0/level_1/level_2', [], [u'standard.sIBLT'])
Parameters: | |
---|---|
Returns: | Parent directory, directories, files. |
Return type: | tuple |
Defines a generator used to walk into nested dictionaries.
Usage:
>>> nestedDictionary = {"Level 1A":{"Level 2A": { "Level 3A" : "Higher Level"}}, "Level 1B" : "Lower level"}
>>> dictionariesWalker(nestedDictionary)
<generator object dictionariesWalker at 0x10131a320>
>>> for value in dictionariesWalker(nestedDictionary):
... print value
(('Level 1A', 'Level 2A'), 'Level 3A', 'Higher Level')
((), 'Level 1B', 'Lower level')
Parameters: | |
---|---|
Returns: | Path, key, value. |
Return type: | tuple |
Note: | This generator won’t / can’t yield any dictionaries, if you want to be able to retrieve dictionaries anyway, you will have to either encapsulate them in another object, or mutate their base class. |
Defines a generator used to walk into Nodes hierarchy.
Usage:
>>> nodeA = AbstractCompositeNode("MyNodeA")
>>> nodeB = AbstractCompositeNode("MyNodeB", nodeA)
>>> nodeC = AbstractCompositeNode("MyNodeC", nodeA)
>>> nodeD = AbstractCompositeNode("MyNodeD", nodeB)
>>> nodeE = AbstractCompositeNode("MyNodeE", nodeB)
>>> nodeF = AbstractCompositeNode("MyNodeF", nodeD)
>>> nodeG = AbstractCompositeNode("MyNodeG", nodeF)
>>> nodeH = AbstractCompositeNode("MyNodeH", nodeG)
>>> for node in nodesWalker(nodeA):
... print node.name
MyNodeB
MyNodeD
MyNodeF
MyNodeG
MyNodeH
MyNodeE
MyNodeC
Parameters: |
|
---|---|
Returns: | Node. |
Return type: | AbstractNode or AbstractCompositeNode |