• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python misc.check_output函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wlauto.utils.misc.check_output函数的典型用法代码示例。如果您正苦于以下问题:Python check_output函数的具体用法?Python check_output怎么用?Python check_output使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了check_output函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: create_uiauto_project

def create_uiauto_project(path, name, target='1'):
    sdk_path = get_sdk_path()
    android_path = os.path.join(sdk_path, 'tools', 'android')
    package_name = 'com.arm.wlauto.uiauto.' + name.lower()

    # ${ANDROID_HOME}/tools/android create uitest-project -n com.arm.wlauto.uiauto.linpack -t 1 -p ../test2
    command = '{} create uitest-project --name {} --target {} --path {}'.format(android_path,
                                                                                package_name,
                                                                                target,
                                                                                path)
    try:
        check_output(command, shell=True)
    except subprocess.CalledProcessError as e:
        if 'is is not valid' in e.output:
            message = 'No Android SDK target found; have you run "{} update sdk" and download a platform?'
            raise CommandError(message.format(android_path))

    build_script = os.path.join(path, 'build.sh')
    with open(build_script, 'w') as wfh:
        template = string.Template(UIAUTO_BUILD_SCRIPT)
        wfh.write(template.substitute({'package_name': package_name}))
    os.chmod(build_script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

    source_file = _f(os.path.join(path, 'src',
                                  os.sep.join(package_name.split('.')[:-1]),
                                  'UiAutomation.java'))
    with open(source_file, 'w') as wfh:
        wfh.write(render_template('UiAutomation.java', {'name': name, 'package_name': package_name}))
开发者ID:muendelezaji,项目名称:workload-automation,代码行数:28,代码来源:create.py


示例2: adb_connect

def adb_connect(device, timeout=None):
    _check_env()
    command = "adb connect " + device
    if ":" in device:
        port = device.split(':')[-1]
        logger.debug(command)

        output, _ = check_output(command, shell=True, timeout=timeout)
        logger.debug(output)
        #### due to a rare adb bug sometimes an extra :5555 is appended to the IP address
        if output.find('{}:{}'.format(port, port)) != -1:
            logger.debug('ADB BUG with extra port')
            command = "adb connect " + device.replace(':{}'.format(port), '')

    tries = 0
    output = None
    while not poll_for_file(device, "/proc/cpuinfo"):
        logger.debug("adb connect failed, retrying now...")
        tries += 1
        if tries > MAX_TRIES:
            raise DeviceError('Cannot connect to adb server on the device.')
        logger.debug(command)
        output, _ = check_output(command, shell=True, timeout=timeout)
        time.sleep(10)

    if tries and output.find('connected to') == -1:
        raise DeviceError('Could not connect to {}'.format(device))
开发者ID:bjackman,项目名称:workload-automation,代码行数:27,代码来源:android.py


示例3: adb_connect

def adb_connect(device, timeout=None):
    _check_env()
    command = "adb connect " + device
    if ":5555" in device:
        logger.debug(command)

        output, _ = check_output(command, shell=True, timeout=timeout)
        logger.debug(output)
        #### due to a rare adb bug sometimes an extra :5555 is appended to the IP address
        if output.find("5555:5555") != -1:
            logger.debug("ADB BUG with extra 5555")
            command = "adb connect " + device.replace(":5555", "")

    tries = 0
    while not poll_for_file(device, "/proc/cpuinfo"):
        logger.debug("adb connect failed, retrying now...")
        tries += 1
        if tries > MAX_TRIES:
            raise DeviceError("Cannot connect to adb server on the device.")
        logger.debug(command)
        output, _ = check_output(command, shell=True, timeout=timeout)
        time.sleep(10)

    if output.find("connected to") == -1:
        raise DeviceError("Could not connect to {}".format(device))
开发者ID:bobbyb-arm,项目名称:workload-automation,代码行数:25,代码来源:android.py


示例4: _generate_workgen_config

 def _generate_workgen_config(self, user_file, output_directory):
     output_file = os.path.join(output_directory, 'unkind.json')
     # use workgen dry run option to generate a use case
     # file with proper JSON grammar on host first
     try:
         check_output('python {} -d -o {} {}'.format(self.workgen_script,
                                                     output_file,
                                                     user_file),
                      shell=True)
     except CalledProcessError as e:
         message = 'Could not generate config using workgen, got "{}"'
         raise WorkloadError(message.format(e))
     return output_file
开发者ID:bigzz,项目名称:workload-automation,代码行数:13,代码来源:__init__.py


示例5: adb_command

def adb_command(device, command, timeout=None):
    _check_env()
    device_string = '-s {}'.format(device) if device else ''
    full_command = "adb {} {}".format(device_string, command)
    logger.debug(full_command)
    output, _ = check_output(full_command, timeout, shell=True)
    return output
开发者ID:bjackman,项目名称:workload-automation,代码行数:7,代码来源:android.py


示例6: _scp

 def _scp(self, source, dest, timeout=30):
     # NOTE: the version of scp in Ubuntu 12.04 occasionally (and bizarrely)
     # fails to connect to a device if port is explicitly specified using -P
     # option, even if it is the default port, 22. To minimize this problem,
     # only specify -P for scp if the port is *not* the default.
     port_string = '-P {}'.format(self.port) if (self.port and self.port != 22) else ''
     keyfile_string = '-i {}'.format(self.keyfile) if self.keyfile else ''
     command = '{} -r {} {} {} {}'.format(scp, keyfile_string, port_string, source, dest)
     pass_string = ''
     logger.debug(command)
     if self.password:
         command = _give_password(self.password, command)
     try:
         check_output(command, timeout=timeout, shell=True)
     except subprocess.CalledProcessError as e:
         raise subprocess.CalledProcessError(e.returncode, e.cmd.replace(pass_string, ''), e.output)
     except TimeoutError as e:
         raise TimeoutError(e.command.replace(pass_string, ''), e.output)
开发者ID:bigzz,项目名称:workload-automation,代码行数:18,代码来源:ssh.py


示例7: adb_shell

def adb_shell(device, command, timeout=None, check_exit_code=False, as_root=False):  # NOQA
    _check_env()
    if as_root:
        command = 'echo "{}" | su'.format(escape_double_quotes(command))
    device_string = "-s {}".format(device) if device else ""
    full_command = 'adb {} shell "{}"'.format(device_string, escape_double_quotes(command))
    logger.debug(full_command)
    if check_exit_code:
        actual_command = "adb {} shell '({}); echo $?'".format(device_string, escape_single_quotes(command))
        raw_output, error = check_output(actual_command, timeout, shell=True)
        if raw_output:
            try:
                output, exit_code, _ = raw_output.rsplit("\n", 2)
            except ValueError:
                exit_code, _ = raw_output.rsplit("\n", 1)
                output = ""
        else:  # raw_output is empty
            exit_code = "969696"  # just because
            output = ""

        exit_code = exit_code.strip()
        if exit_code.isdigit():
            if int(exit_code):
                message = "Got exit code {}\nfrom: {}\nSTDOUT: {}\nSTDERR: {}".format(
                    exit_code, full_command, output, error
                )
                raise DeviceError(message)
            elif am_start_error.findall(output):
                message = "Could not start activity; got the following:"
                message += "\n{}".format(am_start_error.findall(output)[0])
                raise DeviceError(message)
        else:  # not all digits
            if am_start_error.findall(output):
                message = "Could not start activity; got the following:"
                message += "\n{}".format(am_start_error.findall(output)[0])
                raise DeviceError(message)
            else:
                raise DeviceError("adb has returned early; did not get an exit code. Was kill-server invoked?")
    else:  # do not check exit code
        output, _ = check_output(full_command, timeout, shell=True)
    return output
开发者ID:bobbyb-arm,项目名称:workload-automation,代码行数:41,代码来源:android.py


示例8: create_uiauto_project

def create_uiauto_project(path, name, target='1'):
    sdk_path = get_sdk_path()
    android_path = os.path.join(sdk_path, 'tools', 'android')
    package_name = 'com.arm.wlauto.uiauto.' + name.lower()

    # ${ANDROID_HOME}/tools/android create uitest-project -n com.arm.wlauto.uiauto.linpack -t 1 -p ../test2
    command = '{} create uitest-project --name {} --target {} --path {}'.format(android_path,
                                                                                package_name,
                                                                                target,
                                                                                path)
    check_output(command, shell=True)

    build_script = os.path.join(path, 'build.sh')
    with open(build_script, 'w') as wfh:
        template = string.Template(UIAUTO_BUILD_SCRIPT)
        wfh.write(template.substitute({'package_name': package_name}))
    os.chmod(build_script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

    source_file = _f(os.path.join(path, 'src',
                                  os.sep.join(package_name.split('.')[:-1]),
                                  'UiAutomation.java'))
    with open(source_file, 'w') as wfh:
        wfh.write(render_template('UiAutomation.java', {'name': name, 'package_name': package_name}))
开发者ID:chagar01,项目名称:workload-automation,代码行数:23,代码来源:create.py


示例9: update_result

    def update_result(self, context):  # pylint: disable=r0201
        self.logger.debug("Waiting for atrace to finish dumping data")
        self.p.wait()
        context.device.pull_file(self.output_file, context.output_directory)
        cmd = "python {} --from-file={} -o {}"
        cmd = cmd.format(os.path.join(os.environ['ANDROID_HOME'],
                                      "platform-tools/systrace/systrace.py"),
                         os.path.join(context.output_directory, "atrace.txt"),
                         os.path.join(context.output_directory, "systrace.html"))
        self.logger.debug(cmd)
        _, error = check_output(cmd.split(" "), timeout=10)
        if error:
            raise InstrumentError(error)

        context.add_iteration_artifact('atrace.txt',
                                       path=os.path.join(context.output_directory,
                                                         "atace.txt"),
                                       kind='data',
                                       description='atrace dump.')
        context.add_iteration_artifact('systrace.html',
                                       path=os.path.join(context.output_directory,
                                                         "systrace.html"),
                                       kind='data',
                                       description='Systrace HTML report.')
开发者ID:bjackman,项目名称:workload-automation,代码行数:24,代码来源:__init__.py


示例10: run

 def run(self, context):
     self.logger.debug(self.command)
     self.raw_output, _ = check_output(self.command, shell=True, timeout=self.run_timeout, ignore='all')
开发者ID:JaviMerino,项目名称:workload-automation,代码行数:3,代码来源:__init__.py


示例11: fastboot_command

def fastboot_command(command, timeout=None):
    _check_env()
    full_command = "fastboot {}".format(command)
    logger.debug(full_command)
    output, _ = check_output(full_command, timeout, shell=True)
    return output
开发者ID:bjackman,项目名称:workload-automation,代码行数:6,代码来源:android.py


示例12: adb_shell

def adb_shell(device, command, timeout=None, check_exit_code=False, as_root=False):  # NOQA
    # pylint: disable=too-many-branches, too-many-locals, too-many-statements
    _check_env()
    if as_root:
        command = 'echo \'{}\' | su'.format(escape_single_quotes(command))
    device_string = '-s {}'.format(device) if device else ''
    full_command = 'adb {} shell "{}"'.format(device_string, escape_double_quotes(command))
    logger.debug(full_command)
    if check_exit_code:
        actual_command = "adb {} shell '({}); echo; echo $?'".format(device_string, escape_single_quotes(command))
        try:
            raw_output, error = check_output(actual_command, timeout, shell=True)
        except CalledProcessErrorWithStderr as e:
            raw_output = e.output
            error = e.error
            exit_code = e.returncode
            if exit_code == 1:
                logger.debug("Exit code 1 could be either the return code of the command or mean ADB failed")

        if raw_output:
            if raw_output.endswith('\r\n'):
                newline = '\r\n'
            elif raw_output.endswith('\n'):
                newline = '\n'
            else:
                raise WAError("Unknown new line separator in: {}".format(raw_output))

            try:
                output, exit_code, _ = raw_output.rsplit(newline, 2)
            except ValueError:
                exit_code, _ = raw_output.rsplit(newline, 1)
                output = ''
        else:  # raw_output is empty
            exit_code = '969696'  # just because
            output = ''

        exit_code = exit_code.strip()
        if exit_code.isdigit():
            if int(exit_code):
                message = 'Got exit code {}\nfrom: {}\nSTDOUT: {}\nSTDERR: {}'.format(exit_code, full_command,
                                                                                      output, error)
                raise DeviceError(message)
            elif am_start_error.findall(output):
                message = 'Could not start activity; got the following:'
                message += '\n{}'.format(am_start_error.findall(output)[0])
                raise DeviceError(message)
        else:  # not all digits
            if am_start_error.findall(output):
                message = 'Could not start activity; got the following:'
                message += '\n{}'.format(am_start_error.findall(output)[0])
                raise DeviceError(message)
            else:
                raise DeviceError('adb has returned early; did not get an exit code. Was kill-server invoked?')
    else:  # do not check exit code
        try:
            output, _ = check_output(full_command, timeout, shell=True)
        except CalledProcessErrorWithStderr as e:
            output = e.output
            error = e.error
            exit_code = e.returncode
            if e.returncode == 1:
                logger.debug("Got Exit code 1, could be either the return code of the command or mean ADB failed")
    return output
开发者ID:chase-qi,项目名称:workload-automation,代码行数:63,代码来源:android.py



注:本文中的wlauto.utils.misc.check_output函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python wnck.screen_get_default函数代码示例发布时间:2022-05-26
下一篇:
Python android.adb_shell函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap