当前位置: 首页>>代码示例>>Python>>正文


Python sh.ErrorReturnCode_1方法代码示例

本文整理汇总了Python中sh.ErrorReturnCode_1方法的典型用法代码示例。如果您正苦于以下问题:Python sh.ErrorReturnCode_1方法的具体用法?Python sh.ErrorReturnCode_1怎么用?Python sh.ErrorReturnCode_1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sh的用法示例。


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

示例1: get_cpu_mask

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def get_cpu_mask(device):
    freq_list = []
    cpu_id = 0
    cpu_mask = ''
    while True:
        try:
            freq_list.append(
                int(device.exec_command(
                           "cat /sys/devices/system/cpu/cpu%d"
                           "/cpufreq/cpuinfo_max_freq" % cpu_id)))
        except (ValueError, sh.ErrorReturnCode_1):
            break
        else:
            cpu_id += 1
    for freq in freq_list:
        cpu_mask = '1' + cpu_mask if freq == max(freq_list) else '0' + cpu_mask
    return str(hex(int(cpu_mask, 2)))[2:], cpu_mask.count('1') 
开发者ID:XiaoMi,项目名称:mobile-ai-bench,代码行数:19,代码来源:bench_engine.py

示例2: adb_push_file

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def adb_push_file(src_file, dst_dir, serialno, silent=False):
    if not os.path.isfile(src_file):
        print("Not file, skip pushing " + src_file)
        return
    src_checksum = bench_utils.file_checksum(src_file)
    dst_file = os.path.join(dst_dir, os.path.basename(src_file))
    stdout_buff = []
    try:
        sh.adb("-s", serialno, "shell", "md5sum", dst_file,
               _out=lambda line: stdout_buff.append(line))
    except sh.ErrorReturnCode_1:
        print("Push %s to %s" % (src_file, dst_dir))
        sh.adb("-s", serialno, "push", src_file, dst_dir)
    else:
        dst_checksum = stdout_buff[0].split()[0]
        if src_checksum == dst_checksum:
            if not silent:
                print("Equal checksum with %s and %s" % (src_file, dst_file))
        else:
            if not silent:
                print("Push %s to %s" % (src_file, dst_dir))
            sh.adb("-s", serialno, "push", src_file, dst_dir) 
开发者ID:XiaoMi,项目名称:mobile-ai-bench,代码行数:24,代码来源:sh_commands.py

示例3: ssh_push_file

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def ssh_push_file(src_file, dst_dir, username, address, silent=False):
    if not os.path.isfile(src_file):
        print("Not file, skip pushing " + src_file)
        return
    src_checksum = bench_utils.file_checksum(src_file)
    dst_file = os.path.join(dst_dir, os.path.basename(src_file))
    stdout_buff = []
    try:
        sh.ssh('%s@%s' % (username, address), "md5sum", dst_file,
               _out=lambda line: stdout_buff.append(line))
    except sh.ErrorReturnCode_1:
        print("Scp %s to %s" % (src_file, dst_dir))
        sh.ssh('%s@%s' % (username, address), "mkdir -p %s" % dst_dir)
        sh.scp(src_file, '%s@%s:%s' % (username, address, dst_dir))
    else:
        dst_checksum = stdout_buff[0].split()[0]
        if src_checksum == dst_checksum:
            if not silent:
                print("Equal checksum with %s and %s" % (src_file, dst_file))
        else:
            if not silent:
                print("Scp %s to %s" % (src_file, dst_dir))
            sh.scp(src_file, '%s@%s:%s' % (username, address, dst_dir)) 
开发者ID:XiaoMi,项目名称:mobile-ai-bench,代码行数:25,代码来源:sh_commands.py

示例4: pull

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def pull(self, src_path, dst_path='.'):
        if self.system == SystemType.android:
            sh_commands.adb_pull(src_path, dst_path, self.address)
        elif self.system == SystemType.arm_linux:
            if os.path.isdir(dst_path):
                exist_file = dst_path + '/' + src_path.split('/')[-1]
                if os.path.exists(exist_file):
                    sh.rm('-rf', exist_file)
            elif os.path.exists(dst_path):
                sh.rm('-f', dst_path)
            try:
                sh.scp('-r',
                       '%s@%s:%s' % (self.username,
                                     self.address,
                                     src_path),
                       dst_path)
            except sh.ErrorReturnCode_1 as e:
                six.print_('Error msg {}'.format(e), file=sys.stderr)
                return 
