File: generate_ids.py

package info (click to toggle)
python-opcua 0.98.11-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 45,296 kB
  • sloc: xml: 579,866; cs: 124,455; python: 56,857; makefile: 164; sh: 37
file content (33 lines) | stat: -rw-r--r-- 1,411 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
if __name__ == "__main__":
    inputfile = open("NodeIds.csv")
    outputfile = open("../opcua/ua/object_ids.py", "w")
    outputfile.write("#AUTOGENERATED!!!\n")
    outputfile.write("\n")
    outputfile.write("from enum import IntEnum\n")
    outputfile.write("\n")
    # Making ObjectIds inherit IntEnum has a huge performance impact!!!!!
    # so we use a normal class and a reverse one for the few places we need it
    outputfile.write("class ObjectIds(object):\n")
    outputfile.write("    Null = 0\n")
    for line in inputfile:
        name, nb, datatype = line.split(",")
        outputfile.write("    {0} = {1}\n".format(name, nb))
    inputfile.close()
    inputfile = open("NodeIds.csv")
    outputfile.write("\n\nObjectIdNames = {}\n")
    outputfile.write("ObjectIdNames[0] = 'Null'\n".format(nb, name))
    for line in inputfile:
        name, nb, datatype = line.split(",")
        outputfile.write("ObjectIdNames[{0}] = '{1}'\n".format(nb, name))

    inputfile = open("AttributeIds.csv")
    outputfile = open("../opcua/ua/attribute_ids.py", "w")
    outputfile.write("#AUTOGENERATED!!!\n")
    outputfile.write("\n")
    outputfile.write("from enum import IntEnum\n")
    outputfile.write("\n")
    outputfile.write("class AttributeIds(IntEnum):\n")
    for line in inputfile:
        name, nb = line.split(",")
        outputfile.write("    {0} = {1}\n".format(name.strip(), nb.strip()))