lsst.daf.persistence g6a31054a6e+baf510fb77
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
lsst.daf.persistence.policy.Policy Class Reference
Inheritance diagram for lsst.daf.persistence.policy.Policy:
lsst.daf.persistence.policy._PolicyBase lsst.daf.persistence.policy._PolicyMeta lsst.daf.persistence.access.AccessCfg

Public Member Functions

def __init__ (self, other=None)
 
def ppprint (self)
 
def __repr__ (self)
 
def __getitem__ (self, name)
 
def __setitem__ (self, name, value)
 
def __contains__ (self, key)
 
def update (self, other)
 
def merge (self, other)
 
def names (self, topLevelOnly=False)
 
def asArray (self, name)
 
def getValue (self, name)
 
def setValue (self, name, value)
 
def mergeDefaults (self, other)
 
def exists (self, key)
 
def getString (self, key)
 
def getBool (self, key)
 
def getPolicy (self, key)
 
def getStringArray (self, key)
 
def __lt__ (self, other)
 
def __le__ (self, other)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __gt__ (self, other)
 
def __ge__ (self, other)
 
def dump (self, output)
 i/o # More...
 
def dumpToFile (self, path)
 

Static Public Member Functions

def defaultPolicyFile (productName, fileName, relativePath=None)
 

Public Attributes

 data
 

Detailed Description

Policy implements a datatype that is used by Butler for configuration parameters.
It is essentially a dict with key/value pairs, including nested dicts (as values). In fact, it can be
initialized with a dict. The only caveat is that keys may NOT contain dots ('.'). This is explained next:
Policy extends the dict api so that hierarchical values may be accessed with dot-delimited notiation.
That is, foo.getValue('a.b.c') is the same as foo['a']['b']['c'] is the same as foo['a.b.c'], and either
of these syntaxes may be used.

Storage format supported:
- yaml: read and write is supported.

Definition at line 48 of file policy.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.daf.persistence.policy.Policy.__init__ (   self,
  other = None 
)
Initialize the Policy. Other can be used to initialize the Policy in a variety of ways:
other (string) Treated as a path to a policy file on disk. Must end with '.yaml'.
other (Policy) Copies the other Policy's values into this one.
other (dict) Copies the values from the dict into this Policy.

Reimplemented in lsst.daf.persistence.access.AccessCfg.

Definition at line 60 of file policy.py.

Member Function Documentation

◆ __contains__()

def lsst.daf.persistence.policy.Policy.__contains__ (   self,
  key 
)

Definition at line 161 of file policy.py.

◆ __eq__()

def lsst.daf.persistence.policy.Policy.__eq__ (   self,
  other 
)

Definition at line 352 of file policy.py.

◆ __ge__()

def lsst.daf.persistence.policy.Policy.__ge__ (   self,
  other 
)

Definition at line 367 of file policy.py.

◆ __getitem__()

def lsst.daf.persistence.policy.Policy.__getitem__ (   self,
  name 
)

Definition at line 132 of file policy.py.

◆ __gt__()

def lsst.daf.persistence.policy.Policy.__gt__ (   self,
  other 
)

Definition at line 362 of file policy.py.

◆ __le__()

def lsst.daf.persistence.policy.Policy.__le__ (   self,
  other 
)

Definition at line 347 of file policy.py.

◆ __lt__()

def lsst.daf.persistence.policy.Policy.__lt__ (   self,
  other 
)

Definition at line 342 of file policy.py.

◆ __ne__()

def lsst.daf.persistence.policy.Policy.__ne__ (   self,
  other 
)

Definition at line 357 of file policy.py.

◆ __repr__()

def lsst.daf.persistence.policy.Policy.__repr__ (   self)

Definition at line 91 of file policy.py.

◆ __setitem__()

def lsst.daf.persistence.policy.Policy.__setitem__ (   self,
  name,
  value 
)

Definition at line 145 of file policy.py.

◆ asArray()

def lsst.daf.persistence.policy.Policy.asArray (   self,
  name 
)
Get a value as an array. May contain one or more elements.

:param key:
:return:

Definition at line 249 of file policy.py.

◆ defaultPolicyFile()

def lsst.daf.persistence.policy.Policy.defaultPolicyFile (   productName,
  fileName,
  relativePath = None 
)
static
Get the path to a default policy file.