开发者ID:XiaoMi,项目名称:mobile-ai-bench,代码行数:21,代码来源:device.py

示例5: test_execute

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def test_execute(self, training_command):
        finished = []

        def done_callback(cmd, success, exit_code):
            finished.append(True)

        training_command._done_callback = done_callback

        if DRY_RUN:
            training_command._config_filepath = NOT_EXISTING_PATH
            running_command = training_command.execute()
            with pytest.raises(sh.ErrorReturnCode_1):
                running_command.wait()
        else:
            running_command = training_command.execute()
            running_command.wait()

        assert len(finished) == 1 and finished[0] 
开发者ID:danieljl,项目名称:keras-image-captioning,代码行数:20,代码来源:hyperparam_search_test.py

示例6: test_tmux_session

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def test_tmux_session(self):
        self.logger.info('Test list without tmux installed...')
        try:
            self.cfy.ssh(list_sessions=True)
        except sh.ErrorReturnCode_1 as ex:
            self.assertIn('tmux executable not found on manager', ex.stdout)

        self.logger.info('Installing tmux...')
        self.execute_on_manager('yum install tmux -y')

        self.logger.info('Test listing sessions when non are available..')
        output = self.cfy.ssh(list_sessions=True)
        self.assertIn('No sessions are available', output)

        self.logger.info('Test running ssh command...')
        content = 'yay'
        remote_path = '/tmp/ssh_test_output_file'
        self.cfy.ssh(command='echo {0} > {1}'.format(content, remote_path))
        self.assertEqual(content, self.read_manager_file(remote_path)) 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:21,代码来源:test_manager_misc.py

示例7: test_clone_no_fallback

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def test_clone_no_fallback(self, sh_mock):
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set('DEFAULT', 'fallback_to_master', '0')
        self.config = ConfigOptions(config)
        # We need to redefine the mock object again, to use a side effect
        # that will fail in the git checkout call. A bit convoluted, but
        # it works
        with mock.patch.object(sh.Command, '__call__') as new_mock:
            new_mock.side_effect = _aux_sh
            self.assertRaises(sh.ErrorReturnCode_1, repositories.refreshrepo,
                              'url', 'path', branch='branch')
            expected = [mock.call('url', 'path'),
                        mock.call('origin'),
                        mock.call('-f', 'branch')]
            self.assertEqual(new_mock.call_args_list, expected) 
开发者ID:softwarefactory-project,项目名称:DLRN,代码行数:18,代码来源:test_repositories.py

示例8: move_files

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def move_files(src_path, dst_path, *files):
    """
    This helper function is aimed to move files from a source path to a destination path.

    :param src_path: absolute or relative source path
    :param dst_path: absolute or relative destination path
    :param files: tuples with the following format (source_filename, destination_filename)
    """
    src_path, dst_path = __expand_folders(src_path, dst_path)
    for f in files:
        if isinstance(f, tuple):
            src, dst = f
        elif isinstance(f, string_types):
            src, dst = 2 * [f]
        else:
            continue
        src, dst = join(src_path, src), join(dst_path, dst)
        try:
            if src != dst:
                sh.mv(src, dst)
        except sh.ErrorReturnCode_1:
            pass 
开发者ID:dhondta,项目名称:rpl-attacks,代码行数:24,代码来源:helpers.py

示例9: move_folder

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def move_folder(src_path, dst_path, new_folder_name=None):
    """
    This helper function is aimed to copy a folder from a source path to a destination path,
     eventually renaming the folder to be moved. If it fails, it does it silently.

    :param src_path: absolute or relative source path
    :param dst_path: absolute or relative destination root path
    :param new_folder_name: new name for the source path's folder
    """
    src_path, dst_path = __expand_folders(src_path, dst_path)
    if new_folder_name is not None:
        dst_path = join(dst_path, new_folder_name).rstrip("/")
    try:
        if src_path != dst_path:
            sh.mv(src_path, dst_path)
    except sh.ErrorReturnCode_1:
        pass 
开发者ID:dhondta,项目名称:rpl-attacks,代码行数:19,代码来源:helpers.py

