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

Source Code for Module PyFoam.Infrastructure.Configuration

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