----- Original Message -----
From: "Dennis Gilmore" <dennis(a)ausil.us>
To: rel-eng(a)lists.fedoraproject.org
Cc: "Jakub Cajka" <jcajka(a)redhat.com>
Sent: Monday, April 20, 2015 5:40:05 PM
Subject: Re: [PATCH] srpm-excluded-arch.py enhancement
Please separate the argparse change from the functionality change
Dennis
Sorry for slow response...
Fixed few typos, preserved/added help. Split patches follow.
Jakub
On Monday, February 23, 2015 10:08:20 AM Jakub Cajka 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 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 fcd8cb19caff8d7b2ae9eaa91c152ab100df91fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20=C4=8Cajka?= <jcajka(a)redhat.com>
Date: Thu, 21 May 2015 16:07:02 +0200
Subject: [PATCH] Move srpm-excluded-arch.py to argparse
---
scripts/srpm-excluded-arch.py | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/scripts/srpm-excluded-arch.py b/scripts/srpm-excluded-arch.py
index 2125517..1b89361 100755
--- a/scripts/srpm-excluded-arch.py
+++ b/scripts/srpm-excluded-arch.py
@@ -3,37 +3,37 @@
# 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(a)ausil.us>
+# Jakub Cajka <jcajka(a)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(',')
+parser = argparse.ArgumentParser()
+parser.add_argument('-a', '--arches', nargs='+', required=True,
+ help='space or command separated list of arches to check
for')
+parser.add_argument('--path', nargs='?', default='./',
+ help='path to dir with srpms, default current directory')
+args = parser.parse_args()
-srpm_path = options.path
+# 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
+
+srpm_path = args.path
srpms = glob.glob('%s/*.rpm' % srpm_path)
pkglist = []
--
1.9.3
From b666a70c26068014b1f75cfceac7b6e0b7878536 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20=C4=8Cajka?= <jcajka(a)redhat.com>
Date: Mon, 25 May 2015 10:37:10 +0200
Subject: [PATCH] srpm-excluded-arch.py can check multiple paths
---
scripts/srpm-excluded-arch.py | 66 +++++++++++++++++++++++++++++++++++--------
1 file changed, 54 insertions(+), 12 deletions(-)
diff --git a/scripts/srpm-excluded-arch.py b/scripts/srpm-excluded-arch.py
index 1b89361..94613a4 100755
--- a/scripts/srpm-excluded-arch.py
+++ b/scripts/srpm-excluded-arch.py
@@ -17,11 +17,26 @@ import argparse
import glob
import types
+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,
- help='space or command separated list of arches to check
for')
-parser.add_argument('--path', nargs='?', default='./',
- help='path to dir with srpms, default current directory')
+ help='space or comma separated list of arches to check for')
+parser.add_argument('-w', '--withcheck', action='store_true',
+ help='report changes in package exclude status')
+parser.add_argument('--path', nargs='+', default='./',
+ help='path to dir(s) with srpms, default current directory')
args = parser.parse_args()
# be previous version compatible i.e. -a "arch arch ..."
@@ -32,10 +47,13 @@ if len(args.arches) == 1 and type(args.arches[0]) is
types.StringType:
args.arches = args.arches[0].split(',')
arches = args.arches
+srpms = []
-srpm_path = args.path
-srpms = glob.glob('%s/*.rpm' % srpm_path)
-pkglist = []
+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 +70,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: Following packages have changed their exclude
state:\n"+warning
+ sys.stderr.write(warning)
print output
+
--
1.9.3