diff options
Diffstat (limited to 'portato/db/database.py')
-rw-r--r-- | portato/db/database.py | 17 |
1 files changed, 17 insertions, 0 deletions
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. |