CMS 3D CMS Logo

Public Member Functions | Public Attributes | Private Attributes | Static Private Attributes

ConfigToolBase::ConfigToolBase Class Reference

List of all members.

Public Member Functions

def __call__
def __copy__
 __copy__(self) returns a copy of the tool
def __init__
def addParameter
 use addParameter method in the redefinition of tool constructor in order to add parameters to the tools each tool is defined by its label, default value, description, type and allowedValues (the last two attribute can be ignored if the user gives a valid default values and if there is not a list of allowed values)
def apply
def comment
def description
def dumpPython
def errorMessage
def getAllowedValues
def getParameters
def getvalue
def isAllowed
 method isAllowed is called by setParameter to check input values for a specific parameter
def reset
def setComment
def setParameter
def setParameters
def toolCode
def typeError
 check about input value type

Public Attributes

 parAccepted

Private Attributes

 _comment
 _description
 _parameters
 _path

Static Private Attributes

string _defaultValue = "No default value. Set parameter value."
string _label = "ConfigToolBase"
string _path = ""

Detailed Description

Base class for PAT tools

Definition at line 33 of file ConfigToolBase.py.


Constructor & Destructor Documentation

def ConfigToolBase::ConfigToolBase::__init__ (   self)

Definition at line 40 of file ConfigToolBase.py.

00041                       :
00042         self._parameters=dicttypes.SortedKeysDict()
00043         self._description=self.__doc__
00044         self._comment = ''
00045         self.parAccepted=True
00046         saveOrigin(self,1)
00047         self._path = path.realpath(self._filename)        
00048         self._path = self._path.split("/src/")
00049         self._path = self._path[1].replace("/python","")
00050         #self._path = "".join(self._path)
00051         self._path = self._path.replace("/",".")
00052         self._path = self._path.replace(".py","")
00053 


Member Function Documentation

def ConfigToolBase::ConfigToolBase::__call__ (   self,
  process 
)
Call the instance 

Definition at line 54 of file ConfigToolBase.py.

00055                               :
00056         """ Call the instance 
00057         """
00058         raise NotImplementedError
    
def ConfigToolBase::ConfigToolBase::__copy__ (   self)

__copy__(self) returns a copy of the tool

Definition at line 83 of file ConfigToolBase.py.

00084                       :
00085         c=type(self)()
00086         c.setParameters(copy.deepcopy(self._parameters))
00087         c.setComment(self._comment)
        return c
def ConfigToolBase::ConfigToolBase::addParameter (   self,
  dict,
  parname,
  parvalue,
  description,
  Type = None,
  allowedValues = None,
  acceptNoneValue = False 
)

use addParameter method in the redefinition of tool constructor in order to add parameters to the tools each tool is defined by its label, default value, description, type and allowedValues (the last two attribute can be ignored if the user gives a valid default values and if there is not a list of allowed values)

Add a parameter with its label, value, description and type to self._parameters

Definition at line 102 of file ConfigToolBase.py.

00103                                                                                                                    :
00104         """ Add a parameter with its label, value, description and type to self._parameters
00105         """
00106         par=parameter()
00107         par.name=parname
00108         par.value=parvalue
00109         par.description=description
00110         if Type==None:
00111             par.type=type(parvalue)
00112         else: par.type=Type
00113         par.allowedValues=allowedValues
00114         par.acceptNoneValue=acceptNoneValue
        dict[par.name]=par        
def ConfigToolBase::ConfigToolBase::apply (   self,
  process 
)

Definition at line 59 of file ConfigToolBase.py.

00060                            :
00061         
00062         if hasattr(process, "addAction"):
00063             process.disableRecording()
00064             
00065         try:
00066             comment=inspect.stack(2)[2][4][0].rstrip("\n")
00067             if comment.startswith("#"):
00068                 self.setComment(comment.lstrip("#"))
00069         except:
00070             pass
00071             
00072         self.toolCode(process)
00073         
00074         if hasattr(process, "addAction"):
00075             process.enableRecording()
00076             action=self.__copy__()
00077             process.addAction(action)
            
def ConfigToolBase::ConfigToolBase::comment (   self)
Return the comment set for this tool

Definition at line 157 of file ConfigToolBase.py.

00158                      :
00159         """ Return the comment set for this tool
00160         """
        return self._comment
def ConfigToolBase::ConfigToolBase::description (   self)
Return a string with a detailed description of the action.

Definition at line 94 of file ConfigToolBase.py.

00095                          :
00096         """ Return a string with a detailed description of the action.
00097         """
00098         return self._description
    
def ConfigToolBase::ConfigToolBase::dumpPython (   self)
Return the python code to perform the action

Definition at line 134 of file ConfigToolBase.py.

00135                         :
00136         """ Return the python code to perform the action
00137         """ 
00138         dumpPythonImport = "\nfrom "+self._path+" import *\n"
00139         dumpPython=''
00140         if self._comment!="":
00141             dumpPython = '#'+self._comment
00142         dumpPython += "\n"+self._label+"(process "
00143         for key in self._parameters.keys():
00144           if str(self._parameters[key].value)!=str(self._defaultParameters[key].value):
00145             dumpPython+= ", "+str(key)+" = "
00146             if self._parameters[key].type is str:
00147                 string = "'"+str(self.getvalue(key))+"'"
00148             else:
00149                 string = str(self.getvalue(key))
00150             dumpPython+= string
00151         dumpPython+=")"+'\n'
00152         return (dumpPythonImport,dumpPython)
    
def ConfigToolBase::ConfigToolBase::errorMessage (   self,
  value,
  type 
)

Definition at line 161 of file ConfigToolBase.py.

00162                                      :
        return "The type for parameter "+'"'+str(value)+'"'+" is not "+'"'+str(type)+'"'
def ConfigToolBase::ConfigToolBase::getAllowedValues (   self,
  name 
)

Definition at line 192 of file ConfigToolBase.py.

00193                                    :
00194         return self._defaultParameters[name].allowedValues
def ConfigToolBase::ConfigToolBase::getParameters (   self)
Return a copy of the dict of the parameters.

Definition at line 115 of file ConfigToolBase.py.

00116                            :
00117         """ Return a copy of the dict of the parameters.
00118         """
        return copy.deepcopy(self._parameters)
def ConfigToolBase::ConfigToolBase::getvalue (   self,
  name 
)
Return the value of parameter 'name'

Definition at line 90 of file ConfigToolBase.py.

00091                            :
00092         """ Return the value of parameter 'name'
00093         """
        return self._parameters[name].value
def ConfigToolBase::ConfigToolBase::isAllowed (   self,
  name,
  value 
)

method isAllowed is called by setParameter to check input values for a specific parameter

Definition at line 164 of file ConfigToolBase.py.

00165                                   :
00166         self.parAccepted=True
00167         if value==[]:
00168             self.parAccepted=False
00169         elif (isinstance(value,dict)) and (isinstance(self._parameters[name].allowedValues,list)):
00170             for key in value.keys():
00171                 if (key not in self._parameters[name].allowedValues):
00172                     raise ValueError("The input key value "+'"'+str(key)+'"'+" for parameter "+'"'+name+'"'+" is not supported. Supported ones are: "+str(self._parameters[name].allowedValues))
00173         elif (isinstance(value,list)) and (isinstance(self._parameters[name].allowedValues,list )):
00174             for i in value:
00175                 if (i not in self._parameters[name].allowedValues) :
00176                     self.parAccepted=False
00177         elif (not isinstance(value,list))and (isinstance(self._parameters[name].allowedValues,list)) :
00178             if (value not in self._parameters[name].allowedValues and value == None) and (not self._parameters[name].acceptNoneValue) :
00179                 self.parAccepted=False
00180         elif not isinstance(self._parameters[name].allowedValues,list):
00181             if (value!=self._parameters[name].allowedValues and value == None) and (not self._parameters[name].acceptNoneValue) :
00182                 self.parAccepted=False  
00183         if self.parAccepted==False:
            raise ValueError("The input value "+'"'+str(value)+'"'+" for parameter "+'"'+name+'"'+" is not supported. Supported ones are: "+str(self._parameters[name].allowedValues)[1:-1])
def ConfigToolBase::ConfigToolBase::reset (   self)

Definition at line 88 of file ConfigToolBase.py.

00089                    :
        self._parameters=copy.deepcopy(self._defaultParameters)
def ConfigToolBase::ConfigToolBase::setComment (   self,
  comment 
)
Write a comment in the configuration file

Definition at line 153 of file ConfigToolBase.py.

00154                                  :
00155         """ Write a comment in the configuration file
00156         """
        self._comment = str(comment)
def ConfigToolBase::ConfigToolBase::setParameter (   self,
  name,
  value,
  typeNone = False 
)
Change parameter 'name' to a new value

Definition at line 119 of file ConfigToolBase.py.

00120                                                        :
00121         """ Change parameter 'name' to a new value
00122         """
00123         self._parameters[name].value=value
00124         ### check about input value type 
00125         self.typeError(name)
00126         ### check about input value (it works if allowedValues for the specific parameter is set)
        if self._defaultParameters[name].allowedValues is not None: self.isAllowed(name,value )
def ConfigToolBase::ConfigToolBase::setParameters (   self,
  parameters 
)

Definition at line 127 of file ConfigToolBase.py.

00128                                        :
        self._parameters=copy.deepcopy(parameters)
def ConfigToolBase::ConfigToolBase::toolCode (   self,
  process 
)

Definition at line 78 of file ConfigToolBase.py.

00079                                :
00080         raise NotImplementedError
00081 
            
def ConfigToolBase::ConfigToolBase::typeError (   self,
  name 
)

check about input value type

Definition at line 185 of file ConfigToolBase.py.

00186                             :
00187         if self._parameters[name].acceptNoneValue is False:
00188             if not isinstance(self._parameters[name].value,self._parameters[name].type):
00189                 raise TypeError(self.errorMessage(self._parameters[name].value,self._parameters[name].type))
00190         else:
00191             if not (isinstance(self._parameters[name].value,self._parameters[name].type) or self._parameters[name].value is  None):
                raise TypeError(self.errorMessage(self._parameters[name].value,self._parameters[name].type))

Member Data Documentation

Definition at line 40 of file ConfigToolBase.py.

string ConfigToolBase::ConfigToolBase::_defaultValue = "No default value. Set parameter value." [static, private]

Definition at line 38 of file ConfigToolBase.py.

Definition at line 40 of file ConfigToolBase.py.

string ConfigToolBase::ConfigToolBase::_label = "ConfigToolBase" [static, private]

Definition at line 37 of file ConfigToolBase.py.

Definition at line 40 of file ConfigToolBase.py.

string ConfigToolBase::ConfigToolBase::_path = "" [static, private]

Definition at line 39 of file ConfigToolBase.py.

Definition at line 40 of file ConfigToolBase.py.

Definition at line 40 of file ConfigToolBase.py.