Go to the documentation of this file.00001
00002
00003
00004 def status_codes():
00005 inputfile = open("StatusCodes_add.csv")
00006 additional = {}
00007 for line in inputfile:
00008 name, val, doc = line.split(",", 2)
00009 additional[int(val, 0)] = (name, val, doc)
00010
00011 inputfile = open("StatusCodes.csv")
00012 result = []
00013 for line in inputfile:
00014 name, val, doc = line.split(",", 2)
00015 result.append((name, val, doc))
00016 additional.pop(int(val, 0), None)
00017 add = [ additional[k] for k in sorted(additional.keys()) ]
00018 return add + result
00019
00020 if __name__ == "__main__":
00021 codes = status_codes()
00022 outputfile = open("../opcua/ua/status_codes.py", "w")
00023 outputfile.write("#AUTOGENERATED!!!\n")
00024 outputfile.write("\n")
00025 outputfile.write("from opcua.ua.uaerrors import UaStatusCodeError\n")
00026 outputfile.write("from opcua.ua import ua_binary as uabin\n")
00027
00028 outputfile.write("\n")
00029
00030 outputfile.write("class StatusCodes(object):\n")
00031 for name, val, doc in codes:
00032 doc = doc.strip()
00033 outputfile.write(" {0} = {1}\n".format(name, val))
00034 outputfile.write("\n")
00035 outputfile.write("\n")
00036
00037 outputfile.write("code_to_name_doc = {\n")
00038 for name, val, doc in codes:
00039 doc = doc.strip()
00040 doc = doc.replace("'", '"')
00041 outputfile.write(" {0}: ('{1}', '{2}'),\n".format(val, name, doc))
00042 outputfile.write("}\n")
00043 outputfile.write("\n")
00044 outputfile.write("\n")
00045
00046 outputfile.write("""def get_name_and_doc(val):
00047 if val in code_to_name_doc:
00048 return code_to_name_doc[val]
00049 else:
00050 if uabin.test_bit(val, 31):
00051 return 'Bad', 'Unknown StatusCode value: {}'.format(val)
00052 elif uabin.test_bit(val, 30):
00053 return 'UncertainIn', 'Unknown StatusCode value: {}'.format(val)
00054 else:
00055 return 'Good', 'Unknown StatusCode value: {}'.format(val)
00056 """)
00057
00058
00059