[Piuparts-devel] [Git][debian/piuparts][develop] 3 commits: Make a valid pkgsummary entry for an "invalid" pkg
Holger Levsen (@holger)
gitlab at salsa.debian.org
Mon Jul 26 13:45:31 BST 2021
Holger Levsen pushed to branch develop at Debian / piuparts
Commits:
1474060d by David Steele at 2021-07-26T14:44:59+02:00
Make a valid pkgsummary entry for an "invalid" pkg
pkgsummary was assuming that package entries would never be made with an
"invalid" state. In that case, the entry would end up with the default
url "invalid url", which never should be the result. When an actual
package with an "invalid" state is entered, the eventual global summary
creation will fail on the bad url. Fix by always replacing a default
entry.
Test included.
Signed-off-by: Holger Levsen <holger at layer-acht.org>
- - - - -
4f1448c6 by David Steele at 2021-07-26T14:45:04+02:00
Remove Python2 support from pkgsummary
six needs to die.
Signed-off-by: Holger Levsen <holger at layer-acht.org>
- - - - -
c1aebaf9 by David Steele at 2021-07-26T14:45:09+02:00
Reformat pkgsummary
Fix some of the damage from 9096975.
Signed-off-by: Holger Levsen <holger at layer-acht.org>
- - - - -
2 changed files:
- piupartslib/pkgsummary.py
- tests/test_pkgsummary.py
Changes:
=====================================
piupartslib/pkgsummary.py
=====================================
@@ -86,42 +86,59 @@ from collections import namedtuple, defaultdict
import os
-import six
+INVALID_URL = "invalid url"
class SummaryException(Exception):
pass
+
SUMMID = "Piuparts Package Test Results Summary"
SUMMVER = "1.0"
-DEFSEC = 'overall'
+DEFSEC = "overall"
-FlagInfo = namedtuple('FlagInfo', ['word', 'priority', 'states'])
+FlagInfo = namedtuple("FlagInfo", ["word", "priority", "states"])
flaginfo = {
- 'F': FlagInfo('Failed', 0, ["failed-testing"]),
- 'X': FlagInfo('Blocked', 1, [
- "cannot-be-tested",
- "dependency-failed-testing",
- "dependency-cannot-be-tested",
- "dependency-does-not-exist",
- ]),
- 'W': FlagInfo('Waiting', 2, [
- "waiting-to-be-tested",
- "waiting-for-dependency-to-be-tested",
- ]),
- 'P': FlagInfo('Passed', 3, [
- "essential-required",
- "successfully-tested",
- ]),
- '-': FlagInfo('Unknown', 4, [
- "does-not-exist",
- "unknown",
- ]),
+ "F": FlagInfo("Failed", 0, ["failed-testing"]),
+ "X": FlagInfo(
+ "Blocked",
+ 1,
+ [
+ "cannot-be-tested",
+ "dependency-failed-testing",
+ "dependency-cannot-be-tested",
+ "dependency-does-not-exist",
+ ],
+ ),
+ "W": FlagInfo(
+ "Waiting",
+ 2,
+ [
+ "waiting-to-be-tested",
+ "waiting-for-dependency-to-be-tested",
+ ],
+ ),
+ "P": FlagInfo(
+ "Passed",
+ 3,
+ [
+ "essential-required",
+ "successfully-tested",
+ ],
+ ),
+ "-": FlagInfo(
+ "Unknown",
+ 4,
+ [
+ "does-not-exist",
+ "unknown",
+ ],
+ ),
}
-state2flg = dict([(y, x[0]) for x in six.iteritems(flaginfo) for y in x[1].states])
+state2flg = dict([(y, x[0]) for x in flaginfo.items() for y in x[1].states])
def worst_flag(*flags):
@@ -130,7 +147,7 @@ def worst_flag(*flags):
except KeyError:
raise SummaryException("Unknown flag in " + flags.__repr__())
- return(flag)
+ return flag
def get_flag(state):
@@ -139,7 +156,7 @@ def get_flag(state):
except KeyError:
raise SummaryException("Unknown state - " + state)
- return(flag)
+ return flag
def new_summary():
@@ -147,31 +164,34 @@ def new_summary():
utcdate = " ".join(cdate_array[:-1] + ["UTC"] + [cdate_array[-1]])
# define the packages struct. The default should never be the one added
- dfltentry = ['-', 0, 'invalid url']
+ dfltentry = ["-", 0, INVALID_URL]
pkgstruct = defaultdict(lambda: defaultdict(lambda: dfltentry))
- return({
+ return {
"_id": SUMMID,
- "_version": SUMMVER,
- "_date": utcdate,
- "_comment": "Debian Piuparts Package Results - "
- "https://salsa.debian.org/debian/piuparts/raw/"
- "develop/piupartslib/pkgsummary.py",
- "_type": "source",
- "packages": pkgstruct,
- })
+ "_version": SUMMVER,
+ "_date": utcdate,
+ "_comment": "Debian Piuparts Package Results - "
+ "https://salsa.debian.org/debian/piuparts/raw/"
+ "develop/piupartslib/pkgsummary.py",
+ "_type": "source",
+ "packages": pkgstruct,
+ }
def add_summary(summary, rep_sec, pkg, flag, block_cnt, url):
- if not flag in flaginfo or not isinstance(block_cnt, int) \
- or not url.startswith('http'):
+ if (
+ not flag in flaginfo
+ or not isinstance(block_cnt, int)
+ or not url.startswith("http")
+ ):
raise SummaryException("Invalid summary argument")
pdict = summary["packages"]
[old_flag, old_cnt, old_url] = pdict[pkg][rep_sec]
block_cnt = max(block_cnt, old_cnt)
- if old_flag != worst_flag(old_flag, flag):
+ if old_flag != worst_flag(old_flag, flag) or old_url == INVALID_URL:
pdict[pkg][rep_sec] = [flag, block_cnt, url]
else:
pdict[pkg][rep_sec] = [old_flag, block_cnt, old_url]
@@ -194,9 +214,9 @@ def merge_summary(gbl_summ, sec_summ):
def tooltip(summary, pkg):
"""Returns e.g. "Failed in testing and stable, blocking 5 packages"."""
- tip = ''
+ tip = ""
- pkgdict = summary['packages']
+ pkgdict = summary["packages"]
if pkg in pkgdict:
flag, block_cnt, url = pkgdict[pkg][DEFSEC]
@@ -207,42 +227,43 @@ def tooltip(summary, pkg):
tip = flaginfo[flag].word
if len(applicable) > 2:
- tip += ' in ' + ', '.join(applicable[:-1]) + ' and ' + applicable[-1]
+ tip += " in " + ", ".join(applicable[:-1]) + " and " + applicable[-1]
elif len(applicable) == 2:
- tip += ' in ' + ' and '.join(applicable)
+ tip += " in " + " and ".join(applicable)
elif len(applicable) == 1:
- tip += ' in ' + applicable[0]
+ tip += " in " + applicable[0]
if block_cnt:
tip += ", blocking %d packages" % block_cnt
- tip += '.'
+ tip += "."
return tip
def write_summary(summary, fname):
- with open(fname + '.tmp', 'w') as fl:
+ with open(fname + ".tmp", "w") as fl:
json.dump(summary, fl, sort_keys=True, indent=1)
- os.rename(fname + '.tmp', fname)
+ os.rename(fname + ".tmp", fname)
def read_summary(fname):
- with open(fname, 'r') as fl:
+ with open(fname, "r") as fl:
result = json.load(fl)
if result["_id"] != SUMMID or result["_version"] != SUMMVER:
- raise SummaryException('Summary JSON header mismatch')
+ raise SummaryException("Summary JSON header mismatch")
return result
-if __name__ == '__main__':
+
+if __name__ == "__main__":
import sys
# read a global summary file and return DDPO info by package
summary = read_summary(sys.argv[1])
- for pkg in summary['packages']:
- flag, blocked, url = summary['packages'][pkg][DEFSEC]
+ for pkg in summary["packages"]:
+ flag, blocked, url = summary["packages"][pkg][DEFSEC]
print(pkg, flag, url, tooltip(summary, pkg))
=====================================
tests/test_pkgsummary.py
=====================================
@@ -104,6 +104,11 @@ class PkgSummaryAddTests(unittest.TestCase):
pkgsummary.add_summary(self.summ, 'dist', 'pkg', 'F', 2, 'http://foo')
self.assertEqual(2, self.summ['packages']['pkg']['dist'][1])
+ def testSummAddInvalid(self):
+ pkgsummary.add_summary(self.summ, 'dist', 'pkg', '-', 0, 'http://foo')
+ print(self.summ['packages']['pkg']['dist'][2])
+ self.assertTrue("http" in self.summ['packages']['pkg']['dist'][2])
+
def testSummMerge(self):
pkgsummary.add_summary(self.summ, 'dist', 'pkg', 'X', 0, 'http://foo')
View it on GitLab: https://salsa.debian.org/debian/piuparts/-/compare/89182d0ca342b129efc5b2750230c0e6f97b8621...c1aebaf91603a0e1c6055142bc04c61f37b3f8b3
--
View it on GitLab: https://salsa.debian.org/debian/piuparts/-/compare/89182d0ca342b129efc5b2750230c0e6f97b8621...c1aebaf91603a0e1c6055142bc04c61f37b3f8b3
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/piuparts-devel/attachments/20210726/8d2960a5/attachment-0001.htm>
More information about the Piuparts-devel
mailing list