Example #1
0
	def run_idevice(self, build, device, provisioning_profile, certificate):
		possible_app_location = '{0}/ios/device-*/'.format(self.path_to_ios_build)
		LOG.debug('Looking for apps at {0}'.format(possible_app_location))
		possible_apps = glob(possible_app_location)
		if not possible_apps:
			raise IOSError("Couldn't find iOS app to run on a device")
		
		path_to_app = possible_apps[0]

		LOG.debug("signing {app}".format(app=path_to_app))
		
		plist_str = self._grab_plist_from_binary_mess(provisioning_profile)
		plist_dict = self._parse_plist(plist_str)
		self.check_plist_dict(plist_dict, self.path_to_ios_build)
		LOG.info("Plist OK.")
		self._create_entitlements_file(build, plist_dict, path_to_app)
		
		self._sign_app(build=build,
			provisioning_profile=provisioning_profile,
			certificate=certificate,
			entitlements_file=path.join(path_to_app, 'template.entitlements'),
		)
		
		fruitstrap = [path.join(self._lib_path(), 'fruitstrap'), path_to_app]
		if device and device.lower() != 'device':
			# pacific device given
			fruitstrap.append(device)
			LOG.info('installing app on device {device}: is it connected?'.format(device=device))
		else:
			LOG.info('installing app on device: is it connected?')

		run_shell(*fruitstrap, fail_silently=False, command_log_level=logging.INFO)
		LOG.info("We can't show log output from your device here: please see the 'Console' section"
				" in the XCode Organiser view")
Example #2
0
def run_wp(build, device):
    path_to_wp_build = path.abspath(path.join('development', 'wp'))

    path_to_xap = _create_xap_from_app(build=build,
                                       path_to_wp_build=path_to_wp_build,
                                       target='development')
    LOG.info('Running: %s' % path_to_xap)

    automation = path.join(path_to_wp_build, "automation", "bin", "Release",
                           "automation.exe")
    if not path.exists(automation):
        raise WPError("Couldn't find Windows Phone deployment tool")

    if not device or device.lower() == 'simulator':
        LOG.info('Running Windows Phone Emulator')
        target = 'emulator'
    else:
        LOG.info(
            'Running on Windows Phone device: {device}'.format(device=device))
        target = 'device'

    run_shell(automation,
              path_to_xap,
              target,
              fail_silently=False,
              verbose=True,
              logger=LOG)
Example #3
0
	def _sign_app(self, build, provisioning_profile, certificate, entitlements_file):
		app_folder_name = self._locate_ios_app(error_message="Couldn't find iOS app in order to sign it")
		path_to_app = path.abspath(path.join(self.path_to_ios_build, 'ios', app_folder_name))
		codesign = self._check_for_codesign()
		embedded_profile = 'embedded.mobileprovision'
		path_to_embedded_profile = path.abspath(path.join(path_to_app, embedded_profile))
		resource_rules = path.abspath(path.join(path_to_app, 'ResourceRules.plist'))

		path_to_pp = path.join(build.orig_wd, provisioning_profile)
		if not path.isfile(path_to_pp):
			raise IOSError("{path} is not a provisioning_profile: "
					"use the --ios.profile.provisioning_profile option".format(
					path=path_to_pp)
			)

		try:
			os.remove(path_to_embedded_profile)
		except Exception:
			LOG.warning("Couldn't remove {profile}".format(profile=path_to_embedded_profile))
		_copy(path_to_pp, path_to_embedded_profile)

		run_shell(codesign, '--force', '--preserve-metadata',
				'--entitlements', entitlements_file,
				'--sign', certificate,
				'--resource-rules={0}'.format(resource_rules),
				path_to_app)
Example #4
0
	def run_iphone_simulator(self):
		possible_app_location = '{0}/ios/simulator-*/'.format(self.path_to_ios_build)
		LOG.debug('Looking for apps at {0}'.format(possible_app_location))
		possible_apps = glob(possible_app_location)
		if not possible_apps:
			raise IOSError("Couldn't find iOS app to run it in the simulator")
		
		path_to_app = possible_apps[0]
		
		LOG.debug('trying to run app %s' % path_to_app)

		if path.exists(SIMULATOR_IN_42):
			LOG.debug("detected XCode version 4.2 or older")
			ios_sim_binary = "ios-sim-xc4.2"
		elif path.exists(SIMULATOR_IN_43):
			LOG.debug("detected XCode version 4.3 or newer")
			ios_sim_binary = "ios-sim-xc4.3"
		else:
			raise IOSError("Couldn't find iOS simulator in {old} or {new}".format(
				old=SIMULATOR_IN_42,
				new=SIMULATOR_IN_43,
			))
		logfile = tempfile.mkstemp()[1]
		subprocess.Popen([path.join(self._lib_path(), ios_sim_binary), "launch", path_to_app, '--stderr', logfile])
		LOG.info('Showing log output:')
		try:
			run_shell("tail", "-f", logfile, fail_silently=False, command_log_level=logging.INFO)
		finally:
			os.remove(logfile)
Example #5
0
    def build_apk_gradle(self, rollback_obj, cfg_dir, apk_cfg_info, apk_name):
        # 最终 apk 文件名格式为:GAMENAME_PKGNAME_APPID_CHANNELID_VERNAME_VERCODE.apk
        # Logging.debug_msg('修改apk文件名 game_name=%s pkg_name=%s app_id=%s channel_id=%s ver_name=%s ver_code=%s' % (game_name, pkg_name, app_id, channel_id, ver_name, ver_code))

        # 修改签名文件
        Logging.debug_msg('修改签名文件')
        keystore_path = utils.flat_path(
            os.path.join(
                cfg_dir,
                apk_cfg_info[PackAPK.CFG_SIGN][PackAPK.CFG_SIGN_FILE]))
        keystore_pass = apk_cfg_info[PackAPK.CFG_SIGN][
            PackAPK.CFG_SIGN_PASSWORD]
        alias = apk_cfg_info[PackAPK.CFG_SIGN][PackAPK.CFG_SIGN_ALIAS]
        alias_pass = apk_cfg_info[PackAPK.CFG_SIGN][
            PackAPK.CFG_SIGN_ALIAS_PASSWORD]
        self._modify_gradle_config(rollback_obj, self.output_path, apk_name,
                                   keystore_path, keystore_pass, alias,
                                   alias_pass)

        gradle_cmd = "cd %s;gradle clean;gradle aR" % self.proj_androidStudio_path
        try:
            utils.run_shell(gradle_cmd)
        except:
            Logging.warn_msg('gradle 命令行打包失败')

        Logging.debug_msg('gradle配置文件修改完成')
