lsst.daf.persistence  13.0-35-g3a9824c
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
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

Public Member Functions

def __init__
 
def ppprint
 
def __repr__
 
def __getitem__
 
def __setitem__
 
def __contains__
 
def update
 
def merge
 
def names
 
def asArray
 
def getValue
 
def setValue
 
def mergeDefaults
 
def exists
 
def getString
 
def getBool
 
def getPolicy
 
def getStringArray
 
def __lt__
 
def __le__
 
def __eq__
 
def __ne__
 
def __gt__
 
def __ge__
 
def dump
 i/o # More...
 
def dumpToFile
 

Static Public Member Functions

def defaultPolicyFile
 

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 formats supported:
- yaml: read and write is supported.
- pex policy: read is supported, although this is deprecated and will at some point be removed.

Definition at line 57 of file policy.py.

Constructor & Destructor Documentation

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 '.paf' or '.yaml'.
other (Pex Policy) Initializes this Policy with the values in the passed-in Pex Policy.
other (Policy) Copies the other Policy's values into this one.
other (dict) Copies the values from the dict into this Policy.

Definition at line 70 of file policy.py.

Member Function Documentation

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

Definition at line 195 of file policy.py.

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

Definition at line 386 of file policy.py.

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

Definition at line 401 of file policy.py.

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

Definition at line 166 of file policy.py.

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

Definition at line 396 of file policy.py.

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

Definition at line 381 of file policy.py.

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

Definition at line 376 of file policy.py.

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

Definition at line 391 of file policy.py.

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

Definition at line 105 of file policy.py.

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

Definition at line 179 of file policy.py.

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 283 of file policy.py.

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 206 of file policy.py.

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

i/o #

Writes the policy to a yaml stream.

:param stream:
:return:

Definition at line 409 of file policy.py.

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

:param path:
:return:

Definition at line 430 of file policy.py.

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 326 of file policy.py.

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 344 of file policy.py.

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

:param key:
:return:

Definition at line 353 of file policy.py.

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 335 of file policy.py.

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 362 of file policy.py.

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 299 of file policy.py.

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 253 of file policy.py.

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 317 of file policy.py.

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 264 of file policy.py.

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 96 of file policy.py.

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 308 of file policy.py.

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 229 of file policy.py.

Member Data Documentation

lsst.daf.persistence.policy.Policy.data

Definition at line 85 of file policy.py.


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