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