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

Python shell.run_command函数代码示例

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

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



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

示例1: test_process_wrapper_exits_in_reasonable_timeframe

    def test_process_wrapper_exits_in_reasonable_timeframe(self):
        # 1. Verify wrapper script path is correct and file exists
        self.assertTrue(os.path.isfile(WRAPPER_SCRIPT_PATH))

        # 2. First run it without time to verify path is valid
        command_string = 'python %s --file-path=foo.py' % (WRAPPER_SCRIPT_PATH)
        _, _, stderr = run_command(command_string, shell=True)
        self.assertTrue('usage: python_action_wrapper.py' in stderr)

        expected_msg_1 = 'python_action_wrapper.py: error: argument --pack is required'
        expected_msg_2 = ('python_action_wrapper.py: error: the following arguments are '
                          'required: --pack')

        self.assertTrue(expected_msg_1 in stderr or expected_msg_2 in stderr)

        # 3. Now time it
        command_string = '%s -f "%%e" python %s' % (TIME_BINARY_PATH, WRAPPER_SCRIPT_PATH)

        # Do multiple runs and average it
        run_times = []

        count = 8
        for i in range(0, count):
            _, _, stderr = run_command(command_string, shell=True)
            stderr = stderr.strip().split('\n')[-1]
            run_time_seconds = float(stderr)
            run_times.append(run_time_seconds)

        avg_run_time_seconds = (sum(run_times) / count)
        assertion_msg = ASSERTION_ERROR_MESSAGE % (WRAPPER_PROCESS_RUN_TIME_UPPER_LIMIT,
                                                   avg_run_time_seconds)
        self.assertTrue(avg_run_time_seconds <= WRAPPER_PROCESS_RUN_TIME_UPPER_LIMIT, assertion_msg)
开发者ID:StackStorm,项目名称:st2,代码行数:32,代码来源:test_python_action_process_wrapper.py


示例2: test_register_from_pack_action_metadata_fails_validation

    def test_register_from_pack_action_metadata_fails_validation(self):
        # No fail on failure flag, should succeed
        pack_dir = os.path.join(get_fixtures_packs_base_path(), 'dummy_pack_4')
        runner_dirs = os.path.join(get_fixtures_packs_base_path(), 'runners')

        opts = [
            '--register-pack=%s' % (pack_dir),
            '--register-no-fail-on-failure',
            '--register-runner-dir=%s' % (runner_dirs),
        ]

        cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue('Registered 0 actions.' in stderr)
        self.assertEqual(exit_code, 0)

        # Fail on failure, should fail
        pack_dir = os.path.join(get_fixtures_packs_base_path(), 'dummy_pack_4')
        opts = [
            '--register-pack=%s' % (pack_dir),
            '--register-fail-on-failure',
            '--register-runner-dir=%s' % (runner_dirs),
        ]
        cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue('object has no attribute \'get\'' in stderr)
        self.assertEqual(exit_code, 1)
开发者ID:StackStorm,项目名称:st2,代码行数:27,代码来源:test_register_content_script.py


示例3: test_register_from_pack_fail_on_failure_pack_dir_doesnt_exist

    def test_register_from_pack_fail_on_failure_pack_dir_doesnt_exist(self):
        # No fail on failure flag, should succeed
        pack_dir = "doesntexistblah"
        cmd = BASE_CMD_ARGS + ["--register-pack=%s" % (pack_dir)]
        exit_code, _, _ = run_command(cmd=cmd)
        self.assertEqual(exit_code, 0)

        # Fail on failure, should fail
        cmd = BASE_CMD_ARGS + ["--register-pack=%s" % (pack_dir), "--register-fail-on-failure"]
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue('Directory "doesntexistblah" doesn\'t exist' in stderr)
        self.assertEqual(exit_code, 1)
开发者ID:azamsheriff,项目名称:st2,代码行数:12,代码来源:test_register_content_script.py


示例4: test_register_from_pack_action_metadata_fails_validation

    def test_register_from_pack_action_metadata_fails_validation(self):
        # No fail on failure flag, should succeed
        pack_dir = os.path.join(get_fixtures_base_path(), "dummy_pack_4")
        cmd = BASE_CMD_ARGS + ["--register-pack=%s" % (pack_dir)]
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue("Registered 0 actions." in stderr)
        self.assertEqual(exit_code, 0)

        # Fail on failure, should fail
        pack_dir = os.path.join(get_fixtures_base_path(), "dummy_pack_4")
        cmd = BASE_CMD_ARGS + ["--register-pack=%s" % (pack_dir), "--register-fail-on-failure"]
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue("object has no attribute 'get'" in stderr)
        self.assertEqual(exit_code, 1)
