From 804606b721296a3dc6b4d386eaa3336ae772c9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 28 Jan 2009 12:45:01 +0100 Subject: First 'db' layout --- portato/db/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 portato/db/__init__.py (limited to 'portato/db/__init__.py') diff --git a/portato/db/__init__.py b/portato/db/__init__.py new file mode 100644 index 0000000..5787c56 --- /dev/null +++ b/portato/db/__init__.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# +# File: portato/db/__init__.py +# This file is part of the Portato-Project, a graphical portage-frontend. +# +# Copyright (C) 2009 René 'Necoro' Neumann +# This is free software. You may redistribute copies of it under the terms of +# the GNU General Public License version 2. +# There is NO WARRANTY, to the extent permitted by law. +# +# Written by René 'Necoro' Neumann -- cgit v1.2.3 From 816fbaf42407fbbb8466c0d08d64fc11f605e5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 28 Jan 2009 13:13:56 +0100 Subject: Use the new database class layout --- portato/db/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'portato/db/__init__.py') diff --git a/portato/db/__init__.py b/portato/db/__init__.py index 5787c56..122940a 100644 --- a/portato/db/__init__.py +++ b/portato/db/__init__.py @@ -9,3 +9,17 @@ # There is NO WARRANTY, to the extent permitted by law. # # Written by René 'Necoro' Neumann + +from __future__ import absolute_import + +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 -- cgit v1.2.3 From 59792e7297d90cdead2e1c83e4537991b20dd11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 28 Jan 2009 22:27:59 +0100 Subject: Enable sql-db formats --- portato/db/__init__.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'portato/db/__init__.py') 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")) -- cgit v1.2.3 From e3a7f1a2120f6bd20bdaf53afab5a5de1ae25554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 2 Feb 2009 13:10:26 +0100 Subject: Remove the USE_SQL flag - use normal config instead --- portato/db/__init__.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'portato/db/__init__.py') 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")) -- cgit v1.2.3 From cffc4dbc7529d761600bcaf5fbc63bdb308b3194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 2 Feb 2009 13:24:40 +0100 Subject: Use warning instead of debug, if the sql database could not be loaded --- portato/db/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'portato/db/__init__.py') diff --git a/portato/db/__init__.py b/portato/db/__init__.py index d77fc0d..e0919dd 100644 --- a/portato/db/__init__.py +++ b/portato/db/__init__.py @@ -13,7 +13,7 @@ from __future__ import absolute_import from ..session import Session, SectionDict -from ..helper import debug +from ..helper import debug, warning _SESSION = None _TYPE = None @@ -35,7 +35,7 @@ def Database(): try: from .sql import SQLDatabase except ImportError: - debug("Cannot load SQLDatabase.") + warning(_("Cannot load SQLDatabase.")) _TYPE = "dict" return Database() else: -- cgit v1.2.3