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