~mvo/aptdaemon/0.3-fix-race-597017

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Aptdaemon provides a plugin mechanism by making use of setuptools' entry points.
The group name is "aptdaemon.plugins". 

Currently there are two types of plugins available which allow you to modify 
the marked changes of a transaction. Each plugin can be a function which 
accepts the resolver (apt.cache.ProblemResolver) and the cache (apt.cache.Cache)
as arguments:

* modify_cache_before
  The plugged-in function is called after the intentional changes of the
  transaction have been marked, but before the dependencies have been resolved.

* modify_cache_after
  The plugged-in function is called after the dependency resolution of the
  transaction. The resolver will be called again afterwards.

A short overview of the steps required to process a transaction:

1. Mark intentional changes (e.g. the to be installed packages of a
   InstallPackages transaction)
2. Call all modify_cache_before plugins
3. Run the dependency resolver
4. Call all modify_cache_after_plugins and re-run the resolver
5. Commit changes

Here is an example which would install language packages:

./plugins/aptd.py:

>>> def install_language_packs(resolver, cache):
>>>     """Marks the required language packs for installation."""
>>>     ... do the magic here ...
>>>     language_pack.mark_install(False, True, language_pack.is_auto_installed)
>>>     # Only protect your changes if they are mantadory. If they cannot be
>>>     # be installed the transaction will fail.
>>>     resolver.clear(language_pack)
>>>     resolver.protect(language_pack)

Finally you would have to register your function as entry point in setup.py:

>>> setup(
>>> ...
>>> entry_points="""[aptdaemon.plugins]
>>> modify_cache_after=plugins.aptd:install_language_packs
>>> """,
>>> ...
>>> )

Keep in mind that you can only register one entry point per name/plugin in
a distribution.