Skip to content

Commit 325037e

Browse files
committed
python: convert from python 2 to python 2 syntax
Signed-off-by: Øyvind Harboe <[email protected]>
1 parent d421b95 commit 325037e

File tree

1 file changed

+62
-46
lines changed

1 file changed

+62
-46
lines changed

flow/util/appendStatsToDb.py

Lines changed: 62 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python2
22

33
# This scripts appends the test metadata to the master json
4-
#-------------------------------------------------------------------------
4+
# -------------------------------------------------------------------------
55

66
import argparse # argument parsing
77
import json # json parsing
@@ -17,63 +17,79 @@
1717

1818
# Parse and validate arguments
1919
# ==============================================================================
20-
parser = argparse.ArgumentParser(
21-
description='Appends test metadata to master database')
22-
parser.add_argument('--masterTestListPath', '-m', default="masterTestList.json", required=False,
23-
help='Path to Master Metadata')
24-
parser.add_argument('--testMetadataPaths', '-t', required=True,
25-
help='Path to Json Metadata', nargs='+')
20+
parser = argparse.ArgumentParser(description="Appends test metadata to master database")
21+
parser.add_argument(
22+
"--masterTestListPath",
23+
"-m",
24+
default="masterTestList.json",
25+
required=False,
26+
help="Path to Master Metadata",
27+
)
28+
parser.add_argument(
29+
"--testMetadataPaths", "-t", required=True, help="Path to Json Metadata", nargs="+"
30+
)
2631
args = parser.parse_args()
2732

2833
# Open master file
2934
if os.path.isfile(args.masterTestListPath):
30-
with open(args.masterTestListPath) as f:
31-
masterJson = json.load(f, object_pairs_hook=OrderedDict)
35+
with open(args.masterTestListPath) as f:
36+
masterJson = json.load(f, object_pairs_hook=OrderedDict)
3237
else:
33-
masterJson = {"fields": [], "testcases": []}
38+
masterJson = {"fields": [], "testcases": []}
3439

3540

3641
for testMetadata in args.testMetadataPaths:
37-
38-
if not os.path.isfile(testMetadata):
39-
print "Error: testMetadataPath does not exist"
40-
print "Path: " + testMetadata
41-
sys.exit(1)
42-
43-
# Open test metadata
44-
try:
45-
with open(testMetadata) as f:
46-
designJson = json.load(f, object_pairs_hook=OrderedDict)
47-
except ValueError as e:
48-
print("Error occured opening or loading json file.")
49-
print >> sys.stderr, "Exception: %s" % str(e)
50-
sys.exit(1)
51-
52-
if not designJson["uuid"] in [d["uuid"] for d in masterJson["testcases"]]:
53-
masterJson["testcases"].append(designJson)
54-
55-
# Update Headers if necessary
56-
for key in list(designJson):
57-
if not key in masterJson["fields"]:
58-
masterJson["fields"].append(key)
59-
print "Updating fields with", key
60-
else:
61-
print("Skipping " + designJson["platform"] + "/" + designJson["design"] +
62-
" (" + designJson["uuid"] + ") already in masterDB")
42+
if not os.path.isfile(testMetadata):
43+
print("Error: testMetadataPath does not exist")
44+
print("Path: " + testMetadata)
45+
sys.exit(1)
46+
47+
# Open test metadata
48+
try:
49+
with open(testMetadata) as f:
50+
designJson = json.load(f, object_pairs_hook=OrderedDict)
51+
except ValueError as e:
52+
print("Error occured opening or loading json file.")
53+
print("Exception: %s" % str(e), file=sys.stderr)
54+
sys.exit(1)
55+
56+
if not designJson["uuid"] in [d["uuid"] for d in masterJson["testcases"]]:
57+
masterJson["testcases"].append(designJson)
58+
59+
# Update Headers if necessary
60+
for key in list(designJson):
61+
if not key in masterJson["fields"]:
62+
masterJson["fields"].append(key)
63+
print("Updating fields with", key)
64+
else:
65+
print(
66+
"Skipping "
67+
+ designJson["platform"]
68+
+ "/"
69+
+ designJson["design"]
70+
+ " ("
71+
+ designJson["uuid"]
72+
+ ") already in masterDB"
73+
)
6374

6475

6576
# Dump JSON
6677
with open(args.masterTestListPath, "w") as f:
67-
json.dump(masterJson, f, indent=2)
78+
json.dump(masterJson, f, indent=2)
6879

6980

7081
# Dump CSV
71-
csvFilePath = os.path.splitext(args.masterTestListPath)[0] + '.csv'
72-
with open(csvFilePath, 'w') as csvfile:
73-
fieldnames = list(masterJson["fields"])
74-
writer = csv.DictWriter(csvfile, fieldnames=fieldnames,
75-
restval="-", extrasaction="ignore", dialect='excel')
76-
77-
writer.writeheader()
78-
for testcase in masterJson["testcases"]:
79-
writer.writerow(testcase)
82+
csvFilePath = os.path.splitext(args.masterTestListPath)[0] + ".csv"
83+
with open(csvFilePath, "w") as csvfile:
84+
fieldnames = list(masterJson["fields"])
85+
writer = csv.DictWriter(
86+
csvfile,
87+
fieldnames=fieldnames,
88+
restval="-",
89+
extrasaction="ignore",
90+
dialect="excel",
91+
)
92+
93+
writer.writeheader()
94+
for testcase in masterJson["testcases"]:
95+
writer.writerow(testcase)

0 commit comments

Comments
 (0)