Ejemplo n.º 1
0
def _notice_to_errata(notice):
    """
    Notice metadata examples:

    packages:

     'pkglist': [
        {'name': 'Red Hat Enterprise Linux Server (v. 6 for 64-bit x86_64)',
         'packages': [
            {'arch': 'x86_64',
             'epoch': '0',
             'filename': 'xorg-x11-drv-fbdev-0.4.3-16.el6.x86_64.rpm',
             'name': 'xorg-x11-drv-fbdev',
             'release': '16.el6',
             'src': 'xorg-x11-drv-fbdev-0.4.3-16.el6.src.rpm',
             'sum': ('sha256', '8f3da83bb19c3776053c543002c9...'),
             'version': '0.4.3'},
             ...
        },
        ...
     ]

    cve in notice_metadata["references"]:

    {'href': 'https://www.redhat.com/security/data/cve/CVE-2013-1994.html',
     'id': 'CVE-2013-1994',
     'title': 'CVE-2013-1994',
     'type': 'cve'}
    """
    nmd = notice.get_metadata()

    errata = dict(advisory=nmd["update_id"],
                  synopsis=nmd["title"],
                  description=nmd["description"],
                  update_date=nmd["updated"],
                  issue_date=nmd["issued"],
                  solution=nmd["solution"],
                  type=nmd["type"],
                  severity=nmd.get("severity", "N/A"))

    errata["bzs"] = [
        normalize_bz(bz) for bz in filter(
            lambda r: r.get("type") == "bugzilla", nmd.get("references", []))
    ]
    errata["cves"] = [
        normalize_cve(cve) for cve in filter(lambda r: r.get("type") == "cve",
                                             nmd.get("references", []))
    ]

    errata["packages"] = RU.concat(nps["packages"]
                                   for nps in nmd.get("pkglist", []))

    errata["package_names"] = ','.join(
        RU.uniq(p["name"] for p in errata["packages"]))
    errata["url"] = rpmkit.updateinfo.utils.errata_url(errata["advisory"])

    return errata
Ejemplo n.º 2
0
    def test_00(self):
        ps = PACKAGES_0 + PACKAGES_1 + PACKAGES_2 + PACKAGES_3
        random.shuffle(ps)

        ps0 = [PACKAGES_0[0], PACKAGES_1[0], PACKAGES_2[0], PACKAGES_3[0]]

        updates = U.concat(us for us in RU.find_updates_g(ps, ps0))
        expected = sorted(PACKAGES_0[1:] + PACKAGES_1[1:] +
                          PACKAGES_2[1:] + PACKAGES_3[1:])

        self.assertEquals(updates, expected)
Ejemplo n.º 3
0
def _notice_to_errata(notice):
    """
    Notice metadata examples:

    packages:

     'pkglist': [
        {'name': 'Red Hat Enterprise Linux Server (v. 6 for 64-bit x86_64)',
         'packages': [
            {'arch': 'x86_64',
             'epoch': '0',
             'filename': 'xorg-x11-drv-fbdev-0.4.3-16.el6.x86_64.rpm',
             'name': 'xorg-x11-drv-fbdev',
             'release': '16.el6',
             'src': 'xorg-x11-drv-fbdev-0.4.3-16.el6.src.rpm',
             'sum': ('sha256', '8f3da83bb19c3776053c543002c9...'),
             'version': '0.4.3'},
             ...
        },
        ...
     ]

    cve in notice_metadata["references"]:

    {'href': 'https://www.redhat.com/security/data/cve/CVE-2013-1994.html',
     'id': 'CVE-2013-1994',
     'title': 'CVE-2013-1994',
     'type': 'cve'}
    """
    nmd = notice.get_metadata()

    errata = dict(advisory=nmd["update_id"], synopsis=nmd["title"],
                  description=nmd["description"], update_date=nmd["updated"],
                  issue_date=nmd["issued"], solution=nmd["solution"],
                  type=nmd["type"], severity=nmd.get("severity", "N/A"))

    errata["bzs"] = [normalize_bz(bz) for bz in
                     filter(lambda r: r.get("type") == "bugzilla",
                            nmd.get("references", []))]
    errata["cves"] = [normalize_cve(cve) for cve in
                      filter(lambda r: r.get("type") == "cve",
                             nmd.get("references", []))]

    errata["packages"] = RU.concat(nps["packages"] for nps in
                                   nmd.get("pkglist", []))

    errata["package_names"] = ','.join(RU.uniq(p["name"] for p
                                               in errata["packages"]))
    errata["url"] = rpmkit.updateinfo.utils.errata_url(errata["advisory"])

    return errata
