path_utils.py 2.4 KB

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