diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2009-02-02 13:10:26 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2009-02-02 13:10:26 +0100 |
commit | e3a7f1a2120f6bd20bdaf53afab5a5de1ae25554 (patch) | |
tree | 85e9e4aa5efa69783cb26eadcaf8f85166d0ad9e /portato | |
parent | a80ff9994c49b3aaba7d3f0bbf6317107fcf39bb (diff) | |
download | portato-e3a7f1a2120f6bd20bdaf53afab5a5de1ae25554.tar.gz portato-e3a7f1a2120f6bd20bdaf53afab5a5de1ae25554.tar.bz2 portato-e3a7f1a2120f6bd20bdaf53afab5a5de1ae25554.zip |
Remove the USE_SQL flag - use normal config instead
Diffstat (limited to '')
-rw-r--r-- | portato/constants.py | 3 | ||||
-rw-r--r-- | portato/db/__init__.py | 25 |
2 files changed, 19 insertions, 9 deletions
diff --git a/portato/constants.py b/portato/constants.py index 79ad0f2..3d7217f 100644 --- a/portato/constants.py +++ b/portato/constants.py @@ -22,8 +22,6 @@ These should be set during the installation. @type HOME: string @var SU_COMMAND: command to execute to "su" @type SU_COMMAND: string -@var USE_SQL: whether to use the sqlite db -@type USE_SQL: boolean @var CONFIG_DIR: The configuration directory. @type CONFIG_DIR: string @@ -58,7 +56,6 @@ APP = "portato" VERSION = "9999" HOME = os.environ["HOME"] SU_COMMAND = "gksu -D 'Portato'" -USE_SQL = True # config CONFIG_DIR = "/etc/portato/" diff --git a/portato/db/__init__.py b/portato/db/__init__.py index 40bf9ee..d77fc0d 100644 --- a/portato/db/__init__.py +++ b/portato/db/__init__.py @@ -13,22 +13,35 @@ from __future__ import absolute_import from ..session import Session, SectionDict -from ..constants import USE_SQL from ..helper import debug _SESSION = None +_TYPE = None + +def _set_type(t): + global _TYPE + _TYPE = t def Database(): - global _SESSION + global _SESSION, _TYPE if _SESSION is None: _SESSION = Session("db.cfg", name = "DB") + _SESSION.add_handler((["type"], _set_type, lambda: _TYPE), default = ["sql"]) + _SESSION.load() - if USE_SQL: + if _TYPE == "sql": debug("Using SQLDatabase") - from .sql import SQLDatabase - return SQLDatabase(SectionDict(_SESSION, "SQL")) - else: + try: + from .sql import SQLDatabase + except ImportError: + debug("Cannot load SQLDatabase.") + _TYPE = "dict" + return Database() + else: + return SQLDatabase(SectionDict(_SESSION, "SQL")) + + elif _TYPE == "dict": debug("Using DictDatabase") from .dict import DictDatabase return DictDatabase(SectionDict(_SESSION, "dict")) |