~hopem/charms/trusty/neutron-gateway/lp1485655

« back to all changes in this revision

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

  • Committer: Corey Bryant
  • Date: 2015-07-17 02:02:50 UTC
  • mfrom: (127.1.1 neutron-gateway)
  • Revision ID: corey.bryant@canonical.com-20150717020250-gq1sx7omatfdv987
[corey.bryant,trivial] Synch charm-helpers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
    _run_apt_command(cmd, fatal)
216
216
 
217
217
 
 
218
def apt_mark(packages, mark, fatal=False):
 
219
    """Flag one or more packages using apt-mark"""
 
220
    cmd = ['apt-mark', mark]
 
221
    if isinstance(packages, six.string_types):
 
222
        cmd.append(packages)
 
223
    else:
 
224
        cmd.extend(packages)
 
225
    log("Holding {}".format(packages))
 
226
 
 
227
    if fatal:
 
228
        subprocess.check_call(cmd, universal_newlines=True)
 
229
    else:
 
230
        subprocess.call(cmd, universal_newlines=True)
 
231
 
 
232
 
218
233
def apt_hold(packages, fatal=False):
219
 
    """Hold one or more packages"""
220
 
    cmd = ['apt-mark', 'hold']
221
 
    if isinstance(packages, six.string_types):
222
 
        cmd.append(packages)
223
 
    else:
224
 
        cmd.extend(packages)
225
 
    log("Holding {}".format(packages))
226
 
 
227
 
    if fatal:
228
 
        subprocess.check_call(cmd)
229
 
    else:
230
 
        subprocess.call(cmd)
 
234
    return apt_mark(packages, 'hold', fatal=fatal)
 
235
 
 
236
 
 
237
def apt_unhold(packages, fatal=False):
 
238
    return apt_mark(packages, 'unhold', fatal=fatal)
231
239
 
232
240
 
233
241
def add_source(source, key=None):
370
378
    for handler in handlers:
371
379
        try:
372
380
            installed_to = handler.install(source, *args, **kwargs)
373
 
        except UnhandledSource:
374
 
            pass
 
381
        except UnhandledSource as e:
 
382
            log('Install source attempt unsuccessful: {}'.format(e),
 
383
                level='WARNING')
375
384
    if not installed_to:
376
385
        raise UnhandledSource("No handler found for source {}".format(source))
377
386
    return installed_to