Example #6
0
def _create_apk_with_aapt(build, out_apk_name, path_info, package_name,
                          lib_path, dev_dir):
    LOG.info('Creating APK with aapt')

    run_shell(
        path_info.aapt,
        'p',  # create APK package
        '-F',
        out_apk_name,  # output name
        '-S',
        path.join(dev_dir, 'res'),  # uncompressed resources folder
        '-M',
        path.join(dev_dir, 'AndroidManifest.xml'),  # uncompressed xml manifest
        '-I',
        ensure_lib_available(
            build, 'android-platform.apk'
        ),  # Android platform to "compile" resources against
        '-A',
        path.join(dev_dir, 'assets'),  # Assets folder to include
        '-0',
        '',  # Don't compress any assets - Important for content provider access to assets
        '--rename-manifest-package',
        package_name,  # Package name
        '-f',  # Force overwrite
        path.join(dev_dir, 'bin'),  # Location of raw files (app binary)
        command_log_level=logging.DEBUG)
Example #7
0
    def build(self):
        Logging.log_msg("star build proto gen proto.js\n")

        #批处理
        try:
            utils.run_shell('pbjs -t json proto/fishing.proto > json/fishing.js')
        except Exception as e:
            raise_known_error("生成proto.js文件失败 msg=%s" % str(e))

        #修改文件增加'module.exports ='
        jsFile = utils.flat_path(os.path.join(self.js_path, 'fishing.js'))
        f1 = open(jsFile, "r")
        result = f1.read()
        f1.close()
        oResult = "module.exports = %s " % result
        f2 = open(jsFile, "w")
        f2.writelines(oResult)
        f2.close()
        Logging.log_msg("out file:%s" % jsFile)

        #将fishing.js文件拷贝到客户端的pb目录
        if os.path.exists(self.target_path):
            shutil.copy(jsFile, self.target_path)
            Logging.log_msg("move file fishing.js to path : %s \n" % self.target_path)

        Logging.log_msg("proto build success")
Example #8
0
	def run_iphone_simulator(self):
		if not sys.platform.startswith('darwin'):
			raise IOSError("iOS Simulator is only available on OS X, please change the iOS run settings in your local config.")
	
		possible_app_location = '{0}/ios/simulator-*/'.format(self.path_to_ios_build)
		LOG.debug('Looking for apps at {0}'.format(possible_app_location))
		possible_apps = glob(possible_app_location)
		if not possible_apps:
			raise IOSError("Couldn't find iOS app to run it in the simulator")
		
		path_to_app = possible_apps[0]
		
		LOG.debug('trying to run app %s' % path_to_app)

		if path.exists(SIMULATOR_IN_42):
			LOG.debug("Detected XCode version 4.2 or older")
			ios_sim_binary = "ios-sim-xc4.2"
		elif path.exists(SIMULATOR_IN_43):
			LOG.debug("Detected XCode version 4.3 or newer")
			ios_sim_binary = "ios-sim-xc4.3"
		else:
			raise IOSError("Couldn't find iOS simulator in {old} or {new}".format(
				old=SIMULATOR_IN_42,
				new=SIMULATOR_IN_43,
			))
		logfile = tempfile.mkstemp()[1]
		ios_sim_proc = subprocess.Popen([path.join(self._lib_path(), ios_sim_binary), "launch", path_to_app, '--stderr', logfile])
		LOG.info('Showing log output:')
		try:
			run_shell("tail", "-f", logfile, fail_silently=False, command_log_level=logging.INFO, check_for_interrupt=True)
		finally:
			lib.progressive_kill(ios_sim_proc.pid)
			os.remove(logfile)
Example #9
0
def _align_apk(path_info, signed_zipf_name, out_apk_name):
    LOG.info('Aligning apk')

    args = [
        path.join(path_info.sdk, 'tools', 'zipalign'), '-v', '4',
        signed_zipf_name, out_apk_name
    ]
    run_shell(*args)
Example #10
0
def _node(build, *args, **kw):
	node = "node"
	if not utils.which(node):
		raise WebError("couldn't find {tool} on your PATH or in likely "
				"locations - is it installed?".format(tool=node))

	kw['check_for_interrupt'] = True
	run_shell(node, *args, **kw)
Example #11
0
def _node(build, *args, **kw):
    node = "node"
    if not utils.which(node):
        raise WebError("couldn't find {tool} on your PATH or in likely "
                       "locations - is it installed?".format(tool=node))

    kw['check_for_interrupt'] = True
    run_shell(node, *args, **kw)
Example #12
0
def run_firefox(build, build_type_dir):
	python = sys.executable
	lib_path = path.abspath(
		path.join(__file__, path.pardir, path.pardir, 'lib')
	)
	try:
		run_shell(python, path.join(lib_path, 'run-firefox.zip'), command_log_level=logging.INFO)
	finally:
		_clean_firefox(build_type_dir)