示例10: find_candidate_recipes

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def find_candidate_recipes(meta, args):
    remote_fmt_args = (args.ssh_config_host, meta)
    remote = 'ssh://{}/openbmc/{}'.format(*remote_fmt_args)
    try:
        git_clone_or_reset(meta, remote, args)
    except sh.ErrorReturnCode as e:
        log('{}'.format(e), args)
        return []

    grep_args = ['-l', '-e', '_URI', '--and', '-e', 'github.com/openbmc']
    try:
        return git.grep(*grep_args, _cwd=meta).stdout.decode('utf-8').split()
    except sh.ErrorReturnCode_1:
        pass
    except sh.ErrorReturnCode as e:
        log('{}'.format(e), args)

    return [] 
开发者ID:openbmc,项目名称:openbmc-tools,代码行数:20,代码来源:openbmc-autobump.py

示例11: get

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def get(self):
        query = unquote(self.get_argument('q', ''))
        if query == '':
            self.redirect('/')
        try:
            results = str(grep('-R', '--exclude-dir', '.git', query,
                               self.settings.repo))
        except ErrorReturnCode_1 as e:
            results = ''

        try:
            results += str(find(self.settings.repo, '-type', 'f', '-name',
                                '*' + query + '*', '-not', '(', '-path',
                                '%s/%s/*' % (self.settings.repo, '.git') ))
        except ErrorReturnCode_1 as e:
            pass

        results = results.replace(self.settings.repo, '').split('\n')[:-1]
        formatted_results = []
        for result in results:
            if 'Binary file' in result or result == '':
                continue

            # TODO this doesn't play well with colons in filenames
            stuff = result.split(':')
            filename = stuff[0]
            if path.basename(filename).startswith('.'):
                filename = path.join(path.dirname(filename),
                                     path.basename(filename)[1:])
            string = ''.join(stuff[1:])
            string = self.highlight(string, query)
            formatted_results.append({'filename': filename, 'string': string})
        self.render('search.html', query=query, results=formatted_results) 
开发者ID:charlesthomas,项目名称:magpie,代码行数:35,代码来源:search.py

示例12: pull

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def pull(self, src_path, dst_path='.'):
        if os.path.isdir(dst_path):
            exist_file = dst_path + '/' + src_path.split('/')[-1]
            if os.path.exists(exist_file):
                sh.rm('-rf', exist_file)
        elif os.path.exists(dst_path):
            sh.rm('-f', dst_path)
        try:
            sh.scp('-r',
                   '%s@%s:%s' % (self.username, self.address, src_path),
                   dst_path)
        except sh.ErrorReturnCode_1 as e:
            six.print_('Error msg {}'.format(e), file=sys.stderr)
            return 
开发者ID:XiaoMi,项目名称:mobile-ai-bench,代码行数:16,代码来源:ssh_device.py

示例13: _support_dev_dsp

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def _support_dev_dsp(self):
        support_dev_dsp = False
        try:
            output = self.exec_command(
                "ls /system/vendor/lib/rfsa/adsp/libhexagon_nn_skel.so")  # noqa
        except sh.ErrorReturnCode_1:
            print("libhexagon_nn_skel.so does not exists, QualcommAdbDevice Skip DSP.")  # noqa
        else:
            if "No such file or directory" in output:
                print("libhexagon_nn_skel.so does not exists, QualcommAdbDevice Skip DSP.")  # noqa
            else:
                support_dev_dsp = True
        return support_dev_dsp 
开发者ID:XiaoMi,项目名称:mobile-ai-bench,代码行数:15,代码来源:qualcomm_adb_device.py

示例14: _aux_sh

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def _aux_sh(*args):
    call = args[0]
    if call == '-f':
        raise sh.ErrorReturnCode_1('blabla'.encode(), ''.encode(),
                                   ''.encode())
    return 
开发者ID:softwarefactory-project,项目名称:DLRN,代码行数:8,代码来源:test_repositories.py

示例15: test_clone_no_fallback_default

# 需要导入模块: import sh [as 别名]
# 或者: from sh import ErrorReturnCode_1 [as 别名]
def test_clone_no_fallback_default(self, sh_mock):
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set('DEFAULT', 'fallback_to_master', '1')
        self.config = ConfigOptions(config)
        with mock.patch.object(sh.Command, '__call__') as new_mock:
            new_mock.side_effect = _aux_sh
            self.assertRaises(sh.ErrorReturnCode_1, repositories.refreshrepo,
                              'url', 'path', branch='rpm-master')
            expected = [mock.call('url', 'path'),
                        mock.call('origin'),
                        mock.call('-f', 'rpm-master')]
            self.assertEqual(new_mock.call_args_list, expected) 
开发者ID:softwarefactory-project,项目名称:DLRN,代码行数:15,代码来源:test_repositories.py


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