/[glsr]/trunk/harmonious/_config.py
Gentoo

Contents of /trunk/harmonious/_config.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 109 - (show annotations) (download) (as text)
Mon Aug 1 14:40:49 2005 UTC (9 years ago) by port001
File MIME type: text/x-python
File size: 4605 byte(s)
Added a 'flush2disk' mode to the SessionStorage class which pickles session data to disk when shut down, and unpickles it on startup.

1 __id__ = '$Id$'
2 __modulename__ = 'Config'
3
4 import sys
5 import ConfigParser
6
7 class Config:
8
9 def __init__(self, file):
10
11 self.__file = file
12
13 self.server = {}
14 self.session = {}
15 self.hosts = {}
16 self.logging = {}
17
18 def _read_config(self):
19
20 config = ConfigParser.ConfigParser()
21 config.readfp(open(self.__file))
22
23 if config.has_section('Server'):
24
25 if config.has_option('Server', 'SecretKey'):
26 self.server['SecretKey'] = config.get('Server', 'SecretKey')
27 if config.has_option('Server', 'Host'):
28 self.server['Host'] = config.get('Server', 'Host')
29 if config.has_option('Server', 'Port'):
30 self.server['Port'] = int(config.get('Server', 'Port'))
31 if config.has_option('Server', 'Debug'):
32 if config.get('Server', 'debug').lower() == 'true':
33 self.server['Debug'] = True
34 else:
35 self.server['Debug'] = False
36 else:
37 self.server['Debug'] = False
38 if config.has_option('Server', 'MinThreads'):
39 self.server['MinThreads'] = config.get('Server', 'MinThreads')
40
41 if config.has_section('Logging'):
42
43 if config.has_option('Logging', 'AccessLog'):
44 self.logging['AccessLog'] = config.get('Logging', 'AccessLog')
45 else:
46 self.logging['AccessLog'] = '/var/log/harmonious/access.log'
47
48 if config.has_option('Logging', 'ErrorLog'):
49 self.logging['ErrorLog'] = config.get('Logging', 'ErrorLog')
50 else:
51 self.logging['ErrorLog'] = '/var/log/harmonious/error.log'
52
53 if config.has_section('Session'):
54
55 if config.has_option('Session', 'SessionEnable'):
56 if config.get('Session', 'SessionEnable').lower() in ['true', 'yes']:
57 self.session['SessionEnable'] = True
58 else:
59 self.session['SessionEnable'] = False
60
61 if config.has_option('Session', 'StorageType'):
62 self.session['StorageType'] = config.get('Session', 'StorageType').lower()
63 else:
64 self.session['StorageType'] = 'ram'
65
66 if config.has_option('Session', 'CookieName'):
67 self.session['CookieName'] = config.get('Session', 'CookieName')
68 else:
69 self.session['CookieName'] = 'HarmoniousSession'
70
71 if config.has_option('Session', 'Timeout'):
72 self.session['Timeout'] = int(config.get('Session', 'Timeout'))
73 else:
74 self.session['Timeout'] = 60
75
76 if config.has_option('Session', 'StoreDir'):
77 self.session['StoreDir'] = config.get('Session', 'StoreDir')
78
79 else:
80 self.session['SessionEnable'] = False
81
82 # Load virtual hosts
83 for section in config.sections():
84
85 if len(section) > 12:
86 if section[0:12] == 'VirtualHost:':
87 self.hosts[section[12:].lower()] = {}
88 if config.has_option(section, 'DocumentRoot'):
89
90 self.hosts[section[12:].lower()]['DocumentRoot'] = config.get(section, 'DocumentRoot').rstrip('/')
91
92 # Load an protected dirs
93 for option in config.options(section):
94 if option.startswith('protected'):
95 protected = config.get(section, option)
96
97 try:
98 (path, realm, user, passwd) = protected.split(',', 4)
99
100 except ValueError:
101 print >> sys.stderr, "Malformed Protected Directory option '%s'." % option
102 sys.exit(1)
103
104 if not self.hosts[section[12:].lower()].has_key('protected'):
105 self.hosts[section[12:].lower()]['protected'] = {}
106
107 if not self.hosts[section[12:].lower()]['protected'].has_key(path):
108 self.hosts[section[12:].lower()]['protected'][path] = []
109
110 self.hosts[section[12:].lower()]['protected'][path].append({'user': user, 'passwd': passwd, 'realm': realm})
111
112 if self.server['Host'] not in self.hosts.keys():
113 print "ERROR: No default virtual host defined for Host setting '%s'." % self.server['Host']
114 sys.exit(1)

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20