Skip to content

Commit 5cd011f

Browse files
committed
Fixed some non Python3 compliant code
1 parent 3f5a513 commit 5cd011f

File tree

2 files changed

+51
-34
lines changed

2 files changed

+51
-34
lines changed

factory/tools/analyze_entries

+33-20
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def blockprint(title, d, p, pd):
8282
title (str): The title of the block.
8383
d (dict): Dictionary containing detailed metrics.
8484
p (int): Parameter used in formatting the output.
85-
pd (dict): Dictionary containing overall metrics for comparison.
85+
pd (dict, None): Dictionary containing overall metrics for comparison.
8686
"""
87-
if pd != 0:
87+
if pd is not None:
8888
s = " - %.1f%% of total" % (float(d["glideins"]) / float(pd["glideins"]) * 100.0)
8989
t = ""
9090
else:
@@ -191,16 +191,16 @@ def lineprint(entry_name, entry, g_entry, g, to_be_printed, attr_list, sort_attr
191191
s = "total_time"
192192

193193
# For Sorting
194-
list = dict(entry, **g_entry) # combine the two dictionaries
194+
e_list = dict(entry, **g_entry) # combine the two dictionaries
195195
div = 1
196196
if attr_list[sort_attribute] in ["FailedNr", "JobsNr_None"]:
197197
div = float(g_entry["glideins"])
198198
elif attr_list[sort_attribute] in ["validation_All", "validation", "idle", "wst", "badput"]:
199199
div = float(entry[s])
200200
if attr_list[sort_attribute] == "wst":
201-
sorter = int((float(list["waste"]) / div) * 100)
201+
sorter = int((float(e_list["waste"]) / div) * 100)
202202
else:
203-
sorter = int((float(list[attr_list[sort_attribute]]) / div) * 100)
203+
sorter = int((float(e_list[attr_list[sort_attribute]]) / div) * 100)
204204

205205
if totals is not None:
206206
ekeys = ("FailedNr", "validation_All", "JobsNr_None", s)
@@ -297,7 +297,7 @@ USAGE:
297297

298298
# flags
299299
x = 24
300-
dir = os.getcwd()
300+
w_dir = os.getcwd()
301301
sorting = 0
302302
fe_sorting = 0
303303
sort_attribute = 0
@@ -318,7 +318,7 @@ USAGE:
318318
if o == "-x":
319319
x = a
320320
elif o == "--source":
321-
dir = a
321+
w_dir = a
322322
elif o in ("-h", "-help"):
323323
print(usage)
324324
return
@@ -411,10 +411,10 @@ USAGE:
411411
"wastemill_data": "rrd_Log_Completed_WasteTime.xml",
412412
}
413413

414-
if "http" in dir:
415-
file_dir = os.path.join(dir)
414+
if "http" in w_dir:
415+
file_dir = os.path.join(w_dir)
416416
else:
417-
file_dir = os.path.join(dir, "monitor")
417+
file_dir = os.path.join(w_dir, "monitor")
418418
if not os.path.isdir(file_dir):
419419
# Try RPM location
420420
rpmdir = "/var/lib/gwms-factory/work-dir"
@@ -423,17 +423,20 @@ USAGE:
423423
print("\nCannot open", file_dir)
424424
print("Please set --source to the factory work dir and try again.")
425425
sys.exit(1)
426-
if dir != os.getcwd():
426+
if w_dir != os.getcwd():
427427
# Directory explicitly set, print warning
428428
print("\nWARNING: Cannot open", file_dir)
429429
print("Using RPM default %s instead" % rpmfile_dir)
430-
dir = rpmdir
430+
w_dir = rpmdir
431431
file_dir = rpmfile_dir
432432

433433
for name, xml in rrd_list.items():
434434
try:
435435
file_loc = os.path.join(file_dir, xml)
436-
u = urlopen("file://" + file_loc)
436+
if "://" in file_loc:
437+
u = urlopen(file_loc)
438+
else:
439+
u = open(file_loc)
437440
data[name] = xmlParse.xmlfile2dict(u)
438441
except Exception:
439442
print("\nCannot open", file_loc)
@@ -613,7 +616,7 @@ Glidein log analysis for frontend %s - %s
613616
######################################################################
614617

615618
# sort periods from least to greatest, with 24 hours at the top
616-
period_list = sorted(period_data.keys())
619+
period_list = sorted(list(period_data.keys()))
617620
period_list.remove(86400)
618621
period_list.insert(0, 86400)
619622

@@ -643,7 +646,7 @@ Glidein log analysis for frontend %s - %s
643646

644647
if show_block:
645648
print("----------------------------------------\n%s:\n" % title)
646-
blockprint(title, period_data[p], p, 0)
649+
blockprint(title, period_data[p], p, None)
647650

648651
################################################################################
649652
# Print per entry stats (all frontends)
@@ -671,9 +674,19 @@ Per Entry (all frontends) stats for the past %s hours.\n"""
671674
entry["validation"] = 1
672675

