DrvGen.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import os, sys
  4. import getopt
  5. import traceback
  6. import subprocess
  7. import xml.dom.minidom
  8. sys.dont_write_bytecode = True
  9. sys.path.append('.')
  10. sys.path.append('..')
  11. from obj.ChipObj import ChipObj
  12. from obj.ChipObj import Everest
  13. from obj.ChipObj import Olympus
  14. from obj.ChipObj import MT6757_P25
  15. from obj.ChipObj import Rushmore
  16. from obj.ChipObj import Whitney
  17. from obj.ChipObj import MT6759
  18. from obj.ChipObj import MT6763
  19. from obj.ChipObj import MT6750S
  20. from obj.ChipObj import MT6758
  21. from obj.ChipObj import MT6739
  22. from obj.ChipObj import MT8695
  23. from obj.ChipObj import MT6771
  24. from obj.ChipObj import MT6775
  25. from obj.ChipObj import MT6779
  26. from utility.util import LogLevel
  27. from utility.util import log
  28. def usage():
  29. print '''
  30. usage: DrvGen [dws_path] [file_path] [log_path] [paras]...
  31. options and arguments:
  32. dws_path : dws file path
  33. file_path : where you want to put generated files
  34. log_path : where to store the log files
  35. paras : parameter for generate wanted file
  36. '''
  37. def is_oldDws(path, gen_spec):
  38. if not os.path.exists(path):
  39. log(LogLevel.error, 'Can not find %s' %(path))
  40. sys.exit(-1)
  41. try:
  42. root = xml.dom.minidom.parse(dws_path)
  43. except Exception, e:
  44. log(LogLevel.warn, '%s is not xml format, try to use old DCT!' %(dws_path))
  45. if len(gen_spec) == 0:
  46. log(LogLevel.warn, 'Please use old DCT UI to gen all files!')
  47. return True
  48. old_dct = os.path.join(sys.path[0], 'old_dct', 'DrvGen')
  49. cmd = old_dct + ' ' + dws_path + ' ' + gen_path + ' ' + log_path + ' ' + gen_spec[0]
  50. if 0 == subprocess.call(cmd, shell=True):
  51. return True
  52. else:
  53. log(LogLevel.error, '%s format error!' %(dws_path))
  54. sys.exit(-1)
  55. return False
  56. if __name__ == '__main__':
  57. opts, args = getopt.getopt(sys.argv[1:], '')
  58. if len(args) == 0:
  59. msg = 'Too less arguments!'
  60. usage()
  61. log(LogLevel.error, msg)
  62. sys.exit(-1)
  63. dws_path = ''
  64. gen_path = ''
  65. log_path = ''
  66. gen_spec = []
  67. # get DWS file path from parameters
  68. dws_path = os.path.abspath(args[0])
  69. # get parameters from input
  70. if len(args) == 1:
  71. gen_path = os.path.dirname(dws_path)
  72. log_path = os.path.dirname(dws_path)
  73. elif len(args) == 2:
  74. gen_path = os.path.abspath(args[1])
  75. log_path = os.path.dirname(dws_path)
  76. elif len(args) == 3:
  77. gen_path = os.path.abspath(args[1])
  78. log_path = os.path.abspath(args[2])
  79. elif len(args) >= 4:
  80. gen_path = os.path.abspath(args[1])
  81. log_path = os.path.abspath(args[2])
  82. for i in range(3,len(args)):
  83. gen_spec.append(args[i])
  84. log(LogLevel.info, 'DWS file path is %s' %(dws_path))
  85. log(LogLevel.info, 'Gen files path is %s' %(gen_path))
  86. log(LogLevel.info, 'Log files path is %s' %(log_path))
  87. for item in gen_spec:
  88. log(LogLevel.info, 'Parameter is %s' %(item))
  89. # check DWS file path
  90. if not os.path.exists(dws_path):
  91. log(LogLevel.error, 'Can not find "%s", file not exist!' %(dws_path))
  92. sys.exit(-1)
  93. if not os.path.exists(gen_path):
  94. log(LogLevel.error, 'Can not find "%s", gen path not exist!' %(gen_path))
  95. sys.exit(-1)
  96. if not os.path.exists(log_path):
  97. log(LogLevel.error, 'Can not find "%s", log path not exist!' %(log_path))
  98. sys.exit(-1)
  99. if is_oldDws(dws_path, gen_spec):
  100. sys.exit(0)
  101. chipId = ChipObj.get_chipId(dws_path)
  102. log(LogLevel.info, 'chip id: %s' %(chipId))
  103. chipObj = None
  104. if cmp(chipId, 'MT6797') == 0:
  105. chipObj = Everest(dws_path, gen_path)
  106. elif cmp(chipId, 'MT6757') == 0:
  107. chipObj = Olympus(dws_path, gen_path)
  108. elif cmp(chipId, 'MT6757-P25') == 0:
  109. chipObj = MT6757_P25(dws_path, gen_path)
  110. elif cmp(chipId, 'KIBOPLUS') == 0:
  111. chipObj = MT6757_P25(dws_path, gen_path)
  112. elif cmp(chipId, 'MT6570') == 0:
  113. chipObj = Rushmore(dws_path, gen_path)
  114. elif cmp(chipId, 'MT6799') == 0:
  115. chipObj = Whitney(dws_path, gen_path)
  116. elif cmp(chipId, 'MT6763') == 0:
  117. chipObj = MT6763(dws_path, gen_path)
  118. elif cmp(chipId, 'MT6759') == 0:
  119. chipObj = MT6759(dws_path, gen_path)
  120. elif cmp(chipId, 'MT6750S') == 0:
  121. chipObj = MT6750S(dws_path, gen_path)
  122. elif cmp(chipId, 'MT6758') == 0:
  123. chipObj = MT6758(dws_path, gen_path)
  124. elif cmp(chipId, 'MT6739') == 0:
  125. chipObj = MT6739(dws_path, gen_path)
  126. elif cmp(chipId, 'MT8695') == 0:
  127. chipObj = MT8695(dws_path, gen_path)
  128. elif cmp(chipId, 'MT6771') == 0 or \
  129. cmp(chipId, 'MT6775') == 0 or \
  130. cmp(chipId, 'MT6765') == 0 or \
  131. cmp(chipId, 'MT3967') == 0 or \
  132. cmp(chipId, 'MT6761') == 0:
  133. chipObj = MT6771(dws_path, gen_path)
  134. elif cmp(chipId, 'MT6779') == 0:
  135. chipObj = MT6779(dws_path, gen_path)
  136. else:
  137. chipObj = ChipObj(dws_path, gen_path)
  138. if not chipObj.parse():
  139. log(LogLevel.error, 'Parse %s fail!' %(dws_path))
  140. sys.exit(-1)
  141. if not chipObj.generate(gen_spec):
  142. log(LogLevel.error, 'Generate files fail!')
  143. sys.exit(-1)
  144. sys.exit(0)