diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2009-01-28 22:27:59 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2009-01-28 22:27:59 +0100 |
commit | 59792e7297d90cdead2e1c83e4537991b20dd11c (patch) | |
tree | 9f4f08607a91a460b8f548348fc1669b3afb123d /portato/db/__init__.py | |
parent | 5339ea7a621fc2a406198961613a1e9778ca1339 (diff) | |
download | portato-59792e7297d90cdead2e1c83e4537991b20dd11c.tar.gz portato-59792e7297d90cdead2e1c83e4537991b20dd11c.tar.bz2 portato-59792e7297d90cdead2e1c83e4537991b20dd11c.zip |
Enable sql-db formats
Diffstat (limited to 'portato/db/__init__.py')
-rw-r--r-- | portato/db/__init__.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/portato/db/__init__.py b/portato/db/__init__.py index 122940a..40bf9ee 100644 --- a/portato/db/__init__.py +++ b/portato/db/__init__.py @@ -12,14 +12,23 @@ from __future__ import absolute_import +from ..session import Session, SectionDict from ..constants import USE_SQL from ..helper import debug -if USE_SQL: - debug("Using SQLDatabase") - from .sql import SQLDatabase - Database = SQLDatabase -else: - debug("Using DictDatabase") - from .dict import DictDatabase - Database = DictDatabase +_SESSION = None + +def Database(): + global _SESSION + + if _SESSION is None: + _SESSION = Session("db.cfg", name = "DB") + + if USE_SQL: + debug("Using SQLDatabase") + from .sql import SQLDatabase + return SQLDatabase(SectionDict(_SESSION, "SQL")) + else: + debug("Using DictDatabase") + from .dict import DictDatabase + return DictDatabase(SectionDict(_SESSION, "dict")) |