本文整理汇总了Python中utils.cexec函数的典型用法代码示例。如果您正苦于以下问题:Python cexec函数的具体用法?Python cexec怎么用?Python cexec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cexec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scan_device_port
def scan_device_port(self, sync_value, uuid):
port = 0
for i in range(0, 10):
cexec([self._adb, 'forward', 'tcp:{}'.format(PORT_START + i), 'tcp:{}'.format(PORT_START + i)],
callback=None)
url = 'http://127.0.0.1:{}/checkSync?sync={}&uuid={}'.format(PORT_START + i, sync_value, uuid)
result, err, code = curl(url)
if code == 0 and result is not None:
result = int(result)
self.debug('server result is {}'.format(result))
if result == 0:
self.debug('check sync value failed, maybe you need a clean build.')
from exceptions import CheckSyncStateException
raise CheckSyncStateException('check sync value failed, maybe you need a clean build.',
'NO CAUSE')
elif result == -1:
continue
else:
port = PORT_START + i
break
for i in range(0, 10):
if (PORT_START + i) != port:
cexec([self._adb, 'forward', '--remove', 'tcp:{}'.format(PORT_START + i)], callback=None)
return port
示例2: scan_device_port
def scan_device_port(self):
port = 0
apktime_path = self._get_apktime_path()
self.debug("apktime path: " + apktime_path)
sync_value = get_sync_value(apktime_path, self._cache_dir)
self.debug('your local sync value is: {}'.format(sync_value))
uuid = get_apk_created_ticket(apktime_path)
self.debug('your local uuid value is: {}'.format(uuid))
for i in range(0, 10):
cexec([self._adb, 'forward', 'tcp:{}'.format(41128 + i), 'tcp:{}'.format(41128 + i)], callback=None)
url = 'http://127.0.0.1:{}/checkSync?sync={}&uuid={}'.format(41128 + i, sync_value, uuid)
result, err, code = curl(url)
if code == 0 and result is not None:
result = int(result)
self.debug('server result is {}'.format(result))
if result == 0:
self.debug('check sync value failed, maybe you need a clean build.')
from exceptions import CheckSyncStateException
raise CheckSyncStateException('check sync value failed, maybe you need a clean build.',
'NO CAUSE')
elif result == -1:
continue
else:
port = 41128 + i
break
for i in range(0, 10):
if (41128 + i) != port:
cexec([self._adb, 'forward', '--remove', 'tcp:{}'.format(41128 + i)], callback=None)
return port
示例3: wake_up
def wake_up(self, need_protection=False):
package = self._config['package']
if 'debug_package' in self._config:
package = self._config['debug_package']
wake_up_args = [self._adb, 'shell', 'am', 'startservice', '-n',
'{}/{}'.format(package, 'com.antfortune.freeline.FreelineService')]
if not need_protection:
wake_up_args.extend(['-e', 'wakeup', 'marker'])
self.debug('wake up Service: {}'.format(' '.join(wake_up_args)))
cexec(wake_up_args, callback=None)
示例4: connect_device
def connect_device(self):
self.debug('start to connect device...')
if not self.check_installation():
return
sync_value, uuid = self._get_check_values()
self.scan_to_get_port(sync_value, uuid)
if self._port == 0:
self.check_device_connection()
commands = [self._adb, 'uninstall', self._config['debug_package']]
cexec(commands, callback=None)
self.debug('find device port: {}'.format(self._port))
示例5: _install_apk
def _install_apk(self):
if self._adb:
if not os.path.exists(self._apk_path):
raise FreelineException('apk not found.', 'apk path: {}, not exists.'.format(self._apk_path))
install_args = [self._adb, 'install', '-r', self._apk_path]
self.debug('start to install apk to device: {}'.format(' '.join(install_args)))
output, err, code = cexec(install_args, callback=None)
if 'Failure' in output:
self.debug('install apk failed, start to retry.')
output, err, code = cexec(install_args, callback=None)
if 'Failure' in output:
raise FreelineException('install apk to device failed.', '{}\n{}'.format(output, err))
示例6: run_desugar_task
def run_desugar_task(self):
self.debug('========= desugar task ========')
javaargs = [Builder.get_java(self._config)]
arguments = ['-jar', Builder.get_desugar()]
patch_classes_cache_dir = self._finder.get_patch_classes_cache_dir()
arguments.append('--input')
arguments.append(patch_classes_cache_dir)
arguments.append('--output')
arguments.append(patch_classes_cache_dir)
# bootclasspath
arguments.append('--bootclasspath_entry')
arguments.append(os.path.join(self._config['compile_sdk_directory'], 'android.jar'))
# classpath
for path in self._classpaths:
arguments.append('--classpath_entry')
arguments.append(path)
javaargs.extend(arguments)
self.debug('java exec: ' + ' '.join(javaargs))
output, err, code = cexec(javaargs, callback=None)
if code != 0:
raise FreelineException('desugar failed.', '{}\n{}'.format(output, err))
示例7: _check_connection
def _check_connection(self):
self.debug('check device\' connection...')
commands = [self._adb, 'devices']
output, err, code = cexec(commands, callback=None)
if code == 0:
devices = output.strip().split('\n')
length = len(devices)
from exceptions import UsbConnectionException
if length < 2:
raise UsbConnectionException('No device\'s connection found',
'\tUse `adb devices` to check your device connection')
if length > 2:
raise UsbConnectionException('More than 1 device connect',
'\tOnly 1 device allowed, '
'use `adb devices` to check your devices\' connection')
for content in devices:
if content.find('offline') <> -1:
raise UsbConnectionException('Device is connected but offline',
'\tPlease replug in device')
if content.find('unauthorized') <> -1:
raise UsbConnectionException('Device is connected but unauthorized',
'\tReplug in device and accept authorization as usual')
if not (content.find('device') > -1):
raise UsbConnectionException('Device is connected but unknown status',
'\tPlease replug in device')
示例8: execute
def execute(self):
command = '{} -q checkBeforeCleanBuild'.format(get_gradle_executable(self._config))
output, err, code = cexec(command.split(' '), callback=None)
if code != 0:
from exceptions import FreelineException
raise FreelineException('freeline failed when read project info with script: {}'.format(command),
'{}\n{}'.format(output, err))
示例9: run_retrolambda
def run_retrolambda(self):
if self._is_retrolambda_enabled:
lambda_config = self._config['retrolambda'][self._name]
target_dir = self._finder.get_patch_classes_cache_dir()
jar_args = [Builder.get_java(self._config),
'-Dretrolambda.inputDir={}'.format(target_dir),
'-Dretrolambda.outputDir={}'.format(target_dir)]
if lambda_config['supportIncludeFiles']:
include_files = []
classes = []
for dirpath, dirnames, files in os.walk(target_dir):
for fn in files:
if fn.endswith('.class'):
classes.append(os.path.relpath(os.path.join(dirpath, fn), target_dir))
src_dirs = self._config['project_source_sets'][self._name]['main_src_directory']
for fpath in self._changed_files['src']:
short_path = fpath.replace('.java', '.class')
for src_dir in src_dirs:
if src_dir in short_path:
short_path = os.path.relpath(fpath, src_dir).replace('.java', '')
break
for clazz in classes:
if short_path + '.class' in clazz or short_path + '$' in clazz or 'R.class' in clazz \
or 'R$' in clazz or short_path + '_' in clazz:
include_file = os.path.join(target_dir, clazz)
if os.path.exists(include_file):
self.debug('incremental build lambda file: {}'.format(include_file))
include_files.append(include_file)
include_files_param = os.pathsep.join(include_files)
if len(include_files_param) > 3496:
include_files_path = os.path.join(self._cache_dir, self._name, 'retrolambda_inc.list')
self.__save_parms_to_file(include_files_path, include_files)
jar_args.append('-Dretrolambda.includedFile={}'.format(include_files_path))
else:
jar_args.append('-Dretrolambda.includedFiles={}'.format(include_files_param))
lambda_classpaths = [target_dir, lambda_config['rtJar']]
lambda_classpaths.extend(self._classpaths)
param = os.pathsep.join(lambda_classpaths)
if lambda_config['supportIncludeFiles'] and len(param) > 3496:
classpath_file = os.path.join(self._cache_dir, self._name, 'retrolambda_classpaths.path')
self.__save_parms_to_file(classpath_file, lambda_classpaths)
jar_args.append('-Dretrolambda.classpathFile={}'.format(classpath_file))
else:
jar_args.append('-Dretrolambda.classpath={}'.format(param))
jar_args.append('-cp')
jar_args.append(lambda_config['targetJar'])
jar_args.append(lambda_config['mainClass'])
self.debug('retrolambda exec: ' + ' '.join(jar_args))
output, err, code = cexec(jar_args, callback=None)
if code != 0:
raise FreelineException('retrolambda compile failed.', '{}\n{}'.format(output, err))
示例10: run_javac_task
def run_javac_task(self):
javacargs = [self._javac, '-encoding', 'UTF-8', '-g']
if not self._is_retrolambda_enabled:
javacargs.extend(['-target', '1.7', '-source', '1.7'])
javacargs.append('-cp')
javacargs.append(os.pathsep.join(self._classpaths))
for fpath in self._changed_files['src']:
javacargs.append(fpath)
javacargs.extend(self._extra_javac_args)
javacargs.append('-d')
javacargs.append(self._finder.get_patch_classes_cache_dir())
self.debug('javac exec: ' + ' '.join(javacargs))
output, err, code = cexec(javacargs, callback=None)
if code != 0:
raise FreelineException('incremental javac compile failed.', '{}\n{}'.format(output, err))
else:
if self._is_r_file_changed:
old_r_file = self._finder.get_dst_r_path(config=self._config)
new_r_file = android_tools.DirectoryFinder.get_r_file_path(self._finder.get_backup_dir())
shutil.copyfile(new_r_file, old_r_file)
self.debug('copy {} to {}'.format(new_r_file, old_r_file))
示例11: run_apt_only
def run_apt_only(self):
if self._is_databinding_enabled and self._should_run_databinding_apt():
apt_args = self._generate_java_compile_args(extra_javac_args_enabled=True)
self.debug('apt exec: ' + ' '.join(apt_args))
output, err, code = cexec(apt_args, callback=None)
if code != 0:
raise FreelineException('apt compile failed.', '{}\n{}'.format(output, err))
if self._apt_output_dir and os.path.exists(self._apt_output_dir):
apt_cache_path = os.path.join(self._config['build_cache_dir'], 'apt_files_stat_cache.json')
if os.path.exists(apt_cache_path):
apt_cache = load_json_cache(apt_cache_path)
for dirpath, dirnames, files in os.walk(self._apt_output_dir):
for fn in files:
fpath = os.path.join(dirpath, fn)
if apt_cache and self._name in apt_cache:
if fpath in apt_cache[self._name]:
new_md5 = get_md5(fpath)
if new_md5 != apt_cache[self._name][fpath]['md5']:
self.debug('detect new md5 value, add apt file to change list: {}'.format(fpath))
self._changed_files['src'].append(fpath)
else:
self.debug('find new apt file, add to change list: {}'.format(fpath))
self._changed_files['src'].append(fpath)
else:
self.debug('apt cache not found, add to change list: {}'.format(fpath))
self._changed_files['src'].append(fpath)
示例12: init
def init():
project_dir = os.getcwd()
symlink('freeline', project_dir, 'freeline.py')
if is_windows:
symlink('freeline', project_dir, 'freeline_core')
from gradle_tools import get_all_modules
modules = get_all_modules(project_dir)
for m in modules:
if is_main_project(m['path']):
main_module = m
break
if not main_module:
raise FreelineException('main module not found', 'set main module first')
print('find main module: ' + main_module['name'])
args = []
if is_windows:
args.append('gradlew.bat')
else:
args.append('./gradlew')
args.append(':{}:checkBeforeCleanBuild'.format(main_module['name']))
print('freeline is reading project info, please wait a moment...')
output, err, code = cexec(args, cwd=project_dir)
if code != 0:
raise FreelineException('freeline failed when read project info with script: {}'.format(args),
'{}\n{}'.format(output, err))
print('freeline init success')
示例13: check_installation
def check_installation(self):
commands = [self._adb, 'shell', 'pm', 'list', 'packages', self._config['debug_package']]
self.debug(commands)
output, err, code = cexec(commands, callback=None)
result = re.findall(self._config['debug_package'].replace('.', '\.') + '\s', output)
if len(result) == 1:
return True
return False
示例14: check_installation
def check_installation(self):
commands = [self._adb, 'shell', 'pm', 'list', 'packages', self._config['package']]
output, err, code = cexec(commands, callback=None)
result = re.findall(self._config['package'].replace('.', '\.') + '\s+\Z', output)
if len(result) != 1:
self.debug('No package named {} been installed to your device'.format(self._config['package']))
from exceptions import NoInstallationException
raise NoInstallationException(
'No package named {} been installed to your device'.format(self._config['package']),
'\tUse `adb shell pm list packages {}` to check app installation.'.format(self._config['package']))
示例15: execute
def execute(self):
command = './gradlew -q checkBeforeCleanBuild'
if is_windows_system():
command = 'gradlew.bat -q checkBeforeCleanBuild'
output, err, code = cexec(command.split(' '), callback=None)
if code != 0:
from exceptions import FreelineException
raise FreelineException('freeline failed when read project info with script: {}'.format(command),
'{}\n{}'.format(output, err))