forked from OBOFoundry/OBOFoundry.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.py
executable file
·89 lines (67 loc) · 2.21 KB
/
processor.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
__author__ = 'cjm'
import argparse
import logging
import requests
#from yaml import load, dump
#from yaml import Loader, Dumper
import yaml
def main():
parser = argparse.ArgumentParser(description='OBO'
'Helper utils for OBO',
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-i', '--input', type=str, required=False,
help='Input metadata file')
subparsers = parser.add_subparsers(dest='subcommand', help='sub-command help')
# SUBCOMMAND
parser_n = subparsers.add_parser('check-urls', help='Checks URLs')
parser_n.set_defaults(function=check_urls)
#parser_n.add_argument('files',nargs='*')
args = parser.parse_args()
print("Loading "+args.input)
f = open(args.input, 'r')
obj = yaml.load(f)
ontologies = obj['ontologies']
print(len(ontologies))
func = args.function
func(ontologies, args)
def check_urls(ontologies, args):
"""
ensure PURLs resolve
"""
print(len(ontologies))
for ont in ontologies:
id = ont['id']
print("Checking:"+id)
# TODO: always check canonical purl?
for p in ont['products']:
pid = p['id']
url = get_obo_purl(pid)
print("Checking: "+url)
resp = requests.get(url)
# TODO: redirects
ok = resp.status_code == 200
print("IS_OK " + id + " " + pid + " "+str(ok))
def get_obo_purl(fragment):
"""
Add the magic prefix
"""
return "http://purl.obolibrary.org/obo/"+fragment
def build_from_source(obj):
"""
Given a metadata object describing a build/clone process,
build the ontology.
Replaces build-obo-ontologies.pl in owltools
"""
if (obj.method == 'robot'):
print("TODO: build obo and owl")
elif (obj.method == 'jenkins-archive'):
print("TODO: download and unzip")
elif (obj.method == 'github-archive'):
print("TODO: download and unzip")
elif (obj.method == 'svn-co'):
print("TODO: run svn")
else:
print("UNKNOWN METHOD:"+obj.method)
if __name__ == "__main__":
main()