1
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 "portWait" : "1.",
17 "socketTimeout" : "1.",
18 "socketRetries" : "10",
19 },
20 "Metaserver": {
21 "port" : "17999",
22 "ip" : "192.168.1.11",
23 "checkerSleeping" : "30.",
24 "searchServers" : "192.168.1.0/24,192.168.0.0/24",
25 "webhost" : "127.0.0.1:9000",
26 "doWebsync" : "True",
27 "websyncInterval" : "300.",
28 },
29 "IsAlive": {
30 "maxTimeStart" : "30.",
31 "isLivingMargin" : "1.1"
32 },
33 "Logging": {
34 "default" : "INFO",
35 "server" : "INFO",
36 },
37 "OpenFOAM": {
38 "Installation" : "~/OpenFOAM",
39 "Version" : "1.4.1",
40 },
41 "MPI": {
42
43
44 "options_OPENMPI_pre": '["--mca","pls","rsh","--mca","pls_rsh_agent","rsh"]',
45 "options_OPENMPI_post":'["-x","PATH","-x","LD_LIBRARY_PATH","-x","WM_PROJECT_DIR","-x","PYTHONPATH","-x","FOAM_MPI_LIBBIN","-x","MPI_BUFFER_SIZE","-x","MPI_ARCH_PATH"]'
46 },
47 "Paths": {
48 "python" : "/usr/bin/python",
49 "bash" : "/bin/bash",
50 },
51 "ClusterJob": {
52 "useFoamMPI":'["1.5"]',
53 "path":"/opt/openmpi/bin",
54 "ldpath":"/opt/openmpi/lib",
55 },
56 "Debug": {
57
58 },
59 "Execution":{
60 "controlDictRestoreWait":"60.",
61 },
62 "CaseBuilder":{
63 "descriptionPath": eval('["'+path.curdir+'","'+path.join(userDirectory(),"caseBuilderDescriptions")+'","'+path.join(globalDirectory(),"caseBuilderDescriptions")+'"]'),
64 },
65 "Formats":{
66 "error" : "bold,red,standout",
67 "warning" : "under",
68 "source" : "red,bold",
69 "destination" : "blue,bold",
70 "difference" : "green,back_black,bold",
71 "question" : "green,standout",
72 "input" : "cyan,under",
73 },
74 "CommandOptionDefaults":{
75 "sortListCases":"mtime",
76 },
77 "Plotting":{
78 "preferredImplementation":"gnuplot",
79 },
80 "OutfileCollection": {
81 "maximumOpenFiles":"100",
82 },
83 }
84
86 """Reads the settings from files (if existing). Otherwise uses hardcoded
87 defaults"""
88
99
101 """Dumps the contents in INI-Form
102 @return: a string with the contents"""
103 result=""
104 for section in self.sections():
105 result+="[%s]\n" % (section)
106 for key,value in self.items(section):
107 result+="%s: %s\n" % (key,value)
108 result+="\n"
109
110 return result
111
112 - def getboolean(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.getboolean(self,section,option)
120 except NoOptionError:
121 if default!=None:
122 return default
123 else:
124 raise
125
126 - def getfloat(self,section,option,default=None):
127 """Overrides the original implementation from ConfigParser
128 @param section: the section
129 @param option: the option
130 @param default: if set and the option is not found, then this value is used"""
131
132 try:
133 return ConfigParser.getfloat(self,section,option)
134 except (NoOptionError,ValueError):
135 if default!=None:
136 return default
137 else:
138 raise
139
140 - def get(self,section,option,default=None):
141 """Overrides the original implementation from ConfigParser
142 @param section: the section
143 @param option: the option
144 @param default: if set and the option is not found, then this value is used"""
145
146 try:
147 return ConfigParser.get(self,section,option)
148 except NoOptionError:
149 if default!=None:
150 return default
151 else:
152 raise
153
155 """Gets a debug switch"""
156
157 return self.getboolean("Debug",name,default=False)
158