~tribaal/charms/trusty/nova-compute/enable-api-rate-limiting

« back to all changes in this revision

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

  • Committer: Edward Hope-Morley
  • Date: 2015-03-16 15:38:04 UTC
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: edward.hope-morley@canonical.com-20150316153804-du1szvv0gwfve4g6
cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
    'kilo/proposed': 'trusty-proposed/kilo',
91
91
    'trusty-kilo/proposed': 'trusty-proposed/kilo',
92
92
    'trusty-proposed/kilo': 'trusty-proposed/kilo',
93
 
    # Liberty
94
 
    'liberty': 'trusty-updates/liberty',
95
 
    'trusty-liberty': 'trusty-updates/liberty',
96
 
    'trusty-liberty/updates': 'trusty-updates/liberty',
97
 
    'trusty-updates/liberty': 'trusty-updates/liberty',
98
 
    'liberty/proposed': 'trusty-proposed/liberty',
99
 
    'trusty-liberty/proposed': 'trusty-proposed/liberty',
100
 
    'trusty-proposed/liberty': 'trusty-proposed/liberty',
101
93
}
102
94
 
103
95
# The order of this list is very important. Handlers should be listed in from
166
158
 
167
159
def apt_cache(in_memory=True):
168
160
    """Build and return an apt cache"""
169
 
    from apt import apt_pkg
 
161
    import apt_pkg
170
162
    apt_pkg.init()
171
163
    if in_memory:
172
164
        apt_pkg.config.set("Dir::Cache::pkgcache", "")
223
215
    _run_apt_command(cmd, fatal)
224
216
 
225
217
 
226
 
def apt_mark(packages, mark, fatal=False):
227
 
    """Flag one or more packages using apt-mark"""
228
 
    cmd = ['apt-mark', mark]
 
218
def apt_hold(packages, fatal=False):
 
219
    """Hold one or more packages"""
 
220
    cmd = ['apt-mark', 'hold']
229
221
    if isinstance(packages, six.string_types):
230
222
        cmd.append(packages)
231
223
    else:
233
225
    log("Holding {}".format(packages))
234
226
 
235
227
    if fatal:
236
 
        subprocess.check_call(cmd, universal_newlines=True)
 
228
        subprocess.check_call(cmd)
237
229
    else:
238
 
        subprocess.call(cmd, universal_newlines=True)
239
 
 
240
 
 
241
 
def apt_hold(packages, fatal=False):
242
 
    return apt_mark(packages, 'hold', fatal=fatal)
243
 
 
244
 
 
245
 
def apt_unhold(packages, fatal=False):
246
 
    return apt_mark(packages, 'unhold', fatal=fatal)
 
230
        subprocess.call(cmd)
247
231
 
248
232
 
249
233
def add_source(source, key=None):
386
370
    for handler in handlers:
387
371
        try:
388
372
            installed_to = handler.install(source, *args, **kwargs)
389
 
        except UnhandledSource as e:
390
 
            log('Install source attempt unsuccessful: {}'.format(e),
391
 
                level='WARNING')
 
373
        except UnhandledSource:
 
374
            pass
392
375
    if not installed_to:
393
376
        raise UnhandledSource("No handler found for source {}".format(source))
394
377
    return installed_to