Reference¶
cQuery consists of a single function: cquery.matches()
and takes at least two arguments: a root and selector. The root determines from where within a hierarchy to start a query whereas the selector determines what to query for. Additional functions are either helpers
or conveinence measures.
matches |
Yield matches at absolute path root for selector selector given the direction direction. |
first_match |
Convenience function for returning a first match from matches() . |
convert |
Convert CSS3 selector selector into compatible file-path |
cquery.lib¶
cQuery - Content Object Model traversal.
-
cquery.lib.
CONTAINER
¶ str
Metadata storage prefix Metadata associated with directories are prefixed with a so-called “container”. In Open Metadata land, this means an additional directory by the name of ~openmetadata.Path.CONTAINER
-
cquery.lib.
UP
¶ flag
Search direction A flag for
cquery.matches()
specifying that the content traversal should proceed up from the root directory. Use this to retrieve a hierarchy of matches.
-
cquery.lib.
DOWN
¶ flag
Search direction The opposite of the above UP. Use this to retrieve multiple matches within a given hierarchy, located under root
-
cquery.lib.
matches
(root, selector, direction=4, depth=-1)[source]¶ Yield matches at absolute path root for selector selector given the direction direction.
When looking for a first match only, use
first_match()
Parameters: - root (str) – Absolute path from which where to start looking
- selector (str) – CSS3-compliant selector, e.g. ”.Asset”
- direction (enum, optional) – Search either up or down a hierarchy
- depth (int) – Depth of traversal; a value of -1 means infinite
Yields: path (str) – Absolute path of next match.
-
cquery.lib.
errors
¶ Collection of errors occured during os.walk (NotImplemented)
Raises: OSError
– ENOTDIR is raised if path root is not a directoryExample
>>> import os >>> paths = list() >>> for match in matches(os.getcwd(), ".Asset"): ... paths.append(match)
-
cquery.lib.
first_match
(root, selector, direction=4, depth=-1)[source]¶ Convenience function for returning a first match from
matches()
.Parameters: - root (str) – Absolute path from which where to start loo
- selector (str) – CSS-style selector, e.g. .Asset
- direction (enum) – Search either up or down a hierarchy
Returns: path – Absolute path if successful, None otherwise.
Return type: str
Example
>>> import os >>> path = first_match(os.getcwd(), ".Asset")