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