-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool_validation.py
47 lines (32 loc) · 1.44 KB
/
tool_validation.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
import json
import copy
from biotools_dev import validate_tool
def is_html_error(message):
return '<html' in message.lower() or '<body' in message.lower()
def attempt_fix_tool_name(tool, token):
"""Attempt to fix the tool name and revalidate."""
tool_temp = copy.deepcopy(tool)
tool_temp['name'] += '_autogenerated'
valid, error_message = validate_tool(tool_temp, token)
return valid, tool_temp if valid else error_message
def validate_tools(tools, token):
to_add = []
problem_tools = []
for tool in tools:
valid, txt = validate_tool(tool, token)
if valid:
to_add.append(tool)
continue
print("Tool with name:{name} has the errors: {errors}".format(name=tool['name'], errors=txt))
if not is_html_error(txt):
e = json.loads(txt)
if type(e) is dict and e.get('name') != None:
print('Error with name {name}'.format(name=tool['name']))
valid, result = attempt_fix_tool_name(tool, token)
if valid:
print('The error was fixed by changing the name to {name}'.format(name=result['name']))
tool['name'] = result['name']
to_add.append(tool)
continue
problem_tools.append({'tool_name':tool['name'],'error': 'html' if is_html_error(txt) else txt})
return to_add, problem_tools