generate_datatypes.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. from __future__ import print_function
  6. from nodeset_compiler.type_parser import CSVBSDTypeParser
  7. import nodeset_compiler.backend_open62541_typedefinitions as backend
  8. import argparse
  9. ###############################
  10. # Parse the Command Line Input#
  11. ###############################
  12. parser = argparse.ArgumentParser()
  13. parser.add_argument('-c', '--type-csv',
  14. metavar="<typeDescriptions>",
  15. type=argparse.FileType('r'),
  16. dest="type_csv",
  17. action='append',
  18. default=[],
  19. help='csv file with type descriptions')
  20. parser.add_argument('--namespace',
  21. type=int,
  22. dest="namespace",
  23. default=0,
  24. help='namespace id of the generated type nodeids (defaults to 0)')
  25. parser.add_argument('-s', '--selected-types',
  26. metavar="<selectedTypes>",
  27. type=argparse.FileType('r'),
  28. dest="selected_types",
  29. action='append',
  30. default=[],
  31. help='file with list of types (among those parsed) to be generated. If not given, all types are generated')
  32. parser.add_argument('--no-builtin',
  33. action='store_true',
  34. dest="no_builtin",
  35. help='Do not generate builtin types')
  36. parser.add_argument('--opaque-map',
  37. metavar="<opaqueTypeMap>",
  38. type=argparse.FileType('r'),
  39. dest="opaque_map",
  40. action='append',
  41. default=[],
  42. help='JSON file with opaque type mapping: { \'typename\': { \'ns\': 0, \'id\': 7, \'name\': \'UInt32\' }, ... }')
  43. parser.add_argument('--internal',
  44. action='store_true',
  45. dest="internal",
  46. help='Given bsd are internal types which do not have any .csv file')
  47. parser.add_argument('-t', '--type-bsd',
  48. metavar="<typeBsds>",
  49. type=argparse.FileType('r'),
  50. dest="type_bsd",
  51. action='append',
  52. default=[],
  53. help='bsd file with type definitions')
  54. parser.add_argument('-i', '--import',
  55. metavar="<importBsds>",
  56. type=str,
  57. dest="import_bsd",
  58. action='append',
  59. default=[],
  60. help='combination of TYPE_ARRAY#filepath.bsd with type definitions which should be loaded but not exported/generated')
  61. parser.add_argument('outfile',
  62. metavar='<outputFile>',
  63. help='output file w/o extension')
  64. args = parser.parse_args()
  65. outname = args.outfile.split("/")[-1]
  66. inname = ', '.join(list(map(lambda x: x.name.split("/")[-1], args.type_bsd)))
  67. parser = CSVBSDTypeParser(args.opaque_map, args.selected_types, args.no_builtin, outname, args.namespace, args.import_bsd,
  68. args.type_bsd, args.type_csv)
  69. parser.create_types()
  70. generator = backend.CGenerator(parser, inname, args.outfile, args.internal)
  71. generator.write_definitions()