From 3eca826acbe5455f881526b45b757ed8669a42de Mon Sep 17 00:00:00 2001 From: Alex Iribarren Date: Apr 07 2021 13:45:36 +0000 Subject: Convert to python 3 --- diff --git a/src/bin/kojitop b/src/bin/kojitop index 925786a..2b47946 100755 --- a/src/bin/kojitop +++ b/src/bin/kojitop @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python3 import koji import xml.dom.minidom @@ -19,17 +19,20 @@ def count_uniq(seq): def value(v): if "string" in v: - v = '"%s"' % (v["string"][0],) + try: + v = '"%s"' % (list(v["string"][0].values())[0][0],) + except IndexError: + v = '""' elif "boolean" in v: - v = v["boolean"][0] + v = list(v["boolean"][0].values())[0][0] if v.lower() in ["", "0", "false", "no"]: v = "False" elif v.lower() in ["1", "true", "yes"]: v = "True" elif "int" in v: - v = "%d" % (int(v["int"][0])) + v = "%d" % (int(list(v["int"][0].values())[0][0])) elif "double" in v: - v = "%f" % (float(v["double"][0])) + v = "%f" % (float(list(v["double"][0].values())[0][0])) elif "nil" in v: v = "nil" elif "array" in v: @@ -38,7 +41,7 @@ def value(v): assert len(v["struct"]) == 1 s = [] for m in v["struct"][0].get("member", []): - s.append((m["name"][0], value(m["value"][0]))) + s.append((list(m["name"][0].values())[0][0], value(m["value"][0]))) v = "{%s}" % (", ".join("%s=%s" % (n, v) for n, v in s),) else: raise Exception("gargh %s" % (pprint.pformat(v))) @@ -58,8 +61,8 @@ def params(d): def xmltodict(xmlstring): doc = xml.dom.minidom.parseString(xmlstring) d = ettodict(doc.documentElement) - if d.keys() == ["methodCall"]: - return "%s(%s)" % (d["methodCall"]["methodName"][0], + if "methodCall" in d: + return "%s(%s)" % (list(d["methodCall"]["methodName"][0].values())[0][0], ", ".join(params(d))) else: return d @@ -146,24 +149,24 @@ for h in taskbyhost: for hn in sorted(hostbyname): hi = hostinfo[hn] load = sum(float(t["weight"]) for t in taskbyhost[hostbyname[hn]]) - print "%s %.1f total %.1f/%.1f %s" % (hn, load, float(hi["task_load"]), float(hi["capacity"]), "R" if hi["ready"] else "-") + print("%s %.1f total %.1f/%.1f %s" % (hn, load, float(hi["task_load"]), float(hi["capacity"]), "R" if hi["ready"] else "-")) for t in sorted(taskbyhost[hostbyname[hn]], key=lambda x: -float(x["weight"])): - print " %s %8d %.1f %6s %7s %s" % ( + print(" %s %8d %.1f %6s %7s %s" % ( koji.TASK_STATES[t["state"]][:2], int(t["id"]), float(t["weight"]), howlong(t["start_time"]), t["arch"], - pretty(t["request"])) - print "" + pretty(t["request"]))) + print() states = [koji.TASK_STATES["FREE"]] tasks = session.listTasks(opts={"state": states, "channel_id": channel}) tasks_by_arch = count_uniq((t["method"], t["arch"]) for t in tasks) -print "Tasks available:" +print("Tasks available:") if tasks_by_arch == []: - print " (none)" + print(" (none)") else: for m, a in sorted(tasks_by_arch): - print " %3d %7s %s" % (tasks_by_arch[m, a], a, m) + print(" %3d %7s %s" % (tasks_by_arch[m, a], a, m))