开发者ID:azamsheriff,项目名称:st2,代码行数:14,代码来源:test_register_content_script.py


示例5: run

    def run(self, hostname, port, bean_name, command, arguments=None,
            username=None, password=None):
        args = self._get_args(hostname=hostname, port=port,
                              bean_name=bean_name, command=command,
                              arguments=arguments, username=username,
                              password=password)

        command = ' '.join(args)
        self.logger.debug('Running command: "%s"' % (command))
        exit_code, stdout, stderr = run_command(cmd=args)

        if exit_code != 0:
            msg = 'Failed to invoke command: %s' % (stderr)
            raise Exception(msg)

        if re.match('.*Operation .*? not found.*', stderr):
            msg = 'Failed to invoke command: %s' % (stderr)
            raise Exception(msg)

        if 'Passed param count does not match signature count' in stderr:
            msg = 'Failed to invoke command: %s' % (stderr)
            raise Exception(msg)

        self.logger.debug('Command successfully finished. Output: %s' % (stdout))
        return True
开发者ID:AlexeyDeyneko,项目名称:st2contrib,代码行数:25,代码来源:invoke_method.py


示例6: test_register_from_pack_success

    def test_register_from_pack_success(self):
        pack_dir = os.path.join(get_fixtures_base_path(), 'dummy_pack_1')

        cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + ['--register-pack=%s' % (pack_dir)]
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue('Registered 1 actions.' in stderr)
        self.assertEqual(exit_code, 0)
开发者ID:MohammadHabbab,项目名称:st2,代码行数:7,代码来源:test_register_content_script.py


示例7: test_register_setup_virtualenvs

    def test_register_setup_virtualenvs(self):
        # Single pack
        pack_dir = os.path.join(get_fixtures_base_path(), 'dummy_pack_1')

        cmd = BASE_CMD_ARGS + ['--register-pack=%s' % (pack_dir), '--register-setup-virtualenvs']
        exit_code, stdout, stderr = run_command(cmd=cmd)

        self.assertTrue('Setting up virtualenv for pack "dummy_pack_1"' in stderr)
        self.assertTrue('Setup virtualenv for 1 pack(s)' in stderr)
        self.assertEqual(exit_code, 0)

        # All packs
        cmd = BASE_CMD_ARGS + ['--register-setup-virtualenvs']
        exit_code, stdout, stderr = run_command(cmd=cmd)
        self.assertTrue('Setup virtualenv for 4 pack(s)' in stderr)
        self.assertEqual(exit_code, 0)
开发者ID:MohammadHabbab,项目名称:st2,代码行数:16,代码来源:test_register_content_script.py


示例8: create_virtualenv

def create_virtualenv(virtualenv_path, logger=None):
    logger = logger or LOG

    python_binary = cfg.CONF.actionrunner.python_binary
    virtualenv_binary = cfg.CONF.actionrunner.virtualenv_binary
    virtualenv_opts = cfg.CONF.actionrunner.virtualenv_opts

    if not os.path.isfile(python_binary):
        raise Exception('Python binary "%s" doesn\'t exist' % (python_binary))

    if not os.path.isfile(virtualenv_binary):
        raise Exception('Virtualenv binary "%s" doesn\'t exist.' % (virtualenv_binary))

    logger.debug('Creating virtualenv in "%s" using Python binary "%s"' %
                 (virtualenv_path, python_binary))

    cmd = [virtualenv_binary, '-p', python_binary]
    cmd.extend(virtualenv_opts)
    cmd.extend([virtualenv_path])
    logger.debug('Running command "%s" to create virtualenv.', ' '.join(cmd))

    try:
        exit_code, _, stderr = run_command(cmd=cmd)
    except OSError as e:
        raise Exception('Error executing command %s. %s.' % (' '.join(cmd),
                                                             e.message))

    if exit_code != 0:
        raise Exception('Failed to create virtualenv in "%s": %s' %
                        (virtualenv_path, stderr))

    return True
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:32,代码来源:virtualenvs.py


示例9: test_register_from_pack_success

    def test_register_from_pack_success(self):
        pack_dir = os.path.join(get_fixtures_base_path(), "dummy_pack_1")

        cmd = BASE_CMD_ARGS + ["--register-pack=%s" % (pack_dir)]
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue("Registered 1 actions." in stderr)
        self.assertEqual(exit_code, 0)
开发者ID:azamsheriff,项目名称:st2,代码行数:7,代码来源:test_register_content_script.py


示例10: get_deb_package_list

