def _get_upgradable(dist_upgrade=True, **kwargs):
    '''
    Utility function to get upgradable packages

    Sample return data:
    { 'pkgname': '1.2.3-45', ... }
    '''

    cmd = ['apt-get', '--just-print']
    if dist_upgrade:
        cmd.append('dist-upgrade')
    else:
        cmd.append('upgrade')
    try:
        cmd.extend(['-o', 'APT::Default-Release={0}'.format(kwargs['fromrepo'])])
    except KeyError:
        pass

    call = _call_apt(cmd)
    if call['retcode'] != 0:
        msg = 'Failed to get upgrades'
        for key in ('stderr', 'stdout'):
            if call[key]:
                msg += ': ' + call[key]
                break
        raise CommandExecutionError(msg)
    else:
        out = call['stdout']

    # rexp parses lines that look like the following:
    # Conf libxfont1 (1:1.4.5-1 Debian:testing [i386])
    rexp = re.compile('(?m)^Conf '
                      '([^ ]+) '          # Package name
                      r'\(([^ ]+)')       # Version
    keys = ['name', 'version']
    _get = lambda l, k: l[keys.index(k)]

    upgrades = rexp.findall(out)

    ret = {}
    for line in upgrades:
        name = _get(line, 'name')
        version_num = _get(line, 'version')
        ret[name] = version_num

    return ret
Utility function to get upgradable packages

    Sample return data:
    { 'pkgname': '1.2.3-45', ... }