the injection pattern for extending charms

Gavin Panella gavin.panella at canonical.com
Fri Aug 30 13:31:10 UTC 2013


On 24 August 2013 17:30, Patrick Hetu <patrick.hetu at gmail.com> wrote:
> import imp
> import glob
> from os.path import abspath, dirname, join
>
> PROJECT_DIR = abspath(dirname(__file__))
>
> conffiles = glob.glob(join(PROJECT_DIR, 'juju_settings', '*.py'))
>
> for f in conffiles:
>     execfile(abspath(f))

I don't know enough to comment on how suitable this is as a pattern
for charms, but I can comment on this code:

- Check that glob() returns a sorted list, or sort it yourself, to
ensure that the results of that code is stable.

- Also, execfile() is gone in Python 3.3 (and possibly earlier, I
haven't checked). There are lots of workarounds to be found, but
there's a peer-reviewed and tested one in Twisted, see
twisted/python/compat.py.

Good luck!

Gavin.



More information about the Juju mailing list