diff options
Diffstat (limited to 'lib/dodai/config/__init__.py')
-rw-r--r-- | lib/dodai/config/__init__.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/dodai/config/__init__.py b/lib/dodai/config/__init__.py new file mode 100644 index 0000000..e849f8e --- /dev/null +++ b/lib/dodai/config/__init__.py | |||
@@ -0,0 +1,76 @@ | |||
1 | # Copyright (C) 2010 Leonard Thomas | ||
2 | # | ||
3 | # This file is part of Dodai. | ||
4 | # | ||
5 | # Dodai is free software: you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published by | ||
7 | # the Free Software Foundation, either version 3 of the License, or | ||
8 | # (at your option) any later version. | ||
9 | # | ||
10 | # Dodai is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | # GNU General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with Dodai. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | |||
19 | class Config(object): | ||
20 | |||
21 | def __call__(self): | ||
22 | obj = ConfigResults() | ||
23 | if hasattr(self, 'vars'): | ||
24 | for key, val in self.vars.items(): | ||
25 | setattr(obj, key, val) | ||
26 | return obj | ||
27 | |||
28 | @property | ||
29 | def files(self): | ||
30 | if not hasattr(self, '_files'): | ||
31 | from dodai.config.files import ConfigFiles | ||
32 | from dodai.tools.odict import OrderedDict | ||
33 | from dodai.tools import Section | ||
34 | from dodai.tools.himo import String2Himo | ||
35 | from ConfigParser import ConfigParser | ||
36 | s2h = String2Himo() | ||
37 | self._files = ConfigFiles(OrderedDict, Section, s2h) | ||
38 | self._files.register_parser_object(ConfigParser) | ||
39 | return self._files | ||
40 | |||
41 | @property | ||
42 | def options(self): | ||
43 | if not hasattr(self, '_options'): | ||
44 | from dodai.config.option import ConfigOption | ||
45 | self._options = ConfigOption() | ||
46 | return self._options | ||
47 | |||
48 | @property | ||
49 | def logs(self): | ||
50 | if not hasattr(self, '_logs'): | ||
51 | from dodai.config.log import ConfigLog | ||
52 | self._logs = ConfigLog() | ||
53 | return self._logs | ||
54 | |||
55 | @property | ||
56 | def databases(self): | ||
57 | if not hasattr(self, '_databases'): | ||
58 | # Wire up the sqlalchemy objects to use in the sa object | ||
59 | # which will be used as the default database handler | ||
60 | from dodai.config.databases import ConfigDatabases | ||
61 | from dodai.config.databases.sa import Sa | ||
62 | from sqlalchemy.orm import sessionmaker | ||
63 | from sqlalchemy import create_engine | ||
64 | from dodai.db import Db | ||
65 | sa = Sa(create_engine, sessionmaker, Db) | ||
66 | self._databases = ConfigDatabases(sa, 'sa') | ||
67 | return self._databases | ||
68 | |||
69 | def set(self, key, val): | ||
70 | if not hasattr(self, 'vars'): | ||
71 | self.vars = {} | ||
72 | self.vars[key] = val | ||
73 | |||
74 | |||
75 | class ConfigResults(object): | ||
76 | pass | ||