~ivoks/charms/trusty/neutron-gateway/mtu-vlan

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/fetch/__init__.py

  • Committer: Corey Bryant
  • Date: 2014-07-09 19:25:29 UTC
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: corey.bryant@canonical.com-20140709192529-c2azv58whgj6dnmd
Sync with charm-helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
235
235
                      sources_var='install_sources',
236
236
                      keys_var='install_keys'):
237
237
    """
238
 
    Configure multiple sources from charm configuration
 
238
    Configure multiple sources from charm configuration.
 
239
 
 
240
    The lists are encoded as yaml fragments in the configuration.
 
241
    The frament needs to be included as a string.
239
242
 
240
243
    Example config:
241
 
        install_sources:
 
244
        install_sources: |
242
245
          - "ppa:foo"
243
246
          - "http://example.com/repo precise main"
244
 
        install_keys:
 
247
        install_keys: |
245
248
          - null
246
249
          - "a1b2c3d4"
247
250
 
248
251
    Note that 'null' (a.k.a. None) should not be quoted.
249
252
    """
250
 
    sources = safe_load(config(sources_var))
251
 
    keys = config(keys_var)
252
 
    if keys is not None:
253
 
        keys = safe_load(keys)
254
 
    if isinstance(sources, basestring) and (
255
 
            keys is None or isinstance(keys, basestring)):
256
 
        add_source(sources, keys)
 
253
    sources = safe_load((config(sources_var) or '').strip()) or []
 
254
    keys = safe_load((config(keys_var) or '').strip()) or None
 
255
 
 
256
    if isinstance(sources, basestring):
 
257
        sources = [sources]
 
258
 
 
259
    if keys is None:
 
260
        for source in sources:
 
261
            add_source(source, None)
257
262
    else:
258
 
        if not len(sources) == len(keys):
259
 
            msg = 'Install sources and keys lists are different lengths'
260
 
            raise SourceConfigError(msg)
261
 
        for src_num in range(len(sources)):
262
 
            add_source(sources[src_num], keys[src_num])
 
263
        if isinstance(keys, basestring):
 
264
            keys = [keys]
 
265
 
 
266
        if len(sources) != len(keys):
 
267
            raise SourceConfigError(
 
268
                'Install sources and keys lists are different lengths')
 
269
        for source, key in zip(sources, keys):
 
270
            add_source(source, key)
263
271
    if update:
264
272
        apt_update(fatal=True)
265
273