6.21. foundations.walkers

walkers.py

Platform:
Windows, Linux, Mac Os X.
Description:
This module defines various walking related objects.

Others:

6.21.1. Module Attributes

foundations.walkers.LOGGER

6.21.2. Functions

foundations.walkers.filesWalker(directory, filtersIn=None, filtersOut=None, flags=0)[source]

This definition is 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:
  • directory – Directory to recursively walk. ( String )
  • filtersIn – Regex filters in list. ( Tuple / List )
  • filtersIn – Regex filters out list. ( Tuple / List )
  • flags – Regex flags. ( Integer )
Returns:

File. ( String )

foundations.walkers.depthWalker(directory, maximumDepth=1)[source]

This definition is 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)
...
('./foundations/tests/testsFoundations/resources/standard/level_0', ['level_1'], ['standard.ibl'])
('./foundations/tests/testsFoundations/resources/standard/level_0/level_1', ['level_2'], ['loremIpsum.txt', 'standard.rc'])
>>> for item in depthWalker("./foundations/tests/testsFoundations/resources/standard/level_0", 2):
...     print(item)
...
('./foundations/tests/testsFoundations/resources/standard/level_0', ['level_1'], ['standard.ibl'])
('./foundations/tests/testsFoundations/resources/standard/level_0/level_1', ['level_2'], ['loremIpsum.txt', 'standard.rc'])
('./foundations/tests/testsFoundations/resources/standard/level_0/level_1/level_2', [], ['standard.sIBLT'])
Parameters:
  • directory – Directory to walk. ( String )
  • maximumDepth – Maximum depth. ( Integer )
Returns:

Parent directory, directories, files. ( Tuple )

foundations.walkers.dictionariesWalker(dictionary, path=())[source]

This definition is 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:
  • dictionary – Dictionary to walk. ( Dictionary )
  • path – Walked paths. ( Tuple )
Returns:

Path, key, value. ( 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.

foundations.walkers.nodesWalker(node, ascendants=False)[source]

This definition is 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:
  • node – Node to walk. ( AbstractCompositeNode )
  • ascendants – Ascendants instead of descendants will be yielded. ( Boolean )
Returns:

Node. ( AbstractNode / AbstractCompositeNode )

Table Of Contents

Previous topic

6.20. foundations.verbose

Next topic

6.22. manager.component

This Page