Dynamically registering reactive handlers at runtime

Merlijn Sebrechts merlijn.sebrechts at gmail.com
Thu Feb 18 17:06:39 UTC 2016


Thanks Stuart, I'm learning a lot of cool things about Python :)

I think charms.apt.install_queued() is what we'll use for the moment.

2016-02-18 18:04 GMT+01:00 Stuart Bishop <stuart at stuartbishop.net>:

> On 18 February 2016 at 17:15, Merlijn Sebrechts
> <merlijn.sebrechts at gmail.com> wrote:
>
> > The possible values for package-names are not known during build time.
> We do
> > know that _all_ queued packages have to be installed. Would it be
> possible
> > to have an `apt.installed.all` state?
>
> @when_not('apt.queued_installs') tells you this.
>
> @when_not('packages_queued')
> def queue_package_installations():
>     apt.queue_install(config()['packages'].split())
>     reactive.set_state('packages_queued')
>
> @when('packages_queued')
> @when_not('apt.queued_installs')
> def do_setup():
>     # packages installed. Lets do this
>     [...]
>
>
> If you can calculate the packages at import time, you could also do this:
>
> package_states = ['apt.installed.{}'.format(p) for p in
> config()['packages'].split()]
>
> @when(*package_states)
> def do_setup():
>     # Packages installed. Lets do this
>     [...]
>
>
> And for more potential solutions, the documentation for the apt layer
> has been updated which states you can call charms.apt.install_queued()
> yourself to install queued packages right now. It does nothing if
> nothing is queued, so you could just call it at the start of your
> handler instead of waiting on an apt.installed.* state at all.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20160218/5c589406/attachment.html>


More information about the Juju mailing list