-
Notifications
You must be signed in to change notification settings - Fork 0
/
vspec2json.py
executable file
·66 lines (56 loc) · 1.92 KB
/
vspec2json.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
#!/usr/bin/env python3
#
# (C) 2016 Jaguar Land Rover
#
# All files and artifacts in this repository are licensed under the
# provisions of the license provided by the LICENSE file in this repository.
#
#
# Concert vspec file to JSON
#
import sys
import vspec
import json
import getopt
def usage():
print("Usage:", sys.argv[0], "[-I include_dir] ... [-i prefix:id_file] vspec_file json_file")
print(" -I include_dir Add include directory to search for included vspec")
print(" files. Can be used multiple timees.")
print()
print(" -i prefix:uuid_file File to use for storing generated UUIDs for signals with")
print(" a given path prefix. Can be used multiple times to store")
print(" UUIDs for signal sub-trees in different files.")
print()
print(" vspec_file The vehicle specification file to parse.")
print(" json_file The file to output the JSON objects to.")
sys.exit(255)
if __name__ == "__main__":
#
# Check that we have the correct arguments
#
opts, args= getopt.getopt(sys.argv[1:], "I:i:")
# Always search current directory for include_file
include_dirs = ["."]
for o, a in opts:
if o == "-I":
include_dirs.append(a)
elif o == "-i":
id_spec = a.split(":")
if len(id_spec) != 2:
print("ERROR: -i needs a 'prefix:id_file' argument.")
usage()
[prefix, file_name] = id_spec
vspec.db_mgr.create_signal_uuid_db(prefix, file_name)
else:
usage()
if len(args) != 2:
usage()
json_out = open (args[1], "w")
try:
tree = vspec.load(args[0], include_dirs)
except vspec.VSpecError as e:
print("Error: {}".format(e))
exit(255)
json.dump(tree, json_out, indent=2)
json_out.write("\n")
json_out.close()