Determines a directory for the product specified by productName. Then Concatenates
productDir/relativePath/fileName (or productDir/fileName if relativePath is None) to find the path
to the default Policy file

@param productName (string) The name of the product that the default policy is installed as part of
@param fileName (string) The name of the policy file. Can also include a path to the file relative to
                         the directory where the product is installed.
@param relativePath (string) The relative path from the directior where the product is installed to
                             the location where the file (or the path to the file) is found. If None
                             (default), the fileName argument is relative to the installation
                             directory.

Definition at line 172 of file policy.py.

◆ dump()

def lsst.daf.persistence.policy.Policy.dump (   self,
  output 
)

i/o #

Writes the policy to a yaml stream.

:param stream:
:return:

Definition at line 375 of file policy.py.

◆ dumpToFile()

def lsst.daf.persistence.policy.Policy.dumpToFile (   self,
  path 
)
Writes the policy to a file.

:param path:
:return:

Definition at line 396 of file policy.py.

◆ exists()

def lsst.daf.persistence.policy.Policy.exists (   self,
  key 
)
Query if a key exists in this Policy

:param key:
:return: True if the key exists, else false.

Definition at line 292 of file policy.py.

◆ getBool()

def lsst.daf.persistence.policy.Policy.getBool (   self,
  key 
)
Get the value of a key.

:param key:
:return: the value for key

Definition at line 310 of file policy.py.

◆ getPolicy()

def lsst.daf.persistence.policy.Policy.getPolicy (   self,
  key 
)
Get a subpolicy.

:param key:
:return:

Definition at line 319 of file policy.py.

◆ getString()

def lsst.daf.persistence.policy.Policy.getString (   self,
  key 
)
Get the string value of a key.

:param key:
:return: the value for key

Definition at line 301 of file policy.py.

◆ getStringArray()

def lsst.daf.persistence.policy.Policy.getStringArray (   self,
  key 
)
Get a value as an array. May contain one or more elements.

:param key:
:return:

Definition at line 328 of file policy.py.

◆ getValue()

def lsst.daf.persistence.policy.Policy.getValue (   self,
  name 
)
Get the value for a parameter name/key. See class notes about dot-delimited access.

:param name:
:return: the value for the given name.

Definition at line 265 of file policy.py.

◆ merge()

def lsst.daf.persistence.policy.Policy.merge (   self,
  other 
)
Like Policy.update, but will add keys & values from other that DO NOT EXIST in self. Keys and
values that already exist in self will NOT be overwritten.

:param other:
:return:

Definition at line 219 of file policy.py.

◆ mergeDefaults()

def lsst.daf.persistence.policy.Policy.mergeDefaults (   self,
  other 
)
For any keys in other that are not present in self, sets that key and its value into self.

:param other: another Policy
:return: None

Definition at line 283 of file policy.py.

◆ names()

def lsst.daf.persistence.policy.Policy.names (   self,
  topLevelOnly = False 
)
Get the dot-delimited name of all the keys in the hierarchy.
NOTE: this is different than the built-in method dict.keys, which will return only the first level
keys.

Definition at line 230 of file policy.py.

◆ ppprint()

def lsst.daf.persistence.policy.Policy.ppprint (   self)
helper function for debugging, prints a policy out in a readable way in the debugger.

use: pdb> print myPolicyObject.pprint()
:return: a prettyprint formatted string representing the policy

Definition at line 82 of file policy.py.

◆ setValue()

def lsst.daf.persistence.policy.Policy.setValue (   self,
  name,
  value 
)
Set the value for a parameter name/key. See class notes about dot-delimited access.

:param name:
:return: None

Definition at line 274 of file policy.py.

◆ update()

def lsst.daf.persistence.policy.Policy.update (   self,
  other 
)
Like dict.update, but will add or modify keys in nested dicts, instead of overwriting the nested
dict entirely.

For example, for the given code:
foo = {'a': {'b': 1}}
foo.update({'a': {'c': 2}})

If foo is a dict, then after the update foo == {'a': {'c': 2}}
But if foo is a Policy, then after the update foo == {'a': {'b': 1, 'c': 2}}

Definition at line 195 of file policy.py.

Member Data Documentation

◆ data

lsst.daf.persistence.policy.Policy.data

Definition at line 74 of file policy.py.


The documentation for this class was generated from the following file: