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 = "" |
Base class for PAT tools
Definition at line 33 of file ConfigToolBase.py.
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
def ConfigToolBase::ConfigToolBase::__call__ | ( | self, | |
process | |||
) |
Call the instance
Definition at line 54 of file ConfigToolBase.py.
def ConfigToolBase::ConfigToolBase::__copy__ | ( | self | ) |
__copy__(self) returns a copy of the tool
Definition at line 83 of file ConfigToolBase.py.
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.
def ConfigToolBase::ConfigToolBase::description | ( | self | ) |
Return a string with a detailed description of the action.
Definition at line 94 of file ConfigToolBase.py.
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.
def ConfigToolBase::ConfigToolBase::getAllowedValues | ( | self, | |
name | |||
) |
Definition at line 192 of file ConfigToolBase.py.
def ConfigToolBase::ConfigToolBase::getParameters | ( | self | ) |
Return a copy of the dict of the parameters.
Definition at line 115 of file ConfigToolBase.py.
def ConfigToolBase::ConfigToolBase::getvalue | ( | self, | |
name | |||
) |
Return the value of parameter 'name'
Definition at line 90 of file ConfigToolBase.py.
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.
def ConfigToolBase::ConfigToolBase::setComment | ( | self, | |
comment | |||
) |
Write a comment in the configuration file
Definition at line 153 of file ConfigToolBase.py.
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.
def ConfigToolBase::ConfigToolBase::toolCode | ( | self, | |
process | |||
) |
Definition at line 78 of file ConfigToolBase.py.
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))
ConfigToolBase::ConfigToolBase::_comment [private] |
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.
ConfigToolBase::ConfigToolBase::_path [private] |
Definition at line 40 of file ConfigToolBase.py.
Definition at line 40 of file ConfigToolBase.py.