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

Source Code for Module PyFoam.Infrastructure.Configuration

  1  #  ICE Revision: $Id: Configuration.py 8171 2007-11-12 08:57:33Z 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","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      } 
 53   
54 -class Configuration(ConfigParser):
55 """Reads the settings from files (if existing). Otherwise uses hardcoded 56 defaults""" 57
58 - def __init__(self):
59 """Constructs the ConfigParser and fills it with the hardcoded defaults""" 60 ConfigParser.__init__(self) 61 62 for section,content in _defaults.iteritems(): 63 self.add_section(section) 64 for key,value in content.iteritems(): 65 self.set(section,key,value) 66 67 self.read([globalConfigFile(),userConfigFile()])
68
69 - def dump(self):
70 """Dumps the contents in INI-Form 71 @return: a string with the contents""" 72 result="" 73 for section in self.sections(): 74 result+="[%s]\n" % (section) 75 for key,value in self.items(section): 76 result+="%s: %s\n" % (key,value) 77 result+="\n" 78 79 return result
80
81 - def getboolean(self,section,option,default=None):
82 """Overrides the original implementation from ConfigParser 83 @param section: the section 84 @param option: the option 85 @param default: if set and the option is not found, then this value is used""" 86 87 try: 88 return ConfigParser.getboolean(self,section,option) 89 except NoOptionError: 90 if default!=None: 91 return default 92 else: 93 raise
94
95 - def get(self,section,option,default=None):
96 """Overrides the original implementation from ConfigParser 97 @param section: the section 98 @param option: the option 99 @param default: if set and the option is not found, then this value is used""" 100 101 try: 102 return ConfigParser.get(self,section,option) 103 except NoOptionError: 104 if default!=None: 105 return default 106 else: 107 raise
108
109 - def getdebug(self,name):
110 """Gets a debug switch""" 111 112 return self.getboolean("Debug",name,default=False)
113