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 "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
40
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
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
77 """Reads the settings from files (if existing). Otherwise uses hardcoded
78 defaults"""
79
90
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
146 """Gets a debug switch"""
147
148 return self.getboolean("Debug",name,default=False)
149