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

Source Code for Module PyFoam.Infrastructure.Configuration

  1  #  ICE Revision: $Id: Configuration.py 10020 2009-02-17 13:04:30Z 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      "socketRetries"    : "10", 
 20      }, 
 21      "Metaserver": { 
 22      "port"             : "17999", 
 23      "ip"               : "192.168.1.11", 
 24      "checkerSleeping"  : "30.", 
 25      }, 
 26      "IsAlive": { 
 27      "maxTimeStart"     : "30.", 
 28      "isLivingMargin"   : "1.1" 
 29      }, 
 30      "Logging": { 
 31      "default" : "INFO", 
 32      "server" : "INFO", 
 33      }, 
 34      "OpenFOAM": { 
 35      "Installation" : "~/OpenFOAM", 
 36      "Version" : "1.4.1", 
 37      }, 
 38      "MPI": { 
 39  #    "run_OPENMPI":"mpirun", 
 40  #    "run_LAM":"mpirun", 
 41      "options_OPENMPI_pre": '["--mca","pls","rsh","--mca","pls_rsh_agent","rsh"]', 
 42      "options_OPENMPI_post":'["-x","PATH","-x","LD_LIBRARY_PATH","-x","WM_PROJECT_DIR","-x","PYTHON_PATH","-x","FOAM_MPI_LIBBIN","-x","MPI_BUFFER_SIZE","-x","MPI_ARCH_PATH"]' 
 43      }, 
 44      "Paths": { 
 45      "python" : "/usr/bin/python", 
 46      "bash" : "/bin/bash", 
 47      }, 
 48      "ClusterJob": { 
 49      "useFoamMPI":'["1.5"]', 
 50      "path":"/opt/openmpi/bin", 
 51      "ldpath":"/opt/openmpi/lib", 
 52      }, 
 53      "Debug": { 
 54  #    "ParallelExecution":"True", 
 55      }, 
 56      "Execution":{ 
 57      "controlDictRestoreWait":"60.", 
 58      }, 
 59      "CaseBuilder":{ 
 60      "descriptionPath": eval('["'+path.curdir+'","'+path.join(userDirectory(),"caseBuilderDescriptions")+'","'+path.join(globalDirectory(),"caseBuilderDescriptions")+'"]'), 
 61      }, 
 62      "Formats":{ 
 63      "error"       : "bold,red,standout", 
 64      "warning"     : "under", 
 65      "source"      : "red,bold", 
 66      "destination" : "blue,bold", 
 67      "difference"  : "green,back_black,bold", 
 68      "question"    : "green,standout", 
 69      "input"       : "cyan,under", 
 70      }, 
 71      "CommandOptionDefaults":{ 
 72      "sortListCases":"mtime", 
 73      } 
 74      } 
 75   
76 -class Configuration(ConfigParser):
77 """Reads the settings from files (if existing). Otherwise uses hardcoded 78 defaults""" 79
80 - def __init__(self):
81 """Constructs the ConfigParser and fills it with the hardcoded defaults""" 82 ConfigParser.__init__(self) 83 84 for section,content in _defaults.iteritems(): 85 self.add_section(section) 86 for key,value in content.iteritems(): 87 self.set(section,key,value) 88 89 self.read([globalConfigFile(),userConfigFile()])
90
91 - def dump(self):
92 """Dumps the contents in INI-Form 93 @return: a string with the contents""" 94 result="" 95 for section in self.sections(): 96 result+="[%s]\n" % (section) 97 for key,value in self.items(section): 98 result+="%s: %s\n" % (key,value) 99 result+="\n" 100 101 return result
102
103 - def getboolean(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.getboolean(self,section,option) 111 except NoOptionError: 112 if default!=None: 113 return default 114 else: 115 raise
116
117 - def getfloat(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.getfloat(self,section,option) 125 except (NoOptionError,ValueError): 126 if default!=None: 127 return default 128 else: 129 raise
130
131 - def get(self,section,option,default=None):
132 """Overrides the original implementation from ConfigParser 133 @param section: the section 134 @param option: the option 135 @param default: if set and the option is not found, then this value is used""" 136 137 try: 138 return ConfigParser.get(self,section,option) 139 except NoOptionError: 140 if default!=None: 141 return default 142 else: 143 raise
144
145 - def getdebug(self,name):
146 """Gets a debug switch""" 147 148 return self.getboolean("Debug",name,default=False)
149