Ejemplo n.º 1
0
def format_pkg_list(packages, versions_as_list, attr):
    '''
    Formats packages according to parameters for list_pkgs.
    '''
    ret = copy.deepcopy(packages)
    if attr:
        requested_attr = set(['epoch', 'version', 'release', 'arch',
                              'install_date', 'install_date_time_t'])

        if attr != 'all':
            requested_attr &= set(attr + ['version'])

        for name in ret:
            versions = []
            for all_attr in ret[name]:
                filtered_attr = {}
                for key in requested_attr:
                    if all_attr[key]:
                        filtered_attr[key] = all_attr[key]
                versions.append(filtered_attr)
            ret[name] = versions
        return ret

    for name in ret:
        ret[name] = [format_version(d['epoch'], d['version'], d['release'])
                     for d in ret[name]]
    if not versions_as_list:
        stringify(ret)
    return ret
Ejemplo n.º 2
0
def format_pkg_list(packages, versions_as_list, attr):
    """
    Formats packages according to parameters for list_pkgs.
    """
    ret = copy.deepcopy(packages)
    if attr:
        ret_attr = {}
        requested_attr = {
            "epoch",
            "version",
            "release",
            "arch",
            "install_date",
            "install_date_time_t",
        }

        if attr != "all":
            requested_attr &= set(attr + ["version"] + ["arch"])

        for name in ret:
            if "pkg.parse_arch" in __salt__:
                _parse_arch = __salt__["pkg.parse_arch"](name)
            else:
                _parse_arch = {"name": name, "arch": None}
            _name = _parse_arch["name"]
            _arch = _parse_arch["arch"]

            versions = []
            pkgname = None
            for all_attr in ret[name]:
                filtered_attr = {}
                for key in requested_attr:
                    if key in all_attr:
                        filtered_attr[key] = all_attr[key]
                versions.append(filtered_attr)
                if _name and filtered_attr.get("arch", None) == _arch:
                    pkgname = _name
            ret_attr.setdefault(pkgname or name, []).extend(versions)
        return ret_attr

    for name in ret:
        ret[name] = [
            format_version(d["epoch"], d["version"], d["release"])
            for d in ret[name]
        ]
    if not versions_as_list:
        stringify(ret)
    return ret
Ejemplo n.º 3
0
def format_pkg_list(packages, versions_as_list, attr):
    '''
    Formats packages according to parameters for list_pkgs.
    '''
    ret = copy.deepcopy(packages)
    if attr:
        ret_attr = {}
        requested_attr = set([
            'epoch', 'version', 'release', 'arch', 'install_date',
            'install_date_time_t'
        ])

        if attr != 'all':
            requested_attr &= set(attr + ['version'] + ['arch'])

        for name in ret:
            _parse_arch_from_name = __salt__.get(
                'pkg.parse_arch_from_name', lambda pkgname: {
                    'name': pkgname,
                    'arch': None
                })
            name_arch_d = _parse_arch_from_name(name)
            _name = name_arch_d['name']
            _arch = name_arch_d['arch']

            versions = []
            pkgname = None
            for all_attr in ret[name]:
                filtered_attr = {}
                for key in requested_attr:
                    if key in all_attr:
                        filtered_attr[key] = all_attr[key]
                versions.append(filtered_attr)
                if _name and filtered_attr.get('arch', None) == _arch:
                    pkgname = _name
            ret_attr.setdefault(pkgname or name, []).extend(versions)
        return ret_attr

    for name in ret:
        ret[name] = [
            format_version(d['epoch'], d['version'], d['release'])
            for d in ret[name]
        ]
    if not versions_as_list:
        stringify(ret)
    return ret