-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
142 lines (120 loc) · 5.64 KB
/
main.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import json
import time
import re
import requests
import argparse
def request_validation(data, files):
url = 'https://apps.opcfoundation.org/NodeSetValidator/Home/Upload'
response = requests.post(url, files=files, data=data)
job_id = get_job_id(response.text)
print(f"Get response {response} of ther server: ")
print(f"Validation Job started with number {job_id}")
# print(response.text)
return job_id
def prepare_input_data_from_config(config_path):
with open(config_path, "r") as json_file:
config = json.loads(json_file.read())
with open(config['nodesetFile'], 'rb') as nodeset_file:
files = [("nodesetFile", nodeset_file)]
for support_node_set in config['supportingNodeSetFiles']:
with open(support_node_set, 'rb') as nodeset_file:
files.append(("supportingNodeSetFiles", nodeset_file))
with open(config['specificationFile'], 'rb') as specification_file:
files.append(("specificationFile", specification_file))
data = {
"email": config['email'],
"ignoreTypes": config['ignoreTypes'],
"suppressErrors": config['suppressErrors'],
"noDelete": config['noDelete'],
"checkConformanceUnits": config['checkConformanceUnits']
}
return prepare_input_data(config["nodesetFile"],
config["supportingNodeSetFiles"],
config["specificationFile"],
config["email"],
config["ignoreTypes"],
config["suppressErrors"],
config["noDelete"],
config["checkConformanceUnits"])
def prepare_input_data_from_cli(args):
return prepare_input_data(args["nodesetfile"],
args["supportingNodeSetFiles"],
args["specificationFile"],
args["email"],
args["ignoreTypes"],
args["suppressErrors"],
args["noDelete"],
args["checkConformanceUnits"])
def prepare_input_data(nodesetfile,
supporting_node_set_files,
specificationFile,
email,
ignoreTypes,
suppressErrors,
noDelete,
checkConformanceUnits):
files = [("nodesetFile", open(nodesetfile, 'rb'))]
for support_node_set in supporting_node_set_files:
files.append(("supportingNodeSetFiles", open(support_node_set, 'rb')))
files.append(("specificationFile", open(specificationFile, 'rb')))
data = {
"email": email,
"ignoreTypes": ignoreTypes,
"suppressErrors": suppressErrors,
"noDelete": noDelete,
"checkConformanceUnits": checkConformanceUnits
}
return data, files
def get_job_id(text):
regex = r"\/NodeSetValidator\/Home\/Results\/([0-9]+)\""
job_id = re.findall(regex, text)
return job_id[0]
def get_validation_result(timeout, job_id):
result_url = f"https://apps.opcfoundation.org/NodeSetValidator/Home/DownloadResults/{job_id}?filename=results.csv"
for x in range(10):
print(f"try load results {x} /10")
time.sleep(timeout / 10)
response = requests.post(result_url)
if "html" in response.text:
continue
else:
print(response.text)
break
print(f"More information can be found at:https://apps.opcfoundation.org/NodeSetValidator/Home/Results/{job_id}")
def main():
args = argument_parser()
if 'config' in args:
data, files = prepare_input_data_from_config(args.config)
else:
data, files = prepare_input_data_from_cli(args)
job_id = request_validation(data, files)
del data
del files
get_validation_result(timeout=(15 * 60), job_id=job_id)
def argument_parser():
"""
Generate an ArgumentParser menu and parse the arguments
see main.py -h for all options
:return: args
"""
parser = argparse.ArgumentParser(description='Nodeset Validation Runner')
parser.add_argument('--config', metavar='c', type=str, nargs='?',
help='path to a json config file. Which contain all of the other args')
parser.add_argument('--nodesetfile', metavar='n', type=str, nargs='?',
help='A file to validate that conforms to the UANodeSet schema defined in Part 6 of the OPC '
'UA Specification. ')
parser.add_argument('--supportingNodeSetFiles', type=str, nargs='*',
help='Additional NodeSet files which are needed to process the NodeSet that is being validated.')
parser.add_argument('--document', metavar='d', type=str, nargs='?',
help='A Word document that follows the conventions defined for OPC UA specifications.')
parser.add_argument('--email', type=str, nargs='?',
help='An optional email used to send a notification when the processing compeletes.')
parser.add_argument('--ignoreTitels', metavar='s', type=str, nargs='*',
help='An optional comma seperated list of type names which will be ignored by the tool')
parser.add_argument('--supressError', metavar='e', type=str, nargs='*',
help='An optional comma seperated list of type names which will be ignored by the tool')
args = parser.parse_args()
return args
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
main()