Update of /cvsroot/webware/Webware/MiscUtils
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21934/MiscUtils
Modified Files:
Configurable.py
Log Message:
* Configuration files can now be written as Python modules, where the
global variables are keys in the configuration dictionary. Old
configuration files are still supported.
* The default configuration files have updated with this new, more
pleasant syntax.
* MakeAppWorkDir.py and install.py parse the new configuration files.
* MakeAppWorkDir.py accepts a couple new options -- one to set the
default context's home directory, and another to add library directories
to the path (a generalization of the --library option).
Index: Configurable.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiscUtils/Configurable.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Configurable.py 12 Dec 2002 05:17:12 -0000 1.13
--- Configurable.py 26 May 2004 06:56:19 -0000 1.14
***************
*** 76,80 ****
def configFilename(self):
! """ Returns the filename by which users can override the configuration. Subclasses must override to specify a name. Returning None is valid, in which case no user config file will be loaded. """
raise AbstractError, self.__class__
--- 76,85 ----
def configFilename(self):
! """
! Returns the filename by which users can override the
! configuration. Subclasses must override to specify a
! name. Returning None is valid, in which case no user
! config file will be loaded."""
!
raise AbstractError, self.__class__
***************
*** 106,113 ****
else:
contents = file.read()
file.close()
modloader.watchFile(filename)
replacements = self.configReplacementValues()
! if replacements:
try:
contents = contents % replacements
--- 111,119 ----
else:
contents = file.read()
+ isDict = contents.strip().startswith('{')
file.close()
modloader.watchFile(filename)
replacements = self.configReplacementValues()
! if replacements and isDict:
try:
contents = contents % replacements
***************
*** 115,122 ****
raise ConfigurationError, 'Unable to embed replacement text in %s.' % self.configFilename()
try:
! config = eval(contents, {})
! except:
! raise ConfigurationError, 'Invalid configuration file, %s.' % self.configFilename()
if type(config) is not DictType:
raise ConfigurationError, 'Invalid type of configuration. Expecting dictionary, but got %s.' % type(config)
--- 121,138 ----
raise ConfigurationError, 'Unable to embed replacement text in %s.' % self.configFilename()
+ evalContext = replacements.copy()
+ evalContext['True'] = 1==1
+ evalContext['False'] = 1==0
try:
! if isDict:
! config = eval(contents, evalContext)
! else:
! exec contents in evalContext
! config = evalContext
! for name in config.keys():
! if name.startswith('_'):
! del config[name]
! except Exception, e:
! raise ConfigurationError, 'Invalid configuration file, %s (%s).' % (self.configFilename(), e)
if type(config) is not DictType:
raise ConfigurationError, 'Invalid type of configuration. Expecting dictionary, but got %s.' % type(config)
|