Package PyFoam :: Package Infrastructure :: Module Configuration
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Infrastructure.Configuration

  1  #  ICE Revision: $Id: Configuration.py 8948 2008-06-05 15:23:51Z bgschaid $  
  2  """Reads configuration-files that define defaults for various PyFoam-Settings 
  3   
  4  Also hardcodes defaults for the settings""" 
  5   
  6  from ConfigParser import ConfigParser,NoOptionError 
  7   
  8  from Hardcoded import globalConfigFile,userConfigFile 
  9   
 10  _defaults={ 
 11      "Network": { 
 12      "startServerPort"  : "18000", 
 13      "nrServerPorts"    : "100", 
 14      "searchServers"    : "192.168.1.0/24,192.168.0.0/24", 
 15      "portWait"         : "1.", 
 16      "socketTimeout"    : "1.", 
 17      }, 
 18      "Metaserver": { 
 19      "port"             : "17999", 
 20      "ip"               : "192.168.1.11", 
 21      "checkerSleeping"  : "30.", 
 22      }, 
 23      "IsAlive": { 
 24      "maxTimeStart"     : "30.", 
 25      "isLivingMargin"   : "1.1" 
 26      }, 
 27      "Logging": { 
 28      "default" : "INFO", 
 29      "server" : "INFO", 
 30      }, 
 31      "OpenFOAM": { 
 32      "Installation" : "~/OpenFOAM", 
 33      "Version" : "1.4.1", 
 34      }, 
 35      "MPI": { 
 36  #    "run_OPENMPI":"mpirun", 
 37  #    "run_LAM":"mpirun", 
 38      "options_OPENMPI_pre":'["--mca","pls_rsh_agent","rsh"]', 
 39      "options_OPENMPI_post":'["-x","PATH","-x","LD_LIBRARY_PATH","-x","WM_PROJECT_DIR","-x","FOAM_MPI_LIBBIN","-x","MPI_BUFFER_SIZE"]' 
 40      }, 
 41      "Paths": { 
 42      "python" : "/usr/bin/python", 
 43      "bash" : "/bin/bash", 
 44      }, 
 45      "ClusterJob": { 
 46      "path":"/opt/openmpi/bin", 
 47      "ldpath":"/opt/openmpi/lib", 
 48      }, 
 49      "Debug": { 
 50  #     "ParallelExecution":"True", 
 51      }, 
 52      "Execution":{ 
 53      "controlDictRestoreWait":"60.", 
 54      }, 
 55      } 
 56   
57 -class Configuration(ConfigParser):
58 """Reads the settings from files (if existing). Otherwise uses hardcoded 59 defaults""" 60
61 - def __init__(self):
62 """Constructs the ConfigParser and fills it with the hardcoded defaults""" 63 ConfigParser.__init__(self) 64 65 for section,content in _defaults.iteritems(): 66 self.add_section(section) 67 for key,value in content.iteritems(): 68 self.set(section,key,value) 69 70 self.read([globalConfigFile(),userConfigFile()])
71
72 - def dump(self):
73 """Dumps the contents in INI-Form 74 @return: a string with the contents""" 75 result="" 76 for section in self.sections(): 77 result+="[%s]\n" % (section) 78 for key,value in self.items(section): 79 result+="%s: %s\n" % (key,value) 80 result+="\n" 81 82 return result
83
84 - def getboolean(self,section,option,default=None):
85 """Overrides the original implementation from ConfigParser 86 @param section: the section 87 @param option: the option 88 @param default: if set and the option is not found, then this value is used""" 89 90 try: 91 return ConfigParser.getboolean(self,section,option) 92 except NoOptionError: 93 if default!=None: 94 return default 95 else: 96 raise
97
98 - def getfloat(self,section,option,default=None):
99 """Overrides the original implementation from ConfigParser 100 @param section: the section 101 @param option: the option 102 @param default: if set and the option is not found, then this value is used""" 103 104 try: 105 return ConfigParser.getfloat(self,section,option) 106 except (NoOptionError,ValueError): 107 if default!=None: 108 return default 109 else: 110 raise
111
112 - def get(self,section,option,default=None):
113 """Overrides the original implementation from ConfigParser 114 @param section: the section 115 @param option: the option 116 @param default: if set and the option is not found, then this value is used""" 117 118 try: 119 return ConfigParser.get(self,section,option) 120 except NoOptionError: 121 if default!=None: 122 return default 123 else: 124 raise
125
126 - def getdebug(self,name):
127 """Gets a debug switch""" 128 129 return self.getboolean("Debug",name,default=False)
130