|
1 | 1 | #!/usr/bin/env python2 |
2 | 2 |
|
3 | 3 | # This scripts appends the test metadata to the master json |
4 | | -#------------------------------------------------------------------------- |
| 4 | +# ------------------------------------------------------------------------- |
5 | 5 |
|
6 | 6 | import argparse # argument parsing |
7 | 7 | import json # json parsing |
|
17 | 17 |
|
18 | 18 | # Parse and validate arguments |
19 | 19 | # ============================================================================== |
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 | +) |
26 | 31 | args = parser.parse_args() |
27 | 32 |
|
28 | 33 | # Open master file |
29 | 34 | 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) |
32 | 37 | else: |
33 | | - masterJson = {"fields": [], "testcases": []} |
| 38 | + masterJson = {"fields": [], "testcases": []} |
34 | 39 |
|
35 | 40 |
|
36 | 41 | 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 | + ) |
63 | 74 |
|
64 | 75 |
|
65 | 76 | # Dump JSON |
66 | 77 | with open(args.masterTestListPath, "w") as f: |
67 | | - json.dump(masterJson, f, indent=2) |
| 78 | + json.dump(masterJson, f, indent=2) |
68 | 79 |
|
69 | 80 |
|
70 | 81 | # 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