path_utils.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import platform, sys, os
  2. def getSystemPath():
  3. '''
  4. 获取系统目录
  5. '''
  6. if platform.system() == 'Windows':
  7. return 'win'
  8. elif platform.system() == 'Darwin':
  9. return 'macos'
  10. else:
  11. return 'linux'
  12. def get_current_path():
  13. """
  14. 当前目录
  15. 根据需要修改为绝对路径
  16. """
  17. return os.path.join('/opt/mixsdk/script2.0', 'V2')
  18. # return os.path.join(sys.path[0], 'V2')
  19. def getToolWithSystem(tool):
  20. '''
  21. 获取系统相关工具
  22. '''
  23. system = getSystemPath()
  24. suffix = getSystemSuffix()
  25. return os.path.join(getFullToolPath(system), tool + suffix)
  26. def getFullToolPath(name):
  27. '''
  28. 获取工具的目录
  29. '''
  30. return get_full_path('tools', name)
  31. def get_full_path(gen, *name):
  32. '''
  33. 主目录拼接对应路径
  34. '''
  35. path = os.path.join(get_current_path(), gen)
  36. for n in name:
  37. path = os.path.join(path, str(n))
  38. return path
  39. def getChannelPath(sdk):
  40. """
  41. 获取渠道的目录
  42. """
  43. return get_full_path('channel', sdk)
  44. def getSystemSuffix():
  45. """
  46. 系统工具后缀
  47. """
  48. if platform.system() == 'Windows':
  49. return '.exe'
  50. else:
  51. return ''
  52. def get_aapt_path():
  53. """
  54. 获取aapt
  55. """
  56. return getToolWithSystem('aapt')
  57. def get_aapt2_path():
  58. """
  59. 获取aapt2
  60. """
  61. return getToolWithSystem('aapt2')
  62. def get_android_compile_tool_path():
  63. """
  64. 获取android.jar
  65. """
  66. return getFullToolPath('android.jar')
  67. def get_dx_path():
  68. """
  69. 获取dx.jar
  70. """
  71. return getFullToolPath('dx.jar')
  72. def get_d8_path():
  73. """
  74. 获取d8.jar
  75. """
  76. return getFullToolPath('d8.jar')
  77. def get_zipalign_path():
  78. """
  79. 获取zipalign
  80. """
  81. return getToolWithSystem('zipalign')
  82. def get_multidex_path():
  83. """
  84. 获取multidex.jar
  85. """
  86. return getFullToolPath('android-support-multidex.jar')
  87. def get_apktool_path():
  88. """
  89. 获取apktool.jar
  90. """
  91. return getFullToolPath('apktool_2.6.0.jar')
  92. def get_baksmali_path():
  93. """
  94. 获取baksmali.jar
  95. """
  96. return getFullToolPath('baksmali-2.3.jar')
  97. def get_apksigner_path():
  98. '''
  99. 获取apksigner.jar
  100. '''
  101. return getFullToolPath('apksigner.jar')
  102. def get_sdk_log_path(gcp_code):
  103. return get_full_path("log", gcp_code)
  104. def get_sdk_channel_path(channel):
  105. return get_full_path("channel", channel)