673676
lineprint(entry_name, entry, entry, 0, to_be_printed, attr_list, sort_attribute, min_limit, totals)
674-
lineprint(
675-
"Total/Average", totals["entry"], totals["g_entry"], 0, totals_to_be_printed, attr_list, sort_attribute, {}
676-
)
677+
if len(totals) > 0:
678+
lineprint(
679+
"Total/Average",
680+
totals["entry"],
681+
totals["g_entry"],
682+
0,
683+
totals_to_be_printed,
684+
attr_list,
685+
sort_attribute,
686+
{},
687+
)
688+
else:
689+
print("No Entries with Glideins.")
677690
print(totals_to_be_printed[0][1])
678691
print(LINEPRINT_HEADER_DIV)
679692

@@ -697,7 +710,7 @@ Per Entry (all frontends) stats for the past %s hours.\n"""
697710
---------------------------------------
698711
---------------------------------------
699712
Per Entry (per frontend) stats for the past %s hours.\n"""
700-
% (x)
713+
% x
701714
)
702715
else:
703716
units = ["Slots", "Seconds", "Hours"]
@@ -706,7 +719,7 @@ Per Entry (per frontend) stats for the past %s hours.\n"""
706719
---------------------------------------
707720
---------------------------------------
708721
Frontend stats for the past %s hours.\n"""
709-
% (x)
722+
% x
710723
)
711724
print(
712725
"%-25s%7s %7s %3s %7s %3s %7s %3s %7s %3s %7s %3s %4s\n"

factory/tools/analyze_frontends

+18-14
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ def list_print(frontend, zero_supp, entry_data, sorting, attr_list, sort_attribu
5555
entry["RD"] = rundiff_percent
5656

5757
if zero_supp == 1:
58-
sum = 0
58+
sum_in = 0
5959
for a in attr_list:
60-
sum += entry[a]
61-
if sum == 0:
60+
sum_in += entry[a]
61+
if sum_in == 0:
6262
continue
63-
sum2 += sum
63+
sum2 += sum_in
6464

6565
to_be_printed.append(
6666
(
@@ -145,7 +145,7 @@ USAGE:
145145

146146
# flags
147147
x = 24
148-
dir = os.getcwd()
148+
w_dir = os.getcwd()
149149
sorting = 0
150150
sort_attribute = 0
151151
filter_frontend = 0
@@ -163,7 +163,7 @@ USAGE:
163163
if o == "-x":
164164
x = a
165165
elif o == "--source":
166-
dir = a
166+
w_dir = a
167167
elif o in ("-h", "-help"):
168168
print(usage)
169169
return
@@ -240,10 +240,10 @@ USAGE:
240240
rrd_data = {}
241241
rrd = "rrd_Status_Attributes.xml"
242242

243-
if "http" in dir:
244-
file_dir = os.path.join(dir, rrd)
243+
if "http" in w_dir:
244+
file_dir = os.path.join(w_dir, rrd)
245245
else:
246-
file_dir = os.path.join(dir, "monitor", rrd)
246+
file_dir = os.path.join(w_dir, "monitor", rrd)
247247

248248
if not os.path.exists(file_dir):
249249
# Try RPM location
@@ -253,15 +253,19 @@ USAGE:
253253
print("\nCannot open", file_dir)
254254
print("Please set --source to the factory work dir and try again.")
255255
sys.exit(1)
256-
if dir != os.getcwd():
256+
if w_dir != os.getcwd():
257257
# Directory explicitly set, print warning
258258
print("\nWARNING: Cannot open", file_dir)
259259
print("Using RPM default %s instead" % rpmfile_dir)
260-
dir = rpmdir
260+
w_dir = rpmdir
261261
file_dir = rpmfile_dir
262262

263263
try:
264-
u = urlopen(file_dir)
264+
# request.urlopen cannot handle local files
265+
if file_dir.startswith("http"):
266+
u = urlopen(file_dir)
267+
else:
268+
u = open(file_dir)
265269
rrd_data = xmlParse.xmlfile2dict(u)
266270
except Exception:
267271
print("\nCannot open", file_dir, "\n\tor", rrd, "was not found there.\n")
@@ -318,7 +322,7 @@ USAGE:
318322
pass
319323

320324
# data[period[frontend[entry[element[value]]]]]
321-
#'data' numbers verified by hand
325+
# 'data' numbers verified by hand
322326
# debug_print_dict(data)
323327

324328
#####################################################################
@@ -378,7 +382,7 @@ Status Attributes (Clients) analysis for %s - %s
378382
######################################################################
379383

380384
# sort periods from least to greatest, with 24 hours at the top
381-
period_list = period_data.keys()
385+
period_list = list(period_data.keys())
382386
period_list.sort()
383387
period_list.remove(86400)
384388
period_list.insert(0, 86400)

0 commit comments

Comments
 (0)