~corey.bryant/charms/trusty/glance/mkdir755

« back to all changes in this revision

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

  • Committer: Ryan Beisner
  • Date: 2014-07-10 21:43:51 UTC
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: ryan.beisner@canonical.com-20140710214351-qr3gs4lca9ij3wzh
sync with charm helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
    config,
14
14
    log,
15
15
)
16
 
import apt_pkg
17
16
import os
18
17
 
19
18
 
56
55
    'icehouse/proposed': 'precise-proposed/icehouse',
57
56
    'precise-icehouse/proposed': 'precise-proposed/icehouse',
58
57
    'precise-proposed/icehouse': 'precise-proposed/icehouse',
 
58
    # Juno
 
59
    'juno': 'trusty-updates/juno',
 
60
    'trusty-juno': 'trusty-updates/juno',
 
61
    'trusty-juno/updates': 'trusty-updates/juno',
 
62
    'trusty-updates/juno': 'trusty-updates/juno',
 
63
    'juno/proposed': 'trusty-proposed/juno',
 
64
    'juno/proposed': 'trusty-proposed/juno',
 
65
    'trusty-juno/proposed': 'trusty-proposed/juno',
 
66
    'trusty-proposed/juno': 'trusty-proposed/juno',
59
67
}
60
68
 
61
69
# The order of this list is very important. Handlers should be listed in from
108
116
 
109
117
def filter_installed_packages(packages):
110
118
    """Returns a list of packages that require installation"""
 
119
    import apt_pkg
111
120
    apt_pkg.init()
112
121
 
113
122
    # Tell apt to build an in-memory cache to prevent race conditions (if
226
235
                      sources_var='install_sources',
227
236
                      keys_var='install_keys'):
228
237
    """
229
 
    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.
230
242
 
231
243
    Example config:
232
 
        install_sources:
 
244
        install_sources: |
233
245
          - "ppa:foo"
234
246
          - "http://example.com/repo precise main"
235
 
        install_keys:
 
247
        install_keys: |
236
248
          - null
237
249
          - "a1b2c3d4"
238
250
 
239
251
    Note that 'null' (a.k.a. None) should not be quoted.
240
252
    """
241
 
    sources = safe_load(config(sources_var))
242
 
    keys = config(keys_var)
243
 
    if keys is not None:
244
 
        keys = safe_load(keys)
245
 
    if isinstance(sources, basestring) and (
246
 
            keys is None or isinstance(keys, basestring)):
247
 
        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)
248
262
    else:
249
 
        if not len(sources) == len(keys):
250
 
            msg = 'Install sources and keys lists are different lengths'
251
 
            raise SourceConfigError(msg)
252
 
        for src_num in range(len(sources)):
253
 
            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)
254
271
    if update:
255
272
        apt_update(fatal=True)
256
273