Example #13
0
	def run_idevice(self, build, device, provisioning_profile, certificate=None, certificate_path=None, certificate_password=None):
		possible_app_location = '{0}/ios/device-*/'.format(self.path_to_ios_build)
		LOG.debug('Looking for apps at {0}'.format(possible_app_location))
		possible_apps = glob(possible_app_location)
		if not possible_apps:
			raise IOSError("Couldn't find iOS app to run on a device")
		
		path_to_app = possible_apps[0]

		LOG.debug("Signing {app}".format(app=path_to_app))
		
		plist_str = self._grab_plist_from_binary_mess(build, provisioning_profile)
		plist_dict = self._parse_plist(plist_str)
		self.check_plist_dict(plist_dict, self.path_to_ios_build)
		LOG.info("Plist OK")
		
		if sys.platform.startswith('darwin'):
			with temp_file() as temp_file_path:
				self._create_entitlements_file(build, plist_dict, temp_file_path)
				
				self._sign_app(build=build,
					provisioning_profile=provisioning_profile,
					certificate=certificate,
					entitlements_file=temp_file_path,
				)
			
			fruitstrap = [ensure_lib_available(build, 'fruitstrap'), '-d', '-g', ensure_lib_available(build, 'gdb-arm-apple-darwin'), '-t', '10', '-b', path_to_app]
			if device and device.lower() != 'device':
				# pacific device given
				fruitstrap.append('-i')
				fruitstrap.append(device)
				LOG.info('Installing app on device {device}: is it connected?'.format(device=device))
			else:
				LOG.info('Installing app on device: is it connected?')

			run_shell(*fruitstrap, fail_silently=False, command_log_level=logging.INFO, filter=lambda x: not x.startswith("warning"), check_for_interrupt=True)
		elif sys.platform.startswith('win'):
			with temp_file() as ipa_path:
				self.create_ipa_from_app(
					build=build,
					provisioning_profile=provisioning_profile,
					output_path_for_ipa=ipa_path,
					certificate_path=certificate_path,
					certificate_password=certificate_password,
				)
				win_ios_install = [ensure_lib_available(build, 'win-ios-install.exe')]
				if device and device.lower() != 'device':
					# pacific device given
					win_ios_install.append(device)
					LOG.info('Installing app on device {device}: is it connected?'.format(device=device))
				else:
					LOG.info('Installing app on device: is it connected?')

				win_ios_install.append(ipa_path)
				win_ios_install.append(_generate_package_name(build))

				run_shell(*win_ios_install, fail_silently=False, command_log_level=logging.INFO, check_for_interrupt=True)
Example #14
0
def _follow_log(path_info, chosen_device):
	LOG.info('Clearing android log')

	args = [path_info.adb, '-s', chosen_device, 'logcat', '-c']
	run_shell(*args, command_log_level=logging.INFO)

	LOG.info('Showing android log')

	run_shell(path_info.adb, '-s', chosen_device, 'logcat', 'WebCore:D', 'Forge:D', '*:s', command_log_level=logging.INFO, check_for_interrupt=True)
Example #15
0
def _sign_zipf(lib_path, jre, keystore, storepass, keyalias, keypass,
               signed_zipf_name, zipf_name):
    args = [
        path.join(jre, 'java'), '-jar',
        path.join(lib_path, 'apk-signer.jar'), '--keystore', keystore,
        '--storepass', storepass, '--keyalias', keyalias, '--keypass', keypass,
        '--out', signed_zipf_name, zipf_name
    ]
    run_shell(*args)
Example #16
0
def run(common_args, cmd_argv):
    args = docopt(scm.mount.USAGE, argv=cmd_argv)

    # Success Msg
    if (args['get-success-msg']):
        print("Repo mounted and committed to your repo")
        return

    # Error Msg
    if (args['get-error-msg']):
        print("")  # No message
        return

    # Check if there are pending repo changes
    cmd = f'git diff-index HEAD --exit-code --quiet'
    t = utils.run_shell(cmd, False)
    cmd = f'git diff-index --cached HEAD --exit-code --quiet'
    t2 = utils.run_shell(cmd, False)
    utils.check_results(
        t,
        "ERROR: Your local repo has pending tree modification (i.e. need to do a commit/revert)."
    )
    utils.check_results(
        t2,
        "ERROR: Your local repo has pending index modification (i.e. need to do a commit/revert)."
    )

    # -b option is not supported/needed
    if (args['-b'] != None):
        sys.exit(
            "The '-b' option is not supported/needed.  Use a 'remote-ref' as the <id> argument"
        )

    # Default Package name
    pkg = args['<repo>']
    if (args['-p']):
        pkg = args['-p']

    # Make sure the Parent destination directory exists
    dst = args['<dst>']
    utils.mkdirs(dst)

    # Set directory for the subtree directory
    dst = os.path.join(dst, pkg)
    dst = utils.force_unix_dir_sep(dst)
    utils.print_verbose(f"Destination for the copy: {dst}")

    # Create a 'subtree'
    cmd = f'git subtree add --prefix {dst} {args["<origin>"]}/{args["<repo>"]}.git {args["<id>"]} --squash'
    t = utils.run_shell(cmd, common_args['-v'])
    if (utils.is_error(t)):  # Clean-up dst dir if there was failure
        utils.remove_tree(dst)
    utils.check_results(
        t,
        "ERROR: Failed to create a subtree for the specified package/repository."
    )
Example #17
0
def ln(src, dst):
    src = gen_src(src)
    dstTrue = path.join(dst, path.basename(src))
    if path.exists(dstTrue):
        if path.samefile(src, dstTrue):
            return
        else:
            raise ConflictException(dstTrue)
    run_shell("mkdir -p {}", dst)
    run_shell("ln -s {} {}", src, dst)