def get_deb_package_list(name_startswith):
    cmd = 'dpkg -l | grep %s' % (quote_unix(name_startswith))
    exit_code, stdout, _ = run_command(cmd=cmd, shell=True)

    lines = stdout.split('\n')

    packages = []
    for line in lines:
        line = line.strip()

        if not line:
            continue

        split = re.split(r'\s+', line)
        name = split[1]
        version = split[2]

        if not name.startswith(name_startswith):
            continue

        item = {
            'name': name,
            'version': version
        }
        packages.append(item)

    return packages
开发者ID:nzlosh,项目名称:st2,代码行数:27,代码来源:system_info.py


示例11: install_requirement

def install_requirement(virtualenv_path, requirement, proxy_config=None, logger=None):
    """
    Install a single requirement.

    :param requirement: Requirement specifier.
    """
    logger = logger or LOG
    pip_path = os.path.join(virtualenv_path, 'bin/pip')
    cmd = [pip_path]

    if proxy_config:
        cert = proxy_config.get('proxy_ca_bundle_path', None)
        https_proxy = proxy_config.get('https_proxy', None)
        http_proxy = proxy_config.get('http_proxy', None)

        if http_proxy:
            cmd.extend(['--proxy', http_proxy])

        if https_proxy:
            cmd.extend(['--proxy', https_proxy])

        if cert:
            cmd.extend(['--cert', cert])

    cmd.extend(['install', requirement])
    env = get_env_for_subprocess_command()
    logger.debug('Installing requirement %s with command %s.',
                 requirement, ' '.join(cmd))
    exit_code, stdout, stderr = run_command(cmd=cmd, env=env)

    if exit_code != 0:
        raise Exception('Failed to install requirement "%s": %s' %
                        (requirement, stdout))

    return True
开发者ID:nzlosh,项目名称:st2,代码行数:35,代码来源:virtualenvs.py


示例12: get_rpm_package_list

def get_rpm_package_list(name_startswith):
    cmd = 'rpm -qa | grep %s' % (quote_unix(name_startswith))
    exit_code, stdout, _ = run_command(cmd=cmd, shell=True)

    lines = stdout.split('\n')

    packages = []
    for line in lines:
        line = line.strip()

        if not line:
            continue

        split = line.rsplit('.', 1)
        split = split[0].split('-', 1)
        name = split[0]
        version = split[1]

        if not name.startswith(name_startswith):
            continue

        item = {
            'name': name,
            'version': version
        }
        packages.append(item)

    return packages
开发者ID:nzlosh,项目名称:st2,代码行数:28,代码来源:system_info.py


示例13: test_register_all_and_register_setup_virtualenvs

 def test_register_all_and_register_setup_virtualenvs(self):
     # Verify that --register-all works in combinations with --register-setuo-virtualenvs
     cmd = BASE_CMD_ARGS + ['--register-all', '--register-setup-virtualenvs']
     exit_code, stdout, stderr = run_command(cmd=cmd)
     self.assertTrue('Registering actions' in stderr)
     self.assertTrue('Registering rules' in stderr)
     self.assertTrue('Setup virtualenv for 5 pack(s)' in stderr)
     self.assertEqual(exit_code, 0)
开发者ID:E-LLP,项目名称:st2,代码行数:8,代码来源:test_register_content_script.py


示例14: test_register_from_packs_doesnt_throw_on_missing_pack_resource_folder

    def test_register_from_packs_doesnt_throw_on_missing_pack_resource_folder(self):
        # dummy_pack_4 only has actions folder, make sure it doesn't throw when
        # sensors and other resource folders are missing

        # Note: We want to use a different config which sets fixtures/packs_1/
        # dir as packs_base_paths
        cmd = [SCRIPT_PATH, '--config-file=conf/st2.tests1.conf', '-v', '--register-sensors']
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue('Registered 0 sensors.' in stderr)
        self.assertEqual(exit_code, 0)

        cmd = [SCRIPT_PATH, '--config-file=conf/st2.tests1.conf', '-v', '--register-all']
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue('Registered 0 actions.' in stderr)
        self.assertTrue('Registered 0 sensors.' in stderr)
        self.assertTrue('Registered 0 rules.' in stderr)
        self.assertEqual(exit_code, 0)
开发者ID:MohammadHabbab,项目名称:st2,代码行数:17,代码来源:test_register_content_script.py


