Inherited by objects.logic.configuration.displayConfigurator.displayConfigurator, and objects.logic.configuration.optionsConfigurator.optionsConfigurator.
Public Member Functions | |
| def | __init__ |
| def | loadConfig |
| Load the configuration file specified in the constructor. | |
| def | getConfigValue |
| helper "get" function which fetches some configuration item from the INI file. | |
| def | getSection |
| Retrieves an entire section as returns it as a list of section variables. | |
| def | setConfigValue |
| Helper function used to set a configuration value. | |
| def | writeFmat |
| This helper function will replace all empty strings with a special token. | |
| def | readFmat |
Public Attributes | |
| config | |
| lck | |
| configFileName | |
This class is essentially a Wrapper to the existing python SafeConfiguratorParser class, which is a simple interface to an INI file. Note that this class is implemented as thread safe.
Definition at line 27 of file configurator.py.
| def objects.logic.configuration.configurator.configurator.__init__ | ( | self, | ||
| configFileName | ||||
| ) |
Definition at line 28 of file configurator.py.
00028 : 00029 self.config = ConfigParser.SafeConfigParser() 00030 self.lck = RLock() 00031 00032 self.configFileName = configFileName 00033 00034 ## Load the configuration file specified in the constructor
| def objects.logic.configuration.configurator.configurator.getConfigValue | ( | self, | ||
| section, | ||||
| option, | ||||
| default, | ||||
| setIfNotFound | ||||
| ) |
helper "get" function which fetches some configuration item from the INI file.
| section | INI file Section name [SECTION].... | |
| option | INI file variable name | |
| default | default value (if not found) | |
| setIfNotFound | If True, this parameter will be written to the INI file using the default value if not found |
Definition at line 59 of file configurator.py.
00059 : 00060 00061 self.lck.acquire(1) 00062 try: 00063 return self.readFmat(self.config.get(section, option)) 00064 00065 except Exception, getError: 00066 errMsg = "Could not retrieve [%s]==>%s: %s" % (section, option, getError) 00067 logger.log(__name__ + errMsg ) 00068 00069 if setIfNotFound == True: 00070 # attempt to write that option back to the config file 00071 fileFp = None 00072 00073 try: 00074 fileFp = open(self.configFileName, 'w') 00075 00076 logger.log(__name__ + ": Writing default value back to configuration file" ) 00077 00078 self.setConfigValue(section, option, self.writeFmat(str(default))) 00079 #self.config.set(section, option, self.writeFmat(str(default))) 00080 #self.config.write(fileFp) 00081 00082 except Exception, setError: 00083 errMsg = ": Could not write default setting back to file: %s" % (setError) 00084 logger.log(__name__ + errMsg ) 00085 00086 finally: 00087 if fileFp != None: fileFp.close() 00088 # since there was an error, return the default value 00089 return self.readFmat(default) 00090 finally: 00091 self.lck.release() 00092 00093 ## Retrieves an entire section as returns it as a list of section variables
| def objects.logic.configuration.configurator.configurator.getSection | ( | self, | ||
| section | ||||
| ) |
Retrieves an entire section as returns it as a list of section variables.
| section | Section name |
Definition at line 96 of file configurator.py.
00096 : 00097 try: 00098 self.lck.acquire(1) 00099 return self.config.items(section) 00100 except ConfigParser.NoSectionError: 00101 logger.log(__name__ + ": There was an error Retrieving ini file section") 00102 logger.log(section) 00103 logger.log(__name__ + ": Section will be added") 00104 00105 try: 00106 self.config.add_section(section) 00107 except Exception: 00108 logger.log(__name__ + ": Holy !@#$%. I can't even add the section. I give up") 00109 finally: 00110 return [] 00111 00112 00113 finally: 00114 self.lck.release() 00115 00116
| def objects.logic.configuration.configurator.configurator.loadConfig | ( | self | ) |
Load the configuration file specified in the constructor.
Definition at line 36 of file configurator.py.
00036 : 00037 fileFp = None 00038 00039 self.lck.acquire(1) 00040 try: 00041 fileFp = open(self.configFileName) 00042 self.config.readfp(fileFp) 00043 except Exception, data: 00044 logger.log(__name__ + "There was an error reading: " + self.configFileName) 00045 logger.log(data) 00046 00047 raise Exception, data 00048 finally: 00049 self.lck.release() 00050 if fileFp != None: fileFp.close() 00051 00052 00053 ## helper "get" function which fetches some configuration item from the INI file.
| def objects.logic.configuration.configurator.configurator.readFmat | ( | self, | ||
| str | ||||
| ) |
Definition at line 162 of file configurator.py.
00162 : 00163 if str == "__None__": 00164 return ""; 00165 else: 00166 return str 00167 00168 00169 00170 00171
| def objects.logic.configuration.configurator.configurator.setConfigValue | ( | self, | ||
| section, | ||||
| option, | ||||
| value | ||||
| ) |
Helper function used to set a configuration value.
| section | INI File Section Name | |
| option | INI file variable name | |
| value | INI file variable value |
Definition at line 121 of file configurator.py.
00121 : 00122 try: 00123 self.lck.acquire(1) 00124 fileFp = open(self.configFileName, 'w') 00125 00126 try: 00127 self.config.add_section(section) 00128 except Exception: 00129 # i really don't care if this happens 00130 pass 00131 00132 #logger.log(__name__ + ": Writing display setting option back to configuration file" ) 00133 self.config.set(section, option, self.writeFmat(str(value))) 00134 00135 self.config.write(fileFp) 00136 00137 except Exception, setError: 00138 errMsg = ": Could not write display setting option to file: %s" % (setError) 00139 raise exception(setError, False) 00140 logger.log(__name__ + errMsg ) 00141 00142 finally: 00143 if fileFp != None: fileFp.close() 00144 self.lck.release() 00145 00146 00147 ## This helper function will replace all empty strings with a special token.
| def objects.logic.configuration.configurator.configurator.writeFmat | ( | self, | ||
| str | ||||
| ) |
This helper function will replace all empty strings with a special token.
Although the application may want to save an empty string as part of its configuration, doing so will it will break the integrity of the INI file and make it unparsable later.
| str | String to format |
Definition at line 152 of file configurator.py.
00152 : 00153 if str == None or str == "" or str == "None": 00154 return "__None__" 00155 else: 00156 return str 00157 00158 # this function will take any specially formatted token strings from the INI files 00159 # and replace them with a a corresponding empty strings. This is done because because empty 00160 # strings cannot be physically written into the INI file 00161 # @param str String to convert def readFmat(self, str):
Definition at line 29 of file configurator.py.
Definition at line 32 of file configurator.py.
Definition at line 30 of file configurator.py.
1.5.8