diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2008-04-08 23:54:55 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2008-04-08 23:54:55 +0200 |
commit | e015bdfed3417492dcc7ef794344bca9dacb1686 (patch) | |
tree | 3ed040d68b09fdab928d34c611589f4117083ae8 /portato/gui/utils.py | |
parent | 49958ced8a6ba185aa2e20776d32d31712032cc8 (diff) | |
download | portato-e015bdfed3417492dcc7ef794344bca9dacb1686.tar.gz portato-e015bdfed3417492dcc7ef794344bca9dacb1686.tar.bz2 portato-e015bdfed3417492dcc7ef794344bca9dacb1686.zip |
Added lock to database
Diffstat (limited to '')
-rw-r--r-- | portato/gui/utils.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/portato/gui/utils.py b/portato/gui/utils.py index 0c25463..a6bd800 100644 --- a/portato/gui/utils.py +++ b/portato/gui/utils.py @@ -10,12 +10,14 @@ # # Written by René 'Necoro' Neumann <necoro@necoro.net> -from __future__ import absolute_import +from __future__ import absolute_import, with_statement # some stuff needed import re import logging from collections import defaultdict +from threading import RLock +from functools import wraps # some backend things from ..backend import flags, system, set_system @@ -135,6 +137,16 @@ class Database (object): def __init__ (self): """Constructor.""" self.__initialize() + self._lock = RLock() + + def lock (f): + @wraps(f) + def wrapper (self, *args, **kwargs): + with self._lock: + r = f(self, *args, **kwargs) + return r + + return wrapper def __initialize (self): self._db = defaultdict(list) @@ -144,6 +156,7 @@ class Database (object): def __sort_key (self, x): return x.pkg.lower() + @lock def populate (self, category = None): """Populates the database. @@ -169,6 +182,7 @@ class Database (object): for key in self._db: # sort alphabetically self._db[key].sort(key = self.__sort_key) + @lock def get_cat (self, cat = None, byName = True): """Returns the packages in the category. @@ -207,6 +221,7 @@ class Database (object): except KeyError: # cat is in category list - but not in portage info(_("Catched KeyError => %s seems not to be an available category. Have you played with rsync-excludes?"), cat) + @lock def get_categories (self, installed = False): """Returns all categories. @@ -233,6 +248,7 @@ class Database (object): return (cat for cat in cats) + @lock def reload (self, cat = None): """Reloads the given category. @@ -256,6 +272,7 @@ class Database (object): def get_restrict (self): return self._restrict + @lock def set_restrict (self, restrict): if not restrict: self._restrict = None |