diff options
Diffstat (limited to 'dodai/config/databases/__init__.py')
-rw-r--r-- | dodai/config/databases/__init__.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/dodai/config/databases/__init__.py b/dodai/config/databases/__init__.py index 459ee1b..da317e8 100644 --- a/dodai/config/databases/__init__.py +++ b/dodai/config/databases/__init__.py | |||
@@ -48,15 +48,15 @@ class ConfigDatabases(object): | |||
48 | def _build_default_handler(self): | 48 | def _build_default_handler(self): |
49 | # Creates the default sqlalchemy handler | 49 | # Creates the default sqlalchemy handler |
50 | if 'sa' not in self._handlers: | 50 | if 'sa' not in self._handlers: |
51 | from .sa import Sa | 51 | from dodai.config.databases.sa import Sa |
52 | from sqlalchemy.orm import sessionmaker | 52 | from sqlalchemy.orm import sessionmaker |
53 | from sqlalchemy import create_engine | 53 | from sqlalchemy import create_engine |
54 | from ....db import Db | 54 | from dodai.db import Db |
55 | sa = Sa(create_engine, sessionmaker, Db) | 55 | sa = Sa(create_engine, sessionmaker, Db) |
56 | self._handlers['sa'] = sa | 56 | self._handlers['sa'] = sa |
57 | 57 | ||
58 | def add_handler(self, name, handler): | 58 | def add_handler(self, name, handler): |
59 | """Addes the given handler and name to this objects handlers | 59 | """Adds the given handler and name to this objects handlers |
60 | 60 | ||
61 | """ | 61 | """ |
62 | self._handlers[name] = obj | 62 | self._handlers[name] = obj |
@@ -120,13 +120,14 @@ class DatabaseConnectionValidator(object): | |||
120 | def load(self): | 120 | def load(self): |
121 | if not self.obj: | 121 | if not self.obj: |
122 | self._validate() | 122 | self._validate() |
123 | self.obj = self.handler.load(self.section) | 123 | handler = self._get_handler() |
124 | self.obj = handler(self.name, self.section) | ||
124 | return self.obj | 125 | return self.obj |
125 | 126 | ||
126 | def _set_handler(self): | 127 | def _get_handler(self): |
127 | if hasattr(self.section, 'handler'): | 128 | if hasattr(self.section, 'handler'): |
128 | name = self.section.handler.lower() | 129 | name = self.section.handler.lower() |
129 | if handler in self.handlers.keys(): | 130 | if handler in self._handlers.keys(): |
130 | return self._handlers[name] | 131 | return self._handlers[name] |
131 | return self._handlers[self.DEFAULT_HANDLER] | 132 | return self._handlers[self.DEFAULT_HANDLER] |
132 | 133 | ||
@@ -182,14 +183,14 @@ class DatabaseConnectionValidator(object): | |||
182 | return False | 183 | return False |
183 | 184 | ||
184 | def _database_type(self): | 185 | def _database_type(self): |
185 | keys = self.section.__dict__.keys() | 186 | keys = self.section.___options___.keys() |
186 | for type_, pool in self.OPTIONS_REQUIRED.items(): | 187 | for type_, pool in self.OPTIONS_REQUIRED.items(): |
187 | out = True | 188 | out = True |
188 | for key in keys: | 189 | for key in keys: |
189 | if key not in pool: | 190 | if key not in pool: |
190 | out = False | 191 | out = False |
191 | if out: | 192 | if out: |
192 | return type | 193 | return type_ |
193 | return False | 194 | return False |
194 | 195 | ||
195 | 196 | ||
@@ -321,13 +322,13 @@ class DatabaseConnectionException(Exception): | |||
321 | def __init__(self, section_name, options_required): | 322 | def __init__(self, section_name, options_required): |
322 | self.section_name = section_name | 323 | self.section_name = section_name |
323 | self.options_required = options_required | 324 | self.options_required = options_required |
324 | self.msg = self._build_message | 325 | self.msg = self._build_message() |
325 | 326 | ||
326 | def _build_message(self): | 327 | def _build_message(self): |
327 | out = [] | 328 | out = [] |
328 | out.append(self.MESSAGE.format(section_name=self.section_name)) | 329 | out.append(self.MESSAGE.format(section_name=self.section_name)) |
329 | for database_type, options in self.options_required: | 330 | for database_type, options in self.options_required.items(): |
330 | options = list_to_englis(options) | 331 | options = list_to_english(options) |
331 | out.append(self.MSG_TYPE.format(database_type=database_type, | 332 | out.append(self.MSG_TYPE.format(database_type=database_type, |
332 | options=options)) | 333 | options=options)) |
333 | out.append(self.MSG_END) | 334 | out.append(self.MSG_END) |