Example #18
0
def _open_url(url):
	'''Attempt to open the provided URL in the default browser'''
	if sys.platform.startswith('darwin'):
		run_shell('open', url, fail_silently=True)
	elif sys.platform.startswith('win'):
		# 'start' seems to need shell=True to be found (probably a builtin)
		cmd = subprocess.list2cmdline(['start', url])
		subprocess.call(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
	elif sys.platform.startswith('linux'):
		run_shell('xdg-open', url, fail_silently=True)
Example #19
0
def _open_url(url):
	'''Attempt to open the provided URL in the default browser'''
	if sys.platform.startswith('darwin'):
		run_shell('open', url, fail_silently=True)
	elif sys.platform.startswith('win'):
		# 'start' seems to need shell=True to be found (probably a builtin)
		cmd = subprocess.list2cmdline(['start', url])
		subprocess.call(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
	elif sys.platform.startswith('linux'):
		run_shell('xdg-open', url, fail_silently=True)
Example #20
0
def _open_url(url):
    """Attempt to open the provided URL in the default browser"""
    if sys.platform.startswith("darwin"):
        run_shell("open", url, fail_silently=True)
    elif sys.platform.startswith("win"):
        # 'start' seems to need shell=True to be found (probably a builtin)
        cmd = subprocess.list2cmdline(["start", url])
        subprocess.call(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    elif sys.platform.startswith("linux"):
        run_shell("xdg-open", url, fail_silently=True)
Example #21
0
def run_firefox(build, build_type_dir):
    python = sys.executable
    lib_path = path.abspath(
        path.join(__file__, path.pardir, path.pardir, 'lib'))
    try:
        run_shell(python,
                  path.join(lib_path, 'run-firefox.zip'),
                  command_log_level=logging.INFO)
    finally:
        _clean_firefox(build_type_dir)
Example #22
0
def ln(src, dst):
    src = gen_src(src)
    dstTrue = path.join(dst, path.basename(src))
    if path.exists(dstTrue):
        if path.samefile(src, dstTrue):
            return
        else:
            raise ConflictException(dstTrue)
    run_shell("mkdir -p {}", dst)
    run_shell("ln -s {} {}", src, dst)
Example #23
0
def run_osx(build):
    args = [
        os.path.join('development', 'osx', 'Forge.app', 'Contents', 'MacOS',
                     'ForgeTemplate')
    ]
    # Bring app to foreground after 1 second
    subprocess.Popen([
        "osascript", "-e", "delay 1", "-e",
        'tell application "%s" to activate' % build.config['name']
    ])
    run_shell(*args, command_log_level=logging.INFO, check_for_interrupt=True)
Example #24
0
def _npm(*args, **kw):
	if sys.platform.startswith("win"):
		npm = "npm.cmd"
	else:
		npm = "npm"

	try:
		run_shell(npm, *args, **kw)
	except OSError as e:
		if e.errno == errno.ENOENT:
			raise WebError("failed to run npm: do you have Node.js installed and on your path?")
def _follow_log(path_info, chosen_device):
	LOG.info('Clearing android log')
	args = [path_info.adb, '-s', chosen_device, 'logcat', '-c']
	proc = Popen(args, stdout=sys.stdout, stderr=sys.stderr)
	proc.wait()

	LOG.info('Showing android log')

	# XXX: need to ensure we're out of the development folder before running
	# logcat, otherwise Trigger Toolkit seems to inherit some kind of lock on
	# the android folder :(
	os.chdir(path.abspath('/'))
	run_shell(path_info.adb, '-s', chosen_device, 'logcat', 'WebCore:D', 'Forge:D', '*:s', command_log_level=logging.INFO)
Example #26
0
def _npm(build, *args, **kw):
	if sys.platform.startswith("win"):
		npm = "npm.cmd"
	else:
		npm = "npm"
	if not utils.which(npm):
		raise WebError("""Couldn't find {tool} on your PATH or in likely locations - is it installed?

You can use the 'node_path' setting in your local configuration to set a custom install directory"""
.format(tool=npm))

	kw['check_for_interrupt'] = True
	run_shell(npm, *args, **kw)
def _create_apk_with_aapt(path_info):
	LOG.info('Creating APK with aapt')

	lib_path = path.join(
		os.getcwd(), path.pardir, path.pardir,
		".template", "lib",
	)
	
	apk_name = 'app.apk'
	
	run_shell(path_info.aapt, 'p', '-F', apk_name, '-S', 'res', '-M', 'AndroidManifest.xml', '-I', path.join(lib_path, 'android-platform.apk'), '-A', 'assets', '-f', 'output', command_log_level=logging.DEBUG)
			
	return apk_name
Example #28
0
def _npm(build, *args, **kw):
	if sys.platform.startswith("win"):
		npm = "npm.cmd"
	else:
		npm = "npm"
	if not utils.which(npm):
		raise WebError("""Couldn't find {tool} on your PATH or in likely locations - is it installed?

You can use the 'node_path' setting in your local configuration to set a custom install directory"""
.format(tool=npm))

	kw['check_for_interrupt'] = True
	run_shell(npm, *args, **kw)
Example #29
0
def _kill_adb():
    if sys.platform.startswith('win'):
        run_shell('taskkill', '/T', '/IM', 'adb.exe', fail_silently=True)
        run_shell('taskkill', '/T', '/F', '/IM', 'adb.exe', fail_silently=True)
    else:
        run_shell('killall', 'adb', fail_silently=True)
        run_shell('killall', '-9', 'adb', fail_silently=True)
Example #30
0
def _kill_adb():
	if sys.platform.startswith('win'):
		run_shell('taskkill', '/T', '/IM', 'adb.exe', fail_silently=True)
		run_shell('taskkill', '/T', '/F', '/IM', 'adb.exe', fail_silently=True)
	else:
		run_shell('killall', 'adb', fail_silently=True)
		run_shell('killall', '-9', 'adb', fail_silently=True)
Example #31
0
def _kill_adb():
    if sys.platform.startswith("win"):
        run_shell("taskkill", "/T", "/IM", "adb.exe", fail_silently=True)
        run_shell("taskkill", "/T", "/F", "/IM", "adb.exe", fail_silently=True)
    else:
        run_shell("killall", "adb", fail_silently=True)
        run_shell("killall", "-9", "adb", fail_silently=True)
Example #32
0
def _npm(*args, **kw):
    if sys.platform.startswith("win"):
        npm = "npm.cmd"
    else:
        npm = "npm"

    kw['check_for_interrupt'] = True
    try:
        run_shell(npm, *args, **kw)
    except OSError as e:
        if e.errno == errno.ENOENT:
            raise WebError(
                "failed to run npm: do you have Node.js installed and on your path?"
            )
Example #33
0
 def build_creator_proj(self):
     Logging.debug_msg('开始构建creator项目')
     try:
         if sys.platform == "win32":
             utils.run_shell(
                 'cd /d %s & CocosCreator.exe --path %s --build "platform=android;debug=false"'
                 % (self.creator_exe_path, self.creator_proj_path))
         else:
             creator_path = '/Applications/CocosCreator.app/Contents/MacOS'
             utils.run_shell(
                 'pushd "%s";CocosCreator --path %s --build "platform=android;debug=false";popd'
                 % (creator_path, self.creator_proj_path))
     except Exception as e:
         raise_known_error("Creator 项目命令行构建失败 msg=%s" % str(e))
     Logging.debug_msg('构建creator项目完成')
Example #34
0
def _create_apk_with_aapt(build, out_apk_name, path_info, package_name, lib_path, dev_dir):
	LOG.info('Creating APK with aapt')

	run_shell(path_info.aapt,
		'p', # create APK package
		'-F', out_apk_name, # output name
		'-S', path.join(dev_dir, 'res'), # uncompressed resources folder
		'-M', path.join(dev_dir, 'AndroidManifest.xml'), # uncompressed xml manifest
		'-I', ensure_lib_available(build, 'android-platform.apk'), # Android platform to "compile" resources against
		'-A', path.join(dev_dir, 'assets'), # Assets folder to include
		'-0', '', # Don't compress any assets - Important for content provider access to assets
		'--rename-manifest-package', package_name, # Package name
		'-f', # Force overwrite
		path.join(dev_dir, 'bin'), # Location of raw files (app binary)
		command_log_level=logging.DEBUG)
Example #35
0
 def __find(self, title):
     self.pattern = messages.Entry(title, 'Type search string', '', True, False).run()
     if self.pattern is None or self.pattern == '':
         return -1
     filename = os.path.abspath(self.fc.filename)
     mode = (self.mode==MODE_TEXT) and 'n' or 'b'
     try:
         cmd = '%s -i%c \"%s\" \"%s\"' % (sysprogs['grep'], mode,
                                          self.pattern, filename)
         st, buf = run_shell(encode(cmd), path=u'.', return_output=True)
     except OSError:
         self.show()
         messages.error('Find error: Can\'t open file')
         return -1
     if st == -1:
         self.show()
         messages.error('Find error\n' + buf)
         self.matches = []
         return -1
     else:
         try:
             self.matches = [int(l.split(':')[0]) for l in buf.split('\n') if l]
         except (ValueError, TypeError):
             self.matches = []
         return 0
Example #36
0
def _git(cmd, *args, **kwargs):
    """Runs a git command and scrapes the output for common problems, so that we can try
	to advise the user about them

	e.g. _git('push', '--all')
	"""
    try:
        output = run_shell('git', cmd, *args, **kwargs)
    except OSError as e:
        if e.errno == errno.ENOENT:
            # TODO: download portable copy of git/locate git?
            raise WebError(
                "Can't run git commands - you need to install git and make sure it's in your PATH"
            )
    except ShellError as e:

        def _key_problem(output):
            lines = output.split('\n')
            if len(lines) > 0:
                first = lines[0]
                return first.startswith('Permission denied (publickey)')

        if _key_problem(e.output):
            # TODO: prompt user with choice to use existing .pub in ~/.ssh
            # or create new keypair and submit to heroku
            raise WebError(
                'Failed to access remote git repo, you need to set up key based access'
            )

        raise WebError('Problem running git {cmd}:\n {output}'.format(
            cmd=cmd, output=e.output))

    return output
Example #37
0
def run(common_args, cmd_argv):
    args = docopt(__doc__, argv=cmd_argv)

    # -b option is not supported/needed
    if (args['-b'] != None):
        sys.exit(
            "The '-b' option is not supported/needed.  Use a 'remote-ref' as the <id> argument"
        )

    # Default Package name
    pkg = args['<repo>']
    if (args['-p']):
        pkg = args['-p']

    # Set directory for the subtree directory
    dst = os.path.join(args['<dst>'], pkg)
    dst = utils.force_unix_dir_sep(dst)
    utils.print_verbose(f"Location of the copy being updated: {dst}")

    # Update the 'subtree'
    cmd = f'git subtree pull --prefix {dst} {args["<origin>"]}/_git/{args["<repo>"]} {args["<id>"]} --squash'
    t = utils.run_shell(cmd, common_args['-v'])
    utils.check_results(
        t,
        "ERROR: Failed the update a subtree for the specified package/repository."
    )
Example #38
0
def _git(cmd, *args, **kwargs):
	"""Runs a git command and scrapes the output for common problems, so that we can try
	to advise the user about them

	e.g. _git('push', '--all')
	"""
	try:
		output = run_shell('git', cmd, *args, **kwargs)
	except OSError as e:
		if e.errno == errno.ENOENT:
			# TODO: download portable copy of git/locate git?
			raise WebError("Can't run git commands - you need to install git and make sure it's in your PATH")
	except ShellError as e:
		def _key_problem(output):
			lines = output.split('\n')
			if len(lines) > 0:
				first = lines[0]
				return first.startswith('Permission denied (publickey)')

		if _key_problem(e.output):
			# TODO: prompt user with choice to use existing .pub in ~/.ssh
			# or create new keypair and submit to heroku
			raise WebError('Failed to access remote git repo, you need to set up key based access')

		raise WebError('Problem running git {cmd}:\n {output}'.format(cmd=cmd, output=e.output))

	return output
Example #39
0
 def __find(self, title):
     self.pattern = messages.Entry(title, 'Type search string', '', True,
                                   False).run()
     if self.pattern is None or self.pattern == '':
         return -1
     filename = os.path.abspath(self.fc.filename)
     mode = (self.mode == MODE_TEXT) and 'n' or 'b'
     try:
         cmd = '%s -i%c \"%s\" \"%s\"' % (sysprogs['grep'], mode,
                                          self.pattern, filename)
         st, buf = run_shell(encode(cmd), path=u'.', return_output=True)
     except OSError:
         self.show()
         messages.error('Find error: Can\'t open file')
         return -1
     if st == -1:
         self.show()
         messages.error('Find error\n' + buf)
         self.matches = []
         return -1
     else:
         try:
             self.matches = [
                 int(l.split(':')[0]) for l in buf.split('\n') if l
             ]
         except (ValueError, TypeError):
             self.matches = []
         return 0
Example #40
0
def _follow_log(path_info, chosen_device):
    LOG.info('Clearing android log')

    args = [path_info.adb, '-s', chosen_device, 'logcat', '-c']
    run_shell(*args, command_log_level=logging.INFO)

    LOG.info('Showing android log')

    run_shell(path_info.adb,
              '-s',
              chosen_device,
              'logcat',
              'WebCore:D',
              'Forge:D',
              '*:s',
              command_log_level=logging.INFO,
              check_for_interrupt=True)
Example #41
0
 def build_creator_proj(self):
     Logging.debug_msg('开始构建creator项目')
     Logging.debug_msg(self.creator_proj_parth)
     creator_exe_path = utils.check_environment_variable('CREATOR_PATH')
     try:
         if sys.platform == "win32":
             utils.run_shell(
                 'cd /d %s & CocosCreator.exe --path %s --build "platform=wechatgame;debug=false"'
                 % (creator_exe_path, self.creator_proj_parth))
         else:
             creator_path = '/Applications/CocosCreator.app/Contents/MacOS/'
             utils.run_shell(
                 '%sCocosCreator --path %s --build "platform=wechatgame;debug=false"'
                 % (creator_path, self.creator_proj_parth))
     except Exception as e:
         raise_known_error("Creator 项目命令行构建失败 msg=%s" % str(e))
     Logging.debug_msg('构建creator项目完成')
Example #42
0
    def encrypt_file(self, src_path, dst_path):
        if not os.path.isdir(dst_path):
            os.makedirs(dst_path)

        if self.is_exclude(src_path):
            self.output_info('%s 文件被排除!' % src_path)
            if not self.dst_is_src:
                # 如果文件被排除,而且源路径与目标路径不同,那么需要将源文件拷贝到目标路径
                shutil.copy(src_path,
                            os.path.join(dst_path, os.path.basename(src_path)))
            return

        basename, ext = os.path.splitext(os.path.basename(src_path))
        if os.path.basename(src_path) == 'manifest':
            dst_ext = '.wjd'
        else:
            dst_ext = ENCRYPT_CFG[ext]
        dst_file_path = os.path.join(dst_path, '%s%s' % (basename, dst_ext))
        self.output_info('Encrypt %s to %s' % (src_path, dst_file_path))

        if src_path.lower() == dst_file_path.lower():
            # 源路径与目标路径一致,需要使用临时文件
            encrypt_file_path = '%s_temp' % dst_file_path
        else:
            encrypt_file_path = dst_file_path

        cur_path = os.path.dirname(__file__)
        if utils.os_is_win32():
            cmd_tool_path = utils.flat_path(
                os.path.join(cur_path, 'bin/encryptor.exe'))
        else:
            cmd_tool_path = utils.flat_path(
                os.path.join(cur_path, 'bin/encryptor'))

        encrypt_cmd = '%s "%s" "%s"' % (cmd_tool_path, src_path,
                                        encrypt_file_path)
        utils.run_shell(encrypt_cmd, quiet=True)

        if encrypt_file_path != dst_file_path:
            # 是生成的临时文件,需要替换
            os.remove(src_path)
            os.rename(encrypt_file_path, dst_file_path)

        if self.rm_src and (src_path.lower() != dst_file_path.lower()):
            os.remove(src_path)
Example #43
0
    def run_iphone_simulator(self):
        if not sys.platform.startswith('darwin'):
            raise IOSError(
                "iOS Simulator is only available on OS X, please change the iOS run settings in your local config."
            )

        possible_app_location = '{0}/ios/simulator-*/'.format(
            self.path_to_ios_build)
        LOG.debug('Looking for apps at {0}'.format(possible_app_location))
        possible_apps = glob(possible_app_location)
        if not possible_apps:
            raise IOSError("Couldn't find iOS app to run it in the simulator")

        path_to_app = possible_apps[0]

        LOG.debug('trying to run app %s' % path_to_app)

        if path.exists(SIMULATOR_IN_42):
            LOG.debug("Detected XCode version 4.2 or older")
            ios_sim_binary = "ios-sim-xc4.2"
        elif path.exists(SIMULATOR_IN_43):
            LOG.debug("Detected XCode version 4.3 or newer")
            ios_sim_binary = "ios-sim-xc4.3"
        else:
            raise IOSError(
                "Couldn't find iOS simulator in {old} or {new}".format(
                    old=SIMULATOR_IN_42,
                    new=SIMULATOR_IN_43,
                ))
        logfile = tempfile.mkstemp()[1]
        ios_sim_proc = subprocess.Popen([
            path.join(self._lib_path(), ios_sim_binary), "launch", path_to_app,
            '--stderr', logfile
        ])
        LOG.info('Showing log output:')
        try:
            run_shell("tail",
                      "-f",
                      logfile,
                      fail_silently=False,
                      command_log_level=logging.INFO,
                      check_for_interrupt=True)
        finally:
            lib.progressive_kill(ios_sim_proc.pid)
            os.remove(logfile)
Example #44
0
def _sign_zipf(lib_path, jre, keystore, storepass, keyalias, keypass, signed_zipf_name, zipf_name):
    args = [
        path.join(jre, "java"),
        "-jar",
        path.join(lib_path, "apk-signer.jar"),
        "--keystore",
        keystore,
        "--storepass",
        storepass,
        "--keyalias",
        keyalias,
        "--keypass",
        keypass,
        "--out",
        signed_zipf_name,
        zipf_name,
    ]
    run_shell(*args)
def run_wp(build, device):
    path_to_wp_build = path.abspath(path.join("development", "wp"))

    path_to_xap = _create_xap_from_app(build=build, path_to_wp_build=path_to_wp_build, target="development")
    LOG.info("Running: %s" % path_to_xap)

    automation = path.join(path_to_wp_build, "automation", "bin", "Release", "automation.exe")
    if not path.exists(automation):
        raise WPError("Couldn't find Windows Phone deployment tool")

    if not device or device.lower() == "simulator":
        LOG.info("Running Windows Phone Emulator")
        target = "emulator"
    else:
        LOG.info("Running on Windows Phone device: {device}".format(device=device))
        target = "device"

    run_shell(automation, path_to_xap, target, fail_silently=False, verbose=True, logger=LOG)
Example #46
0
def soft_label_embedding_creation(forward_dir, ali_dir, temp,
                                  max_processing_num):
    log_dir = forward_dir
    cmd = "hmm-info " + ali_dir + "/final.mdl | awk '/pdfs/{print $4}'"
    pdf_num = run_shell(cmd, log_dir + "/log.log")
    manager = multiprocessing.Manager()

    embedding_list = manager.list()
    total_pdf_list = manager.list()
    prediction_ark_list = sorted(
        glob.glob(forward_dir + "/exp_files/" + "*ark"))

    # read lab from ali
    lab = {
        k: v
        for k, v in read_vec_int_ark(
            "gunzip -c " + ali_dir + "/ali*.gz | " + "ali-to-pdf" + " " +
            ali_dir + "/final.mdl ark:- ark:-|", log_dir)
    }
    processes = []
    # produce soft label embedding and total pdf num in multiprocess
    for process_index in range(0, len(prediction_ark_list)):
        p = multiprocessing.Process(
            target=sub_process,
            kwargs={
                "process_index": process_index,
                "pdf_num": pdf_num,
                "temp": temp,
                "prediction_ark_list": prediction_ark_list,
                "embedding_list": embedding_list,
                "total_pdf_list": total_pdf_list,
                "lab": lab,
                "log_dir": log_dir,
            },
        )
        processes.append(p)
        if len(processes) > max_processing_num:
            processes[0].join()
            del processes[0]
        p.start()
        # sub_process(process_index, prediction_ark_list, embedding_list, total_pdf_list, lab, log_dir)
    for process in processes:
        process.join()
    # sum all the results of multiprocess
    embedding = np.zeros((int(pdf_num), int(pdf_num)), dtype=np.float32)
    total_pdf = np.zeros(int(pdf_num), dtype=np.int64)
    for process_index in range(0, len(prediction_ark_list)):
        embedding += embedding_list[process_index]
        total_pdf += total_pdf_list[process_index]
    for pdf_index in range(0, int(pdf_num)):
        embedding[pdf_index] /= float(total_pdf[pdf_index])
    with open(
            os.path.join(forward_dir,
                         "temp_" + str(temp) + "_soft_label_embedding.pkl"),
            "wb") as f_out:
        pickle.dump(embedding, f_out)
    return embedding, total_pdf
Example #47
0
def _sign_zipf(lib_path, jre, keystore, storepass, keyalias, keypass, signed_zipf_name, zipf_name):
	args = [
		path.join(jre,'java'),
		'-jar',
		path.join(lib_path, 'apk-signer.jar'),
		'--keystore',
		keystore,
		'--storepass',
		storepass,
		'--keyalias',
		keyalias,
		'--keypass',
		keypass,
		'--out',
		signed_zipf_name,
		zipf_name
	]
	run_shell(*args)
Example #48
0
def _follow_log(path_info, chosen_device):
    LOG.info("Clearing android log")

    args = [path_info.adb, "-s", chosen_device, "logcat", "-c"]
    run_shell(*args, command_log_level=logging.INFO)

    LOG.info("Showing android log")

    run_shell(
        path_info.adb,
        "-s",
        chosen_device,
        "logcat",
        "WebCore:D",
        "Forge:D",
        "*:s",
        command_log_level=logging.INFO,
        check_for_interrupt=True,
    )
Example #49
0
def shell(cmd):
    """ Executes the specified command. 'cmd' is string of that contains the 
        command with any optional arguments.
        
        The method returns a tuple with the exit code and output from the 
        command.
    """
    exitcode, result = utils.run_shell(cmd)
    output.writeline_verbose(result)
    return exitcode, result
Example #50
0
def run(common_args, cmd_argv):
    args = docopt(scm.findroot.USAGE, argv=cmd_argv)

    # Update the 'subtree'
    cmd = f'git rev-parse --show-toplevel'
    t = utils.run_shell(cmd, common_args['-v'])
    utils.check_results(
        t,
        "ERROR: Failed find to find the root directory of local repository.")
    print(utils.standardize_dir_sep(t[1]))
Example #51
0
def run_web(build):
    """Run an instance of Node locally"""
    # TODO: port should be a parameter/configuration
    port = 3000

    def show_local_server():
        LOG.info("Attempting to open browser at http://localhost:%d/" % port)
        _open_url("http://localhost:%d/" % port)

    with cd(path.join("development", "web")):
        timer = None
        try:
            # TODO: annoyingly difficult to kill npm processes on windows - npm.cmd actually
            # launches an instance of node as a subprocess which is the real thing you need to kill!
            # might be possible to kill npm.cmd in a nicer way, e.g. sending a CTRL_C event, needs
            # a bit of experimentation
            _npm("install")

            attempts = 0
            while not _port_available(port):
                LOG.info('Port still in use, attempting to send a kill signal')
                #TODO: appropriate timeout and handling
                requests.post('http://localhost:%d/_forge/kill/' % port)

                time.sleep(1)

                attempts += 1
                if attempts > 5:
                    raise WebError(
                        "Port %d seems to be in use, you should specify a different port to use"
                        % port)

            timer = threading.Timer(3, show_local_server).start()
            run_shell("node",
                      "./web.js",
                      command_log_level=logging.INFO,
                      check_for_interrupt=True,
                      env=dict(os.environ, PORT=str(port), FORGE_DEBUG='1'))

        finally:
            if timer:
                timer.cancel()
Example #52
0
    def build_apk_gradle(self, rollback_obj, cfg_dir, apk_cfg_info, apk_name):
        # 最终 apk 文件名格式为:GAMENAME_PKGNAME_APPID_CHANNELID_VERNAME_VERCODE.apk
        # Logging.debug_msg('修改apk文件名 game_name=%s pkg_name=%s app_id=%s channel_id=%s ver_name=%s ver_code=%s' % (game_name, pkg_name, app_id, channel_id, ver_name, ver_code))

        # 修改签名文件
        Logging.debug_msg('修改签名文件')
        self.setGradleConfig(rollback_obj, cfg_dir, apk_cfg_info, apk_name)
        try:
            if sys.platform == "win32":
                utils.run_shell(
                    'cd /d %s & set ANDROID_HOME="%s" & gradlew clean & gradlew aR --stacktrace'
                    % (self.proj_android_path, self.sdk_root))
            else:
                utils.run_shell(
                    'pushd "%s";export ANDROID_HOME="%s";./gradlew clean;./gradlew aR --stacktrace;popd'
                    % (self.proj_android_path, self.sdk_root))
        except Exception as e:
            raise_known_error("gradle 命令行打包失败 msg=%s" % str(e))

        Logging.debug_msg('gradle配置文件修改完成')
Example #53
0
def _run_python_code(build, extra_path, entry_point):
    python_runner = ensure_lib_available(build, 'python_runner.py')

    if sys.platform.startswith("win"):
        runner = ensure_lib_available(build, 'python_runner_win.exe')
        run_shell(runner,
                  extra_path,
                  entry_point,
                  command_log_level=logging.INFO,
                  check_for_interrupt=True)
    elif sys.platform.startswith("darwin"):
        runner = ensure_lib_available(build, 'python_runner_darwin')
        run_shell(runner,
                  extra_path,
                  entry_point,
                  command_log_level=logging.INFO,
                  check_for_interrupt=True,
                  create_process_group=True)
    else:
        python = sys.executable
        run_shell(python,
                  python_runner,
                  extra_path,
                  entry_point,
                  command_log_level=logging.INFO,
                  check_for_interrupt=True)
Example #54
0
    def build_creator_proj(self):
        Logging.debug_msg('开始构建creator项目')
        Logging.debug_msg(self.creator_proj_path)
        try:
            # 删除之前构建生成的文件夹
            if os.path.isdir(self.proj_parth):
                shutil.rmtree(self.proj_parth)

            json_file = os.path.join(self.creator_proj_path,
                                     "settings/wechatgame.json")
            loads = self.readJson(json_file)
            loads["startSceneAssetBundle"] = False

            self.writeJson(json_file, loads)

            # https://docs.cocos.com/creator/manual/en/publish/publish-in-command-line.html
            buildoptions = ";".join([
                "platform=wechatgame", "buildPath=build", "debug=false",
                "sourceMaps=false", "md5Cache=true",
                "mainCompressionType=merge_all_json", "mainIsRemote=false"
            ])
            paramFmt = '--path {path} --build "{options}"'
            params = paramFmt.format(path=self.creator_proj_path,
                                     options=buildoptions)

            if sys.platform == "win32":
                creator_exe_path = utils.check_environment_variable(
                    'CREATOR_PATH')
                cmdline = 'cd /d "%s" & CocosCreator.exe %s' % (
                    creator_exe_path, params)
                utils.run_shell(cmdline)
            else:
                creator_path = '/Applications/CocosCreator/Creator/2.4.3/CocosCreator.app/Contents/MacOS/CocosCreator'
                utils.run_shell('%s %s' % (creator_path, params))

        except Exception as e:
            raise_known_error("Creator 项目命令行构建失败 msg=%s" % str(e))
        Logging.debug_msg('构建creator项目完成')
def _sign_zipf(jre, keystore, storepass, keyalias, keypass, signed_zipf_name, zipf_name):
	lib_path = path.join(
		os.getcwd(), path.pardir, path.pardir,
		".template", "lib",
	)
	
	args = [
		path.join(jre,'java'),
		'-jar',
		path.join(lib_path, 'apk-signer.jar'),
		'--keystore',
		keystore,
		'--storepass',
		storepass,
		'--keyalias',
		keyalias,
		'--keypass',
		keypass,
		'--out',
		signed_zipf_name,
		zipf_name
	]
	run_shell(*args)
Example #56
0
def _create_apk_with_aapt(out_apk_name, path_info, package_name, lib_path, dev_dir):
    LOG.info("Creating APK with aapt")

    run_shell(
        path_info.aapt,
        "p",  # create APK package
        "-F",
        out_apk_name,  # output name
        "-S",
        path.join(dev_dir, "res"),  # uncompressed resources folder
        "-M",
        path.join(dev_dir, "AndroidManifest.xml"),  # uncompressed xml manifest
        "-I",
        path.join(lib_path, "android-platform.apk"),  # Android platform to "compile" resources against
        "-A",
        path.join(dev_dir, "assets"),  # Assets folder to include
        "-0",
        "",  # Don't compress any assets - Important for content provider access to assets
        "--rename-manifest-package",
        package_name,  # Package name
        "-f",  # Force overwrite
        path.join(dev_dir, "output"),  # Location of raw files (app binary)
        command_log_level=logging.DEBUG,
    )
Example #57
0
def run_web(build):
	"""Run an instance of Node locally"""
	# TODO: port should be a parameter/configuration
	port = 3000

	def show_local_server():
		LOG.info("Attempting to open browser at http://localhost:%d/" % port)
		_open_url("http://localhost:%d/" % port)

	with cd(path.join("development", "web")):
		timer = None
		try:
			# TODO: annoyingly difficult to kill npm processes on windows - npm.cmd actually
			# launches an instance of node as a subprocess which is the real thing you need to kill!
			# might be possible to kill npm.cmd in a nicer way, e.g. sending a CTRL_C event, needs
			# a bit of experimentation
			_npm("install")

			attempts = 0
			while not _port_available(port):
				LOG.info('Port still in use, attempting to send a kill signal')
				#TODO: appropriate timeout and handling
				requests.post('http://localhost:%d/_forge/kill/' % port)

				time.sleep(1)

				attempts += 1
				if attempts > 5:
					raise WebError("Port %d seems to be in use, you should specify a different port to use" % port)

			timer = threading.Timer(3, show_local_server).start()
			run_shell("node", "./web.js", command_log_level=logging.INFO, check_for_interrupt=True, env=dict(os.environ, PORT=str(port), FORGE_DEBUG='1'))

		finally:
			if timer:
				timer.cancel()
Example #58
0
def git(src, dst):
    if path.exists(dst):
        if path.isdir(dst):
            x =run_shell_text("cd {}; git remote show origin -n", dst)
            if x.find(src):
                run_shell("cd {}; git pull", dst)
                return
        raise ConflictException(dstTrue)
    run_shell("mkdir -p {}", dst)
    run_shell("git clone {} {}", src, dst)
Example #59
0
    def do_compress_uncompress_file(self, filename, path, dest, type):

        fullfile = os.path.join(path, filename)
        if not os.path.isfile(fullfile):
            return -1, '%s: can\'t un/compress' % filename

        c = check_compressed(fullfile,'file')
        if c == None or c.type != type:

            #return -1, '%s: file type' % c.type
            packager = packagers_by_type[type]
            c = packager(fullfile)
            cmd = c.build_compress_cmd()
        else:
            cmd = c.build_uncompress_cmd()
        st, msg = utils.run_shell(cmd, path, return_output = True)
        return st, msg
def _run_python_code(build, extra_path, entry_point):
	python_runner = ensure_lib_available(build, 'python_runner.py')

	if sys.platform.startswith("win"):
		runner = ensure_lib_available(build, 'python_runner_win.exe')
		run_shell(runner, extra_path, entry_point, command_log_level=logging.INFO, check_for_interrupt=True)
	elif sys.platform.startswith("darwin"):
		runner = ensure_lib_available(build, 'python_runner_darwin')
		run_shell(runner, extra_path, entry_point, command_log_level=logging.INFO, check_for_interrupt=True, create_process_group=True)
	else:
		python = sys.executable
		run_shell(python, python_runner, extra_path, entry_point, command_log_level=logging.INFO, check_for_interrupt=True)