new_contents: import string
  import os.path
  
  ############################################################
  #
  # Configuration
  #
  ############################################################
  
  class FrontendConfig:
      def __init__(self):
          # set default values
          # user should modify if needed
  
          self.frontend_descript_file = "frontend.descript"
          self.group_descript_file = "group.descript"
          self.params_descript_file = "params_const.cfg"
          self.exprs_descript_file = "params_expr.cfg"
  
  # global configuration of the module
  frontendConfig=FrontendConfig()
  
  
  ############################################################
  #
  # Generic Class
  # You most probably don't want to use these
  #
  ############################################################
  
  # loads a file composed of
  #   NAME VAL
  # and creates
  #   self.data[NAME]=VAL
  # It also defines:
  #   self.config_file="name of file"
  class ConfigFile:
      def __init__(self,config_file,convert_function=repr):
          self.config_file=config_file
          self.load(config_file,convert_function)
  
      def load(self,fname,convert_function):
          self.data={}
          fd=open(fname,"r")
          try:
              lines=fd.readlines()
              for line in lines:
                  if line[0]=="#":
                      continue # comment
                  if len(string.strip(line))==0:
                      continue # empty line
                  larr=string.split(line,None,1)
                  lname=larr[0]
                  if len(larr)==1:
                      lval=""
                  else:
                      lval=larr[1][:-1] #strip newline
                  exec("self.data['%s']=%s"%(lname,convert_function(lval)))
          finally:
              fd.close()
  
  # load from the group subdir
  class GroupConfigFile(ConfigFile):
      def __init__(self,group_name,config_file,convert_function=repr):
          ConfigFile.__init__(self,os.path.join("group_"+group_name,config_file),convert_function)
          self.group_name=group_name
          self.config_file_short=config_file
  
  # load both the main and group subdir config file
  # and join the results
  class JoinConfigFile(ConfigFile):
      def __init__(self,group_name,config_file,convert_function=repr):
          ConfigFile.__init__(self,config_file,convert_function)
          self.group_name=group_name
          group_obj=GroupConfigFile(group_name,config_file,convert_function)
          #merge by overriding whatever is found in the subdir
          for k in group_obj.data.keys():
              self.data[k]=group_obj.data[k]
  
  ############################################################
  #
  # Configuration
  #
  ############################################################
  
  class FrontendDescript(ConfigFile):
      def __init__(self):
          global frontendConfig
          ConfigFile.__init__(self,frontendConfig.frontend_descript_file,
                              repr) # convert everything in strings
  
  class ElementDescript(GroupConfigFile):
      def __init__(self,group_name):
          global frontendConfig
          GroupConfigFile.__init__(self,group_name,frontendConfig.group_descript_file,
                                   repr) # convert everything in strings
  
  class ParamsDescript(JoinConfigFile):
      def __init__(self,group_name):
          global frontendConfig
          JoinConfigFile.__init__(self,group_name,frontendConfig.params_descript_file,
                                  lambda s:s) # values are in python format
  
  class ExprsDescript(JoinConfigFile):
      def __init__(self,group_name):
          global frontendConfig
          JoinConfigFile.__init__(self,group_name,frontendConfig.exprs_descript_file,
                                  lambda s:s) # values are in python format
  
  
  
  
subject: Read configuration files