File: verify_meta_json.py

package info (click to toggle)
augur 24.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,312 kB
  • sloc: python: 14,253; sh: 227; makefile: 35
file content (44 lines) | stat: -rw-r--r-- 1,364 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from __future__ import print_function
import sys
sys.path.append('..') # this is an assumption and is probably wrong
import argparse
import json


def verify_defaults(defaults):
    booleans = ["mapTriplicate"];
    strings = ['geoResolution', 'colorBy', 'distanceMeasure']
    for trait in booleans:
        if (trait in defaults):
            if type(defaults[trait]) is not bool:
                print("ERROR: defaults -> {} is not boolean".format(trait))
    for trait in strings:
        if (trait in defaults):
            if type(defaults[trait]) is not str:
                print("ERROR: defaults -> {} is not a string".format(trait))

def verify_author_info(arg):
    pass

if __name__=="__main__":
    parser = argparse.ArgumentParser(description = "Verify metadata JSONs")
    parser.add_argument('--json', required=True, type=str, help="metadata JSON")
    params = parser.parse_args()

    try:
        with open(params.json, 'r') as fh:
            data = json.load(fh)
    except:
        print("Couldn't even load the file - big problems!")


    if "defaults" in data:
        verify_defaults(data["defaults"])

    if "author_info" in data:
        verify_author_info(data["author_info"])
    else:
        print("ERROR: author_info does not exist. This build needs to be updated and will soon be incompatible with auspice.")


    # set_trace()