cdms2.database:LDAPDatabase¶
-
LDAPDatabase.
searchFilter
(filter=None, tag=None, relbase=None, scope=2, attnames=None, timeout=None)[source]¶ Method
- searchFilter
(filter=None, tag=None, relbase=None, scope=Subtree, attnames=None, timeout=None)
Description
Search a CDMS database.
Arguments -
filter: string search filter Simple filters have the form “tag = value”. Simple filters can be combined using logical operators ‘&’, ‘|’, ‘!’ in prefix notation. For example, the filter ‘(&(objectclass=variable)(id=cli))’ finds all variables named cli.
More formally
filter = “(” filtercomp “)”
- filtercomp = “&” filterlist | # and
“|” filterlist | # or “!” filterlist | # not simple
filterlist = filter | filter filterlist
simple = tag op value
- op = “=” | # equality
“~=” | # approximate equality “<=” | # lexicographically less than or equal to “>=” # lexicographically greater than or equal to
value = string, may include ‘*’ as a wild card
tag: string class tag (“dataset” | “variable” | “database” | “axis” | “grid”). Restricts the search to a class of objects
relbase: string search base, relative to the database path scope: search scope (Subtree | Onelevel | Base). Subtree searches the base object and its descendants.
Onelevel searches the base object and its immediate descendants. Base searches the base object alone.
Default is Subtree.
- attnames:
list of attribute names. Restricts the attributes returned.
- timeout:
integer number of seconds before timeout.
- Returns
- SearchResult instance.
Entries can be accessed sequentially.
For each entry,
entry.name is the name of the entry,
entry.attributes is a dictionary of the attributes returned by the search,
entry.getObject() returns the CDMS object associated with the entry:
for entry in result: print entry.name, entry.attributes[“id”]
Entries can be refined with searchPredicate().
- Example
Find all variables named “cli”: result = db.searchFilter(filter=”id=cli”,tag=”variable”)
Find all objects in dataset “ncep_reanalysis_mo”: result = db.searchFilter(relbase=”dataset=ncep_reanalysis_mo”), scope=cdms.Onelevel)