Ejemplo n.º 4
0
def complement_rpm_metadata_in_channels(pkg, channels=[], options=[]):
    """
    Get missing package metadata and return a dict by searching RPMs in given
    software channels.

    :param pkg: A dict contains RPM basic information such as name, version,
        release, ...
    :param channels: List of software channels to search RPMs
    :param options: List of option strings passed to
        :function:`rpmkti.swapi.call`, e.g. ['--verbose', '--server ...']

    :return: Updated dict
    """
    __validate_pkg(pkg)

    LOG.info("Try searching possible RPMs in channels w/ the API, "
             "channel.software.listAllPackages in: " + ", ".join(channels))
    ps = RU.concat(list_rpms_in_channel(pkg, c, options) for c in channels)

    if ps:
        return [_normalize(p) for p in ps]

    LOG.warn("Failed to complement RPM metadata: " + pkg["label"])
    return [pkg]
Ejemplo n.º 5
0
def complement_rpm_metadata_in_channels(pkg, channels=[], options=[]):
    """
    Get missing package metadata and return a dict by searching RPMs in given
    software channels.

    :param pkg: A dict contains RPM basic information such as name, version,
        release, ...
    :param channels: List of software channels to search RPMs
    :param options: List of option strings passed to
        :function:`rpmkti.swapi.call`, e.g. ['--verbose', '--server ...']

    :return: Updated dict
    """
    __validate_pkg(pkg)

    LOG.info("Try searching possible RPMs in channels w/ the API, "
             "channel.software.listAllPackages in: " + ", ".join(channels))
    ps = RU.concat(list_rpms_in_channel(pkg, c, options) for c in channels)

    if ps:
        return [_normalize(p) for p in ps]

    LOG.warn("Failed to complement RPM metadata: " + pkg["label"])
    return [pkg]
Ejemplo n.º 6
0
def ucat(xss):
    return RU.uniq(RU.concat(xss))
Ejemplo n.º 7
0
def ucat(xss):
    return RU.uniq(RU.concat(xss))
Ejemplo n.º 8
0
def main(argv=sys.argv):
    default_format = "{name},{version},{release},{arch},{epoch}"
    defaults = dict(verbose=0, format=None, details=False, sw_options=[],
                    input=None, output=None, latest=False, all=False,
                    channels=[], nprocs=_NCPUS)

    p = optparse.OptionParser("""%prog [Options...] [RPM_0 [RPM_1 ...]]

where RPM_N = <name>-<version>-<release>[-<arch>]

Examples:

$ identrpm --format "{name},{version},{release},{arch},{epoch}" \
>   autoconf-2.59-12.noarch
autoconf,2.59,12,noarch,0

$ identrpm --details --format "{name}: {summary}" autoconf-2.59-12
autoconf: A GNU tool for automatically configuring source code.
    """)
    p.set_defaults(**defaults)

    p.add_option("-i", "--input",
                 help="Packages list file path (output of 'rpm -qa')")
    p.add_option("-o", "--output",
                 help="Output file path [stdout]. It must be ends w/ .json, "
                      "yaml, etc.")
    p.add_option("-F", "--format",
                 help="Output format, e.g %s" % default_format)
    p.add_option("", "--details", action="store_true",
                 help="Get extra information other than RPM's N, V, R, E, A")
    p.add_option("", "--latest", action="store_true",
                 help="Output only the latest RPMs instead of oldest RPMs")
    p.add_option("", "--all", action="store_true", help="Output all RPMs")
    p.add_option("", "--channel", action="append", dest="channels",
                 help="Specify software channels to search RPMs, "
                      "ex. --channel='rhel-x86_64-server-6' "
                      "--channel='rhel-x86_64-server-optional-6'")
    p.add_option("", "--sw-options", action="append",
                 help="Options passed to swapi, can be specified multiple"
                      "times.")
    p.add_option("", "--nprocs", type="int",
                 help="Number of parallel processes to find RPMs [%default]")
    p.add_option("-v", "--verbose", action="count", help="Verbose mode")
    p.add_option("-D", "--debug", action="store_const", dest="verbose",
                 const=2, help="Debug mode")

    (options, packages) = p.parse_args(argv[1:])

    init_log(options.verbose)

    if options.input:
        packages = load_packages(options.input)
    else:
        if not packages:
            p.print_usage()
            sys.exit(1)

    (pss, failed) = identify_rpms(packages, options.details, options.latest,
                                  options.channels, options.sw_options,
                                  options.nprocs)
    if options.all:
        print_outputs(RU.concat(pss), options.format, options.output)
    else:
        print_outputs([ps[0] for ps in pss if ps], options.format,
                      options.output)
