diff options
Diffstat (limited to 'dodai/config/__init__.py')
-rw-r--r-- | dodai/config/__init__.py | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/dodai/config/__init__.py b/dodai/config/__init__.py index 6c3011c..e849f8e 100644 --- a/dodai/config/__init__.py +++ b/dodai/config/__init__.py | |||
@@ -25,25 +25,36 @@ class Config(object): | |||
25 | setattr(obj, key, val) | 25 | setattr(obj, key, val) |
26 | return obj | 26 | return obj |
27 | 27 | ||
28 | def __getattr__(self, key): | 28 | @property |
29 | 29 | def files(self): | |
30 | if 'files' == key: | 30 | if not hasattr(self, '_files'): |
31 | from dodai.config.files import ConfigFiles | 31 | from dodai.config.files import ConfigFiles |
32 | from dodai.tools.odict import OrderedDict | 32 | from dodai.tools.odict import OrderedDict |
33 | from dodai.tools import Section | 33 | from dodai.tools import Section |
34 | from dodai.tools.himo import String2Himo | 34 | from dodai.tools.himo import String2Himo |
35 | from ConfigParser import ConfigParser | ||
35 | s2h = String2Himo() | 36 | s2h = String2Himo() |
36 | self.files = ConfigFiles(OrderedDict, Section, s2h) | 37 | self._files = ConfigFiles(OrderedDict, Section, s2h) |
37 | return self.files | 38 | self._files.register_parser_object(ConfigParser) |
38 | elif 'options' == key: | 39 | return self._files |
40 | |||
41 | @property | ||
42 | def options(self): | ||
43 | if not hasattr(self, '_options'): | ||
39 | from dodai.config.option import ConfigOption | 44 | from dodai.config.option import ConfigOption |
40 | self.options = ConfigOption() | 45 | self._options = ConfigOption() |
41 | return self.options | 46 | return self._options |
42 | elif 'logs' == key: | 47 | |
48 | @property | ||
49 | def logs(self): | ||
50 | if not hasattr(self, '_logs'): | ||
43 | from dodai.config.log import ConfigLog | 51 | from dodai.config.log import ConfigLog |
44 | self.logs = ConfigLog() | 52 | self._logs = ConfigLog() |
45 | return self.logs | 53 | return self._logs |
46 | elif 'databases' == key: | 54 | |
55 | @property | ||
56 | def databases(self): | ||
57 | if not hasattr(self, '_databases'): | ||
47 | # Wire up the sqlalchemy objects to use in the sa object | 58 | # Wire up the sqlalchemy objects to use in the sa object |
48 | # which will be used as the default database handler | 59 | # which will be used as the default database handler |
49 | from dodai.config.databases import ConfigDatabases | 60 | from dodai.config.databases import ConfigDatabases |
@@ -52,10 +63,8 @@ class Config(object): | |||
52 | from sqlalchemy import create_engine | 63 | from sqlalchemy import create_engine |
53 | from dodai.db import Db | 64 | from dodai.db import Db |
54 | sa = Sa(create_engine, sessionmaker, Db) | 65 | sa = Sa(create_engine, sessionmaker, Db) |
55 | self.databases = ConfigDatabases(sa, 'sa') | 66 | self._databases = ConfigDatabases(sa, 'sa') |
56 | return self.databases | 67 | return self._databases |
57 | else: | ||
58 | raise KeyError(key) | ||
59 | 68 | ||
60 | def set(self, key, val): | 69 | def set(self, key, val): |
61 | if not hasattr(self, 'vars'): | 70 | if not hasattr(self, 'vars'): |