[PATCH] srpm-excluded-arch.py enhancement
Dan HorĂ¡k
dan at danny.cz
Mon Feb 23 15:20:30 UTC 2015
On Mon, 23 Feb 2015 10:08:20 -0500 (EST)
Jakub Cajka <jcajka at redhat.com> wrote:
> Hello,
>
> I have prepared enhancement of srpm-excluded-arch.py based on
> sharkcz's ideas(if I'm not mistaken :) ). I have moved this script
yes, this is for https://fedorahosted.org/rel-eng/ticket/6064 and we
also discussed a possibility of adding a test-case. Jakub, thanks for
the patch.
Dan
> from optparse to argparse, added possibility to run this script over
> multiple paths/directories(for example updates and release, etc.) and
> prepare list of excluded packages based on most recent ENVR. Also is
> possible to issue warning(to stderr) if package have multiple
> versions present and state of exclusion have changed(to warn about
> possible unintentional changes). Command syntax should be the same as
> original version, except switch -w, which adds up mentioned warnings
> (outputted to stderr), and --path accepts more than one path now,
> expansion is done up to 3 levels using python glob.
>
> I hope it brings desired improvements( and no bugs :)), looking
> forward for any feedback,... Patch follows.
>
> Best regards,
> Jakub
>
>
> From b91af25ac1a89b4892cc1ffb4af60346cdb40eca Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Jakub=20=C4=8Cajka?= <jcajka at redhat.com>
> Date: Mon, 23 Feb 2015 15:57:48 +0100
> Subject: [PATCH] srpm-excluded-arch.py can check multiple paths
>
> ---
> scripts/srpm-excluded-arch.py | 97 +++++++++++++++++++++++++++++
> +------------- 1 file changed, 68 insertions(+), 29 deletions(-)
>
> diff --git a/scripts/srpm-excluded-arch.py
> b/scripts/srpm-excluded-arch.py index 2125517..718f7c2 100755
> --- a/scripts/srpm-excluded-arch.py
> +++ b/scripts/srpm-excluded-arch.py
> @@ -3,39 +3,54 @@
> # srpm-exlcuded-arch: is a tool to give you a list of packge names
> # that are excluded on the given arches. access to a srpm tree is
> # needed.
> #
> -# Copyright (C) 2008-2013 Red Hat, Inc.
> +# Copyright (C) 2008-2015 Red Hat, Inc.
> # SPDX-License-Identifier: GPL-2.0+
> #
> # Authors:
> # Dennis Gilmore <dennis at ausil.us>
> +# Jakub Cajka <jcajka at redhat.com>
>
> import rpm
> import os
> import sys
> -import optparse
> +import argparse
> import glob
> +import types
>
> -OptionParser = optparse.OptionParser
> -usage = "%prog [options]"
> -parser = OptionParser(usage=usage)
> -parser.add_option("-a", "--arches",
> - help="space or command separated list of arches to check for")
> -parser.add_option("--path", default='./',
> - help="path to dir with srpms, default current directory")
> -(options, args) = parser.parse_args()
> -arches = options.arches
> -if arches == None:
> - print "You must pass arches to check for in."
> - sys.exit()
> -else:
> - if arches.find(',') == -1:
> - arches = arches.split(' ')
> - else:
> - arches = arches.split(',')
> -
> -srpm_path = options.path
> -srpms = glob.glob('%s/*.rpm' % srpm_path)
> -pkglist = []
> +def rpmvercmp((e1, v1, r1), (e2, v2, r2)):
> + """find out which build is newer"""
> + rc = rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
> + if rc == 1:
> + #first evr wins
> + return 1
> + elif rc == 0:
> + #same evr
> + return 0
> + else:
> + #second evr wins
> + return -1
> +
> +parser = argparse.ArgumentParser()
> +parser.add_argument('-a', '--arches', nargs='+', required=True)
> +parser.add_argument('-w', '--withcheck', action='store_true')
> +parser.add_argument('--path', nargs='+', default='./')
> +args = parser.parse_args()
> +
> +# be previous version compatible i.e. -a "arch arch ..."
> +if len(args.arches) == 1 and type(args.arches[0]) is
> types.StringType:
> + if args.arches[0].find(',') == -1:
> + args.arches = args.arches[0].split(' ')
> + else:
> + args.arches = args.arches[0].split(',')
> +
> +arches = args.arches
> +srpms = []
> +
> +for srpm_path in args.path:
> + srpms += glob.glob('%s/*/*/*.rpm' % srpm_path)
> + srpms += glob.glob('%s/*/*.rpm' % srpm_path)
> + srpms += glob.glob('%s/*.rpm' % srpm_path)
> +pkglist = {}
>
> for srpm in srpms:
> """Return the rpm header."""
> @@ -52,14 +67,38 @@ for srpm in srpms:
> if arch not in hdr[rpm.RPMTAG_EXCLUSIVEARCH]:
> if arch not in ExcludeArch:
> ExcludeArch.append(arch)
> - if ExcludeArch == arches:
> - pkgname = hdr[rpm.RPMTAG_NAME]
> - if pkgname not in pkglist:
> - pkglist.append(pkgname)
> - #print "Excluding: %s" % pkgname
> +
> + pkgname = hdr[rpm.RPMTAG_NAME]
> + pkgevr = ('0'if not hdr[rpm.RPMTAG_EPOCH] else str(hdr
> [rpm.RPMTAG_EPOCH]),
> + hdr[rpm.RPMTAG_VERSION],
> + hdr[rpm.RPMTAG_RELEASE])
> + if not pkgname in pkglist:
> + pkglist[pkgname] = []
> + excluded = set(ExcludeArch) == set(arches)
> +
> + pkglist[pkgname].append({'evr':pkgevr, 'excluded':excluded})
>
> output = ""
> +warning = ""
> +
> for pkg in pkglist:
> - output += pkg + " "
> + pkglist[pkg].sort(cmp=rpmvercmp, key=lambda x: x['evr'],
> reverse=True)
> + if pkglist[pkg][0]['excluded']:
> + output += pkg + " "
> +
> + if args.withcheck:
> + last = None
> + change = ""
> + for srpm in pkglist[pkg]:
> + if last and last['excluded'] != srpm['excluded']:
> + change += str(srpm)+'->'+str(last)
> + last = srpm
> + if change:
> + warning += pkg + " " + change + "\n"
> +
> +if args.withcheck and warning:
> + warning = "WARNING: Fellowing packages have changed their
> exclude state:\n"+warning
> + sys.stderr.write(warning)
>
> print output
> +
> --
> 1.9.3
> _______________________________________________
> rel-eng mailing list
> rel-eng at lists.fedoraproject.org
> https://admin.fedoraproject.org/mailman/listinfo/rel-eng
More information about the rel-eng
mailing list