Ejemplo n.º 9
0
def main(argv=sys.argv):
    default_format = "{name},{version},{release},{arch},{epoch}"
    defaults = dict(verbose=0,
                    format=None,
                    details=False,
                    sw_options=[],
                    input=None,
                    output=None,
                    latest=False,
                    all=False,
                    channels=[],
                    nprocs=_NCPUS)

    p = optparse.OptionParser("""%prog [Options...] [RPM_0 [RPM_1 ...]]

where RPM_N = <name>-<version>-<release>[-<arch>]

Examples:

$ identrpm --format "{name},{version},{release},{arch},{epoch}" \
>   autoconf-2.59-12.noarch
autoconf,2.59,12,noarch,0

$ identrpm --details --format "{name}: {summary}" autoconf-2.59-12
autoconf: A GNU tool for automatically configuring source code.
    """)
    p.set_defaults(**defaults)

    p.add_option("-i",
                 "--input",
                 help="Packages list file path (output of 'rpm -qa')")
    p.add_option("-o",
                 "--output",
                 help="Output file path [stdout]. It must be ends w/ .json, "
                 "yaml, etc.")
    p.add_option("-F",
                 "--format",
                 help="Output format, e.g %s" % default_format)
    p.add_option("",
                 "--details",
                 action="store_true",
                 help="Get extra information other than RPM's N, V, R, E, A")
    p.add_option("",
                 "--latest",
                 action="store_true",
                 help="Output only the latest RPMs instead of oldest RPMs")
    p.add_option("", "--all", action="store_true", help="Output all RPMs")
    p.add_option("",
                 "--channel",
                 action="append",
                 dest="channels",
                 help="Specify software channels to search RPMs, "
                 "ex. --channel='rhel-x86_64-server-6' "
                 "--channel='rhel-x86_64-server-optional-6'")
    p.add_option("",
                 "--sw-options",
                 action="append",
                 help="Options passed to swapi, can be specified multiple"
                 "times.")
    p.add_option("",
                 "--nprocs",
                 type="int",
                 help="Number of parallel processes to find RPMs [%default]")
    p.add_option("-v", "--verbose", action="count", help="Verbose mode")
    p.add_option("-D",
                 "--debug",
                 action="store_const",
                 dest="verbose",
                 const=2,
                 help="Debug mode")

    (options, packages) = p.parse_args(argv[1:])

    init_log(options.verbose)

    if options.input:
        packages = load_packages(options.input)
    else:
        if not packages:
            p.print_usage()
            sys.exit(1)

    (pss, failed) = identify_rpms(packages, options.details, options.latest,
                                  options.channels, options.sw_options,
                                  options.nprocs)
    if options.all:
        print_outputs(RU.concat(pss), options.format, options.output)
    else:
        print_outputs([ps[0] for ps in pss if ps], options.format,
                      options.output)