當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。