diff options
| author | Julian Andres Klode <jak@debian.org> | 2015-06-17 16:04:41 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2015-06-17 18:08:54 +0200 |
| commit | 3f241967c363b98284315acc8dafed3805e7eb20 (patch) | |
| tree | 69a347d148c9932dcbd122169e4e6bd1c2dc467a /apt/cache.py | |
| parent | 7bac94124668c59fa30784d83050620bf0479f16 (diff) | |
| download | python-apt-3f241967c363b98284315acc8dafed3805e7eb20.tar.gz | |
apt.Cache: Introduce a connect2() callback connector
The new API passes the cache as the first argument to the
callback and allows for other arguments to be passed
as well.
Diffstat (limited to 'apt/cache.py')
| -rw-r--r-- | apt/cache.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/apt/cache.py b/apt/cache.py index 73a95e7c..faad8523 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -78,6 +78,7 @@ class Cache(object): self._records = None self._list = None self._callbacks = {} + self._callbacks2 = {} self._weakref = weakref.WeakValueDictionary() self._changes_count = -1 self._sorted_set = None @@ -144,6 +145,10 @@ class Cache(object): else: callback() + if name in self._callbacks2: + for callback, args, kwds in self._callbacks2[name]: + callback(self, *args, **kwds) + def open(self, progress=None): """ Open the package cache, after that it can be used like a dictionary @@ -545,6 +550,26 @@ class Cache(object): self._callbacks[name] = [] self._callbacks[name].append(callback) + def connect2(self, name, callback, *args, **kwds): + """Connect to a signal. + + The callback will be passed the cache as an argument, and + any arguments passed to this function. Make sure that, if you + pass a method of a class as your callback, your class does not + contain a reference to the cache. + + Cyclic references to the cache can cause issues if the Cache object + is replaced by a new one, because the cache keeps a lot of objects and + tens of open file descriptors. + + currently only used for cache_{post,pre}_{changed,open}. + + .. versionadded:: 1.0 + """ + if name not in self._callbacks2: + self._callbacks2[name] = [] + self._callbacks2[name].append((callback, args, kwds)) + def actiongroup(self): """Return an `ActionGroup` object for the current cache. |