示例15: test_process_wrapper_exits_in_reasonable_timeframe

    def test_process_wrapper_exits_in_reasonable_timeframe(self):
        _, _, stderr = run_command('%s -f "%%e" python %s --is-subprocess' %
                                   (TIME_BINARY_PATH, WRAPPER_SCRIPT_PATH), shell=True)

        stderr = stderr.strip().split('\n')[-1]

        run_time_seconds = float(stderr)
        assertion_msg = ASSERTION_ERROR_MESSAGE % (WRAPPER_PROCESS_RUN_TIME_UPPER_LIMIT,
                        run_time_seconds)
        self.assertTrue(run_time_seconds <= WRAPPER_PROCESS_RUN_TIME_UPPER_LIMIT, assertion_msg)
开发者ID:Pulsant,项目名称:st2,代码行数:10,代码来源:test_python_action_process_wrapper.py


示例16: get_package_list

def get_package_list(name_startswith):
    """
    Retrieve system packages which name matches the provided startswith filter.

    Note: This function only supports Debian and RedHat based systems.

    :param name_startswith: Package name startswith filter string.
    :type name_startswith: ``str``

    :rtype: ``list`` of ``dict``
    """
    dpkg_exit_code, _, _ = run_command(cmd='dpkg', shell=True)
    rpm_exit_code, _, _ = run_command(cmd='rpm', shell=True)

    if dpkg_exit_code != 127:
        result = get_deb_package_list(name_startswith=name_startswith)
    elif rpm_exit_code != 127:
        result = get_rpm_package_list(name_startswith=name_startswith)
    else:
        raise Exception('Unsupported platform (dpkg or rpm binary not available)')

    return result
开发者ID:nzlosh,项目名称:st2,代码行数:22,代码来源:system_info.py


示例17: _install_requirement

    def _install_requirement(self, virtualenv_path, requirement):
        """
        Install a single requirement.
        """
        pip_path = os.path.join(virtualenv_path, "bin/pip")
        cmd = [pip_path, "install", requirement]
        env = self._get_env_for_subprocess_command()
        exit_code, stdout, stderr = run_command(cmd=cmd, env=env)

        if exit_code != 0:
            raise Exception('Failed to install requirement "%s": %s' % (requirement, stdout))

        return True
开发者ID:enykeev,项目名称:st2,代码行数:13,代码来源:setup_virtualenv.py


示例18: test_stdin_params_timeout_no_stdin_data_provided

    def test_stdin_params_timeout_no_stdin_data_provided(self):
        config = {}
        file_path = os.path.join(BASE_DIR, '../../../../examples/actions/noop.py')

        command_string = ('python %s --pack=dummy --file-path=%s --config=\'%s\' '
                          '--stdin-parameters' %
                         (WRAPPER_SCRIPT_PATH, file_path, config))
        exit_code, stdout, stderr = run_command(command_string, shell=True)

        expected_msg = ('ValueError: No input received and timed out while waiting for parameters '
                        'from stdin')
        self.assertEqual(exit_code, 1)
        self.assertTrue(expected_msg in stderr)
开发者ID:StackStorm,项目名称:st2,代码行数:13,代码来源:test_python_action_process_wrapper.py


示例19: _install_requirements

    def _install_requirements(self, virtualenv_path, requirements_file_path):
        """
        Install requirements from a file.
        """
        pip_path = os.path.join(virtualenv_path, 'bin/pip')
        cmd = [pip_path, 'install', '-U', '-r', requirements_file_path]
        env = self._get_env_for_subprocess_command()
        exit_code, stdout, stderr = run_command(cmd=cmd, env=env)

        if exit_code != 0:
            raise Exception('Failed to install requirements from "%s": %s' %
                            (requirements_file_path, stdout))

        return True
开发者ID:SamMarkowitz,项目名称:st2,代码行数:14,代码来源:setup_virtualenv.py


示例20: test_stdin_params_invalid_format_friendly_error

    def test_stdin_params_invalid_format_friendly_error(self):
        config = {}

        file_path = os.path.join(BASE_DIR, '../../../contrib/examples/actions/noop.py')
        # Not a valid JSON string
        command_string = ('echo "invalid" | python %s --pack=dummy --file-path=%s --config=\'%s\' '
                          '--stdin-parameters' %
                         (WRAPPER_SCRIPT_PATH, file_path, config))
        exit_code, stdout, stderr = run_command(command_string, shell=True)

        expected_msg = ('ValueError: Failed to parse parameters from stdin. Expected a JSON '
                        'object with "parameters" attribute:')
        self.assertEqual(exit_code, 1)
        self.assertTrue(expected_msg in stderr)
开发者ID:StackStorm,项目名称:st2,代码行数:14,代码来源:test_python_action_process_wrapper.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python action.validate_action函数代码示例发布时间:2022-05-27
下一篇:
Python shell.quote_unix函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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