2020-07-20 18:46:15 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
# ----------------------------------------------------------------------------
|
2022-08-08 18:02:17 +08:00
|
|
|
# axys "install" plugin
|
2020-07-20 18:46:15 +08:00
|
|
|
#
|
|
|
|
# Copyright 2013 (C) Luis Parravicini
|
|
|
|
#
|
|
|
|
# License: MIT
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
'''
|
2022-08-08 18:02:17 +08:00
|
|
|
"install" plugin for axys command line tool
|
2020-07-20 18:46:15 +08:00
|
|
|
'''
|
|
|
|
|
|
|
|
__docformat__ = 'restructuredtext'
|
|
|
|
|
|
|
|
import os
|
2022-08-08 18:02:17 +08:00
|
|
|
import axys
|
2020-07-20 18:46:15 +08:00
|
|
|
from MultiLanguage import MultiLanguage
|
|
|
|
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
class CCPluginDeploy(axys.CCPlugin):
|
2020-07-20 18:46:15 +08:00
|
|
|
"""
|
|
|
|
Install a project
|
|
|
|
"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def depends_on():
|
|
|
|
return ('compile',)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def plugin_name():
|
|
|
|
return "deploy"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def brief_description():
|
|
|
|
return MultiLanguage.get_string('DEPLOY_BRIEF')
|
|
|
|
|
|
|
|
def _add_custom_options(self, parser):
|
|
|
|
parser.add_argument("-m", "--mode", dest="mode", default='debug',
|
|
|
|
help=MultiLanguage.get_string('DEPLOY_ARG_MODE'))
|
|
|
|
parser.add_argument("--no-uninstall", dest="no_uninstall", action="store_true",
|
|
|
|
help=MultiLanguage.get_string('DEPLOY_ARG_NO_UNINSTALL'))
|
|
|
|
|
|
|
|
def _check_custom_options(self, args):
|
|
|
|
|
|
|
|
if args.mode != 'release':
|
|
|
|
args.mode = 'debug'
|
|
|
|
|
|
|
|
self._mode = 'debug'
|
|
|
|
if 'release' == args.mode:
|
|
|
|
self._mode = args.mode
|
|
|
|
|
|
|
|
self._no_uninstall = args.no_uninstall
|
|
|
|
|
|
|
|
def _is_debug_mode(self):
|
|
|
|
return self._mode == 'debug'
|
|
|
|
|
|
|
|
def deploy_ios(self, dependencies):
|
|
|
|
if not self._platforms.is_ios_active():
|
|
|
|
return
|
|
|
|
|
|
|
|
compile_dep = dependencies['compile']
|
|
|
|
self._iosapp_path = compile_dep.app_path
|
|
|
|
self._use_sdk = compile_dep._use_sdk
|
|
|
|
|
2022-09-05 14:13:52 +08:00
|
|
|
def deploy_tvos(self, dependencies):
|
|
|
|
if not self._platforms.is_tvos_active():
|
|
|
|
return
|
|
|
|
|
|
|
|
compile_dep = dependencies['compile']
|
|
|
|
self._tvosapp_path = compile_dep.app_path
|
|
|
|
self._use_sdk = compile_dep._use_sdk
|
|
|
|
|
2020-07-20 18:46:15 +08:00
|
|
|
def deploy_mac(self, dependencies):
|
|
|
|
if not self._platforms.is_mac_active():
|
|
|
|
return
|
|
|
|
|
|
|
|
compile_dep = dependencies['compile']
|
|
|
|
self._macapp_path = compile_dep.app_path
|
|
|
|
self.target_name = compile_dep.app_name
|
|
|
|
|
|
|
|
def deploy_web(self, dependencies):
|
|
|
|
if not self._platforms.is_web_active():
|
|
|
|
return
|
|
|
|
|
|
|
|
compile_dep = dependencies['compile']
|
|
|
|
self.sub_url = compile_dep.sub_url
|
|
|
|
self.run_root = compile_dep.run_root
|
|
|
|
|
|
|
|
def deploy_win32(self, dependencies):
|
|
|
|
if not self._platforms.is_win32_active():
|
|
|
|
return
|
|
|
|
|
|
|
|
compile_dep = dependencies['compile']
|
|
|
|
self.run_root = compile_dep.app_path
|
|
|
|
self.project_name = compile_dep.project_name
|
|
|
|
|
|
|
|
def find_xap_deploy_tool(self):
|
2021-05-27 17:23:03 +08:00
|
|
|
if(sys.version_info.major >= 3):
|
2022-09-05 14:13:52 +08:00
|
|
|
import winreg
|
2021-05-27 17:23:03 +08:00
|
|
|
else:
|
|
|
|
import _winreg as winreg
|
2020-07-20 18:46:15 +08:00
|
|
|
import re
|
2022-08-08 18:02:17 +08:00
|
|
|
if axys.os_is_32bit_windows():
|
2021-05-27 17:23:03 +08:00
|
|
|
reg_flag_list = [ winreg.KEY_WOW64_32KEY ]
|
2020-07-20 18:46:15 +08:00
|
|
|
else:
|
2021-05-27 17:23:03 +08:00
|
|
|
reg_flag_list = [ winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY ]
|
2020-07-20 18:46:15 +08:00
|
|
|
|
|
|
|
pattern = re.compile(r"v(\d+).(\d+)")
|
|
|
|
find_ret = None
|
|
|
|
find_major = -1
|
|
|
|
find_minor = -1
|
|
|
|
for reg_flag in reg_flag_list:
|
2022-08-08 18:02:17 +08:00
|
|
|
axys.Logging.info(MultiLanguage.get_string('DEPLOY_INFO_FIND_XAP_FMT',
|
2021-05-27 17:23:03 +08:00
|
|
|
("32bit" if reg_flag == winreg.KEY_WOW64_32KEY else "64bit")))
|
2020-07-20 18:46:15 +08:00
|
|
|
try:
|
2021-05-27 17:23:03 +08:00
|
|
|
wp = winreg.OpenKey(
|
|
|
|
winreg.HKEY_LOCAL_MACHINE,
|
2020-07-20 18:46:15 +08:00
|
|
|
r"SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone",
|
|
|
|
0,
|
2021-05-27 17:23:03 +08:00
|
|
|
winreg.KEY_READ | reg_flag
|
2020-07-20 18:46:15 +08:00
|
|
|
)
|
|
|
|
except:
|
|
|
|
# windows phone not found, continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
while True:
|
|
|
|
try:
|
2021-05-27 17:23:03 +08:00
|
|
|
version = winreg.EnumKey(wp, i)
|
2020-07-20 18:46:15 +08:00
|
|
|
except:
|
|
|
|
break
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
match = re.match(pattern, version)
|
|
|
|
if match:
|
|
|
|
major = int(match.group(1))
|
|
|
|
minor = int(match.group(2))
|
|
|
|
if major > 7:
|
|
|
|
try:
|
2021-05-27 17:23:03 +08:00
|
|
|
key = winreg.OpenKey(wp, "%s\Install Path" % version)
|
|
|
|
value, type = winreg.QueryValueEx(key, "Install Path")
|
2020-07-20 18:46:15 +08:00
|
|
|
tool_path = os.path.join(value, "Tools", "XAP Deployment", "XapDeployCmd.exe")
|
|
|
|
if os.path.isfile(tool_path):
|
|
|
|
if (find_ret is None) or (major > find_major) or (major == find_major and minor > find_minor):
|
|
|
|
find_ret = tool_path
|
|
|
|
find_major = major
|
|
|
|
find_minor = minor
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return find_ret
|
|
|
|
|
|
|
|
def deploy_linux(self, dependencies):
|
|
|
|
if not self._platforms.is_linux_active():
|
|
|
|
return
|
|
|
|
|
|
|
|
compile_dep = dependencies['compile']
|
|
|
|
self.run_root = compile_dep.run_root
|
|
|
|
self.project_name = compile_dep.project_name
|
|
|
|
|
|
|
|
def deploy_android(self, dependencies):
|
|
|
|
if not self._platforms.is_android_active():
|
|
|
|
return
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
axys.Logging.info(MultiLanguage.get_string('DEPLOY_INFO_INSTALLING_APK'))
|
2020-07-20 18:46:15 +08:00
|
|
|
|
|
|
|
compile_dep = dependencies['compile']
|
|
|
|
self.package = compile_dep.android_package
|
|
|
|
self.activity = compile_dep.android_activity
|
|
|
|
apk_path = compile_dep.apk_path
|
2022-08-08 18:02:17 +08:00
|
|
|
sdk_root = axys.check_environment_variable('ANDROID_SDK_ROOT')
|
|
|
|
adb_path = axys.CMDRunner.convert_path_to_cmd(os.path.join(sdk_root, 'platform-tools', 'adb'))
|
2020-07-20 18:46:15 +08:00
|
|
|
|
|
|
|
if not self._no_uninstall:
|
|
|
|
# do uninstall only when that app is installed
|
2022-08-08 18:02:17 +08:00
|
|
|
if axys.app_is_installed(adb_path, self.package):
|
2020-07-20 18:46:15 +08:00
|
|
|
adb_uninstall = "%s uninstall %s" % (adb_path, self.package)
|
|
|
|
self._run_cmd(adb_uninstall)
|
|
|
|
|
|
|
|
adb_install = "%s install -r \"%s\"" % (adb_path, apk_path)
|
|
|
|
self._run_cmd(adb_install)
|
|
|
|
|
|
|
|
def get_filename_by_extention(self, ext, path):
|
|
|
|
filelist = os.listdir(path)
|
|
|
|
|
|
|
|
for fname in filelist:
|
|
|
|
name, extention = os.path.splitext(fname)
|
|
|
|
if extention == ext:
|
|
|
|
return fname
|
|
|
|
return None
|
|
|
|
|
|
|
|
def run(self, argv, dependencies):
|
|
|
|
self.parse_args(argv)
|
2022-08-08 18:02:17 +08:00
|
|
|
axys.Logging.info(MultiLanguage.get_string('DEPLOY_INFO_MODE_FMT', self._mode))
|
2020-07-20 18:46:15 +08:00
|
|
|
self.deploy_ios(dependencies)
|
2022-09-05 14:13:52 +08:00
|
|
|
self.deploy_tvos(dependencies)
|
2020-07-20 18:46:15 +08:00
|
|
|
self.deploy_mac(dependencies)
|
|
|
|
self.deploy_android(dependencies)
|
|
|
|
self.deploy_web(dependencies)
|
|
|
|
self.deploy_win32(dependencies)
|
|
|
|
self.deploy_linux(dependencies)
|