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/database.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 portato/db/database.py (limited to 'portato/db/database.py') diff --git a/portato/db/database.py b/portato/db/database.py new file mode 100644 index 0000000..7c51667 --- /dev/null +++ b/portato/db/database.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# +# File: portato/db/database.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 + +class PkgData (object): + __slots__ = ("cat", "pkg", "inst") + + def __init__ (self, cat, pkg, inst): + self.cat = cat + self.pkg = pkg + self.inst = inst + + def __iter__ (self): + return iter((self.cat, self.pkg, self.inst)) + + def __cmp__ (self, other): + return cmp(self.pkg.lower(), other.pkg.lower()) + + def __repr__ (self): + return "" % {"cat" : self.cat, "pkg" : self.pkg, "inst" : self.inst} + +class Database (object): + + def populate (self, category = None): + raise NotImplentedError + + def get_cat (self, cat = None, byName = True): + raise NotImplentedError + + def get_categories (self, installed = False): + raise NotImplentedError + + def reload (self, cat = None): + raise NotImplentedError -- cgit v1.2.3 From abbc143c81d9c5b808d5c8ee14acc33835871fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 28 Jan 2009 12:52:56 +0100 Subject: Moved DictDatabase --- portato/db/database.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'portato/db/database.py') diff --git a/portato/db/database.py b/portato/db/database.py index 7c51667..0ff71a7 100644 --- a/portato/db/database.py +++ b/portato/db/database.py @@ -29,14 +29,42 @@ class PkgData (object): class Database (object): + ALL = _("ALL") + def populate (self, category = None): + """Populates the database. + + @param category: An optional category - so only packages of this category are inserted. + @type category: string + """ raise NotImplentedError def get_cat (self, cat = None, byName = True): + """Returns the packages in the category. + + @param cat: category to return the packages from; if None it defaults to C{ALL} + @type cat: string + @param byName: selects whether to return the list sorted by name or by installation + @type byName: boolean + @return: an iterator over the packages + @rtype: L{PkgData} + """ raise NotImplentedError def get_categories (self, installed = False): + """Returns all categories. + + @param installed: Only return these with at least one installed package. + @type installed: boolean + @returns: the list of categories + @rtype: string + """ raise NotImplentedError def reload (self, cat = None): + """Reloads the given category. + + @param cat: category + @type cat: string + """ raise NotImplentedError -- cgit v1.2.3 From 320f6f6270853b0209611ac6ec642994a90220b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 28 Jan 2009 12:58:53 +0100 Subject: Moved SQLDatabase --- portato/db/database.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'portato/db/database.py') diff --git a/portato/db/database.py b/portato/db/database.py index 0ff71a7..7d8e378 100644 --- a/portato/db/database.py +++ b/portato/db/database.py @@ -10,6 +10,8 @@ # # Written by René 'Necoro' Neumann +from __future__ import absolute_import, with_statement + class PkgData (object): __slots__ = ("cat", "pkg", "inst") -- 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/database.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'portato/db/database.py') diff --git a/portato/db/database.py b/portato/db/database.py index 7d8e378..941c3a3 100644 --- a/portato/db/database.py +++ b/portato/db/database.py @@ -12,6 +12,9 @@ from __future__ import absolute_import, with_statement +from threading import RLock +from functools import wraps + class PkgData (object): __slots__ = ("cat", "pkg", "inst") @@ -33,6 +36,20 @@ class Database (object): ALL = _("ALL") + def __init__ (self): + self._lock = RLock() + + @staticmethod + def lock (f): + @wraps(f) + def wrapper (self, *args, **kwargs): + with self._lock: + r = f(self, *args, **kwargs) + + return r + + return wrapper + def populate (self, category = None): """Populates the database. -- cgit v1.2.3 From d97a8bba4c3c877953bc6e800095ac4bc699ea45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 2 Feb 2009 11:29:08 +0100 Subject: Add the disabled field to PkgData --- portato/db/database.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'portato/db/database.py') diff --git a/portato/db/database.py b/portato/db/database.py index 941c3a3..c36c5dc 100644 --- a/portato/db/database.py +++ b/portato/db/database.py @@ -16,15 +16,16 @@ from threading import RLock from functools import wraps class PkgData (object): - __slots__ = ("cat", "pkg", "inst") + __slots__ = ("cat", "pkg", "inst", "disabled") - def __init__ (self, cat, pkg, inst): + def __init__ (self, cat, pkg, inst = False, disabled = False): self.cat = cat self.pkg = pkg self.inst = inst + self.disabled = disabled def __iter__ (self): - return iter((self.cat, self.pkg, self.inst)) + return iter((self.cat, self.pkg, self.inst, self.disabled)) def __cmp__ (self, other): return cmp(self.pkg.lower(), other.pkg.lower()) @@ -80,6 +81,13 @@ class Database (object): """ raise NotImplentedError + def disable (self, cpv): + """Marks the CPV as disabled. + + @param cpv: the cpv to mark + """ + raise NotImplentedError + def reload (self, cat = None): """Reloads the given category. -- cgit v1.2.3 From a80ff9994c49b3aaba7d3f0bbf6317107fcf39bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 2 Feb 2009 12:47:49 +0100 Subject: Do not show categories which only hold disabled packages --- portato/db/database.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'portato/db/database.py') diff --git a/portato/db/database.py b/portato/db/database.py index c36c5dc..bc78b01 100644 --- a/portato/db/database.py +++ b/portato/db/database.py @@ -59,13 +59,15 @@ class Database (object): """ raise NotImplentedError - def get_cat (self, cat = None, byName = True): + def get_cat (self, cat = None, byName = True, showDisabled = False): """Returns the packages in the category. @param cat: category to return the packages from; if None it defaults to C{ALL} @type cat: string @param byName: selects whether to return the list sorted by name or by installation @type byName: boolean + @param showDisabled: should disabled packages be returned + @type showDisabled: boolean @return: an iterator over the packages @rtype: L{PkgData} """ -- cgit v1.2.3