1 """Reads configuration-files that define defaults for various PyFoam-Settings
2
3 Also hardcodes defaults for the settings"""
4
5 from ConfigParser import ConfigParser
6
7 from Hardcoded import globalConfigFile,userConfigFile
8
9 _defaults={
10 "Network": {
11 "startServerPort" : "18000",
12 "nrServerPorts" : "100",
13 "searchServers" : "192.168.1.0/24,192.168.0.0/24",
14 "portWait" : "1.",
15 "socketTimeout" : "1.",
16 },
17 "Metaserver": {
18 "port" : "17999",
19 "ip" : "192.168.1.11",
20 "checkerSleeping" : "30.",
21 },
22 "IsAlive": {
23 "maxTimeStart" : "30.",
24 "isLivingMargin" : "1.1"
25 },
26 "Logging": {
27 "default" : "INFO",
28 "server" : "INFO",
29 }
30 }
31
33 """Reads the settings from files (if existing). Otherwise uses hardcoded
34 defaults"""
35
37 """Constructs the ConfigParser and fills it with the hardcoded defaults"""
38 ConfigParser.__init__(self)
39
40 for section,content in _defaults.iteritems():
41 self.add_section(section)
42 for key,value in content.iteritems():
43 self.set(section,key,value)
44
45 self.read([globalConfigFile(),userConfigFile()])
46
48 """Dumps the contents in INI-Form
49 @return: a string with the contents"""
50 result=""
51 for section in self.sections():
52 result+="[%s]\n" % (section)
53 for key,value in self.items(section):
54 result+="%s: %s\n" % (key,value)
55 result+="\n"
56
57 return result
58