def _readFile(self, filePath): if os.path.exists(filePath): if os.path.isfile(filePath): try: logging.debug('evaluating %s', filePath) result = {} allSymbols = FastScript.execFile(filePath) # remove Python modules, callables etc. from dict for key, value in allSymbols.items(): if Any.isTextNonEmpty(key): result[key] = value except (AssertionError, IOError, OSError) as e: logging.error(e) result = {} else: logging.error('%s: Not a regular file', filePath) result = {} else: # logging.debug( '%s: No such file', filePath ) result = {} return result
def getConfigOptions(addPaths=None): """ Returns a dict with all config options and their values. The master-list of available config options is defined in etc/ToolBOS.conf (the fallback list shipped with ToolBOS SDK). To search in non-standard locations provide a list 'addPaths'. Its path entries will be searched right after ./ToolBOS.conf. """ allSymbols = {} # do in reverse order (starting from default), and update step-by-step # with the higher-priority settings order = _getEvalOrder(addPaths) order.reverse() for fileName in order: try: fileSymbols = FastScript.execFile(fileName) logging.debug('evaluating %s', fileName) except (AssertionError, IOError, OSError): fileSymbols = {} allSymbols.update(fileSymbols) # remove Python modules, callables etc. from dict result = {} for key, value in allSymbols.items(): if Any.isTextNonEmpty(key) and not Any.isCallable(value): result[key] = value return result
def _getConfigOptionFromFile(varName, fileName): """ This function attempts to find a variable 'varName' defined in the file 'fileName'. """ Any.requireIsTextNonEmpty(varName) Any.requireIsFileNonEmpty(fileName) value = FastScript.execFile(fileName)[varName] return value
def getUserConfigOptions( self ): """ Returns a dict with the settings from the user's configfile (if any). Unlike getConfigOptions() it does not look-up all the other files like in the current working directory or the system-wide or default configs. """ # read current settings (if any) try: config = FastScript.execFile( self._userConfPath ) except IOError as e: # no such file logging.info( e ) config = {} return config
def getUserConfigOptions(): """ Returns a dict with the settings from the user's configfile (if any). Unlike getConfigOptions() it does not look-up all the other files like in the current working directory or the system-wide or default configs. """ fileName = getSettingsFile_user() # read current settings (if any) try: config = FastScript.execFile(fileName) except IOError: # no such file config = {} return config