]>
Commit | Line | Data |
---|---|---|
a6dc0bad MT |
1 | #!/usr/bin/python |
2 | ||
9068dba1 | 3 | import ConfigParser as configparser |
9ed02e3b | 4 | import StringIO |
a6dc0bad MT |
5 | |
6 | import accounts | |
9068dba1 MT |
7 | import database |
8 | import geoip | |
66862195 | 9 | import fireinfo |
9068dba1 MT |
10 | import iuse |
11 | import memcached | |
12 | import mirrors | |
13 | import netboot | |
66862195 | 14 | import nopaste |
9068dba1 MT |
15 | import releases |
16 | import settings | |
66862195 | 17 | import talk |
a6dc0bad | 18 | |
0a6875dc | 19 | from . import blog |
2c361abc MT |
20 | from . import zeiterfassung |
21 | ||
9ed02e3b MT |
22 | DEFAULT_CONFIG = StringIO.StringIO(""" |
23 | [global] | |
24 | debug = false | |
25 | ||
26 | data_dir = | |
27 | static_dir = %(data_dir)s/static | |
28 | templates_dir = %(data_dir)s/templates | |
29 | """) | |
30 | ||
a6dc0bad | 31 | class Backend(object): |
2cd9af74 | 32 | def __init__(self, configfile, debug=False): |
9068dba1 MT |
33 | # Read configuration file. |
34 | self.config = self.read_config(configfile) | |
9ed02e3b MT |
35 | |
36 | # Enable debug logging if configured | |
37 | self.debug = debug or self.config.getboolean("global", "debug") | |
9068dba1 MT |
38 | |
39 | # Setup database. | |
40 | self.setup_database() | |
a6dc0bad | 41 | |
9068dba1 MT |
42 | # Initialize settings first. |
43 | self.settings = settings.Settings(self) | |
44 | self.memcache = memcached.Memcached(self) | |
45 | ||
46 | # Initialize backend modules. | |
a6dc0bad | 47 | self.accounts = accounts.Accounts(self) |
9068dba1 MT |
48 | self.downloads = mirrors.Downloads(self) |
49 | self.geoip = geoip.GeoIP(self) | |
66862195 | 50 | self.fireinfo = fireinfo.Fireinfo(self) |
9068dba1 MT |
51 | self.iuse = iuse.IUse(self) |
52 | self.mirrors = mirrors.Mirrors(self) | |
53 | self.netboot = netboot.NetBoot(self) | |
66862195 | 54 | self.nopaste = nopaste.Nopaste(self) |
9068dba1 | 55 | self.releases = releases.Releases(self) |
66862195 | 56 | self.talk = talk.Talk(self) |
9068dba1 | 57 | |
0a6875dc | 58 | self.blog = blog.Blog(self) |
2c361abc MT |
59 | self.zeiterfassung = zeiterfassung.ZeiterfassungClient(self) |
60 | ||
9068dba1 MT |
61 | def read_config(self, configfile): |
62 | cp = configparser.ConfigParser() | |
9ed02e3b MT |
63 | |
64 | # Initialize configuration with some sensible defaults | |
65 | cp.readfp(DEFAULT_CONFIG) | |
66 | ||
67 | # Parse file | |
9068dba1 MT |
68 | cp.read(configfile) |
69 | ||
70 | return cp | |
71 | ||
72 | def setup_database(self): | |
73 | """ | |
74 | Sets up the database connection. | |
75 | """ | |
76 | credentials = { | |
77 | "host" : self.config.get("database", "server"), | |
78 | "database" : self.config.get("database", "database"), | |
79 | "user" : self.config.get("database", "username"), | |
80 | "password" : self.config.get("database", "password"), | |
81 | } | |
82 | ||
83 | self.db = database.Connection(**credentials) |