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


Python context_managers.hide方法代码示例

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


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

示例1: __init__

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def __init__(self, name, cwd=None):
        """Create a tmux session.

        Args:
            name (str): name of the new session
            cwd (str): initial directory of the session

        Options used:
            -d: do not attach to the new session
            -s: specify a name for the session
        """
        self.name = name

        with settings(hide('warnings'), warn_only=True):
            result = local("tmux new -d -s {}".format(name))  # start tmux session

        if result.failed:
            raise TmuxSessionExists()

        if cwd is None:
            cwd = os.getcwd()

        # move to current directory
        self.run("cd {}".format(cwd)) 
开发者ID:kelvinguu,项目名称:lang2program,代码行数:26,代码来源:io.py

示例2: is_port_in_use

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def is_port_in_use(host):
    _LOGGER.info("Checking if port used by Prestoserver is already in use..")
    try:
        portnum = lookup_port(host)
    except Exception:
        _LOGGER.info("Cannot find port from config.properties. "
                     "Skipping check for port already being used")
        return 0
    with settings(hide('warnings', 'stdout'), warn_only=True):
        output = run('netstat -ln |grep -E "\<%s\>" |grep LISTEN' % str(portnum))
    if output:
        _LOGGER.info("Presto server port already in use. Skipping "
                     "server start...")
        error('Server failed to start on %s. Port %s already in use'
              % (env.host, str(portnum)))
    return output 
开发者ID:prestodb,项目名称:presto-admin,代码行数:18,代码来源:server.py

示例3: get_ext_ip_of_node

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def get_ext_ip_of_node(client):
    node_properties_file = os.path.join(constants.REMOTE_CONF_DIR,
                                        'node.properties')
    with settings(hide('stdout')):
        node_uuid = sudo('sed -n s/^node.id=//p ' + node_properties_file)
    external_ip_row = execute_external_ip_sql(client, node_uuid)
    external_ip = ''
    if len(external_ip_row) > 1:
        warn_more_than_one_ip = 'More than one external ip found for ' + env.host + \
                                '. There could be multiple nodes associated with the same node.id'
        _LOGGER.debug(warn_more_than_one_ip)
        warn(warn_more_than_one_ip)
        return external_ip
    for row in external_ip_row:
        if row:
            external_ip = row[0]
    if not external_ip:
        _LOGGER.debug('Cannot get external IP for ' + env.host)
        external_ip = 'Unknown'
    return external_ip 
开发者ID:prestodb,项目名称:presto-admin,代码行数:22,代码来源:server.py

示例4: collect_node_information

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def collect_node_information():
    with closing(PrestoClient(get_coordinator_role()[0], env.user)) as client:
        with settings(hide('warnings')):
            error_message = check_presto_version()
        if error_message:
            external_ip = 'Unknown'
            is_running = False
        else:
            with settings(hide('warnings', 'aborts', 'stdout')):
                try:
                    external_ip = get_ext_ip_of_node(client)
                except:
                    external_ip = 'Unknown'
                try:
                    is_running = service('status')
                except:
                    is_running = False
        return external_ip, is_running, error_message 
开发者ID:prestodb,项目名称:presto-admin,代码行数:20,代码来源:server.py

示例5: coordinator_config

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def coordinator_config():
        config_path = os.path.join(REMOTE_CONF_DIR, CONFIG_PROPERTIES)
        config_host = env.roledefs['coordinator'][0]
        try:
            data = StringIO()
            with settings(host_string='%s@%s' % (env.user, config_host)):
                with hide('stderr', 'stdout'):
                    temp_dir = run('mktemp -d /tmp/prestoadmin.XXXXXXXXXXXXXX')
                try:
                    get(config_path, data, use_sudo=True, temp_dir=temp_dir)
                finally:
                    run('rm -rf %s' % temp_dir)

            data.seek(0)
            return PrestoConfig.from_file(data, config_path, config_host)
        except:
            _LOGGER.info('Could not find Presto config.')
            return PrestoConfig(None, config_path, config_host) 
开发者ID:prestodb,项目名称:presto-admin,代码行数:20,代码来源:presto_config.py

示例6: test_should_set_all_hosts

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def test_should_set_all_hosts(self):
        """
        should set env.all_hosts to its derived host list
        """
        hosts = ['a', 'b']
        roledefs = {'r1': ['c', 'd']}
        roles = ['r1']
        exclude_hosts = ['a']

        def command():
            self.assertEqual(set(env.all_hosts), set(['b', 'c', 'd']))
        task = Fake(callable=True, expect_call=True).calls(command)
        with settings(hide('everything'), roledefs=roledefs):
            execute(
                task, hosts=hosts, roles=roles, exclude_hosts=exclude_hosts
            ) 
开发者ID:prestodb,项目名称:presto-admin,代码行数:18,代码来源:test_fabric_patches.py

示例7: test_parallel_network_error

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def test_parallel_network_error(self, error_mock):
        """
        network error should call error
        """

        network_error = NetworkError('Network message')
        fabric.state.env.warn_only = False

        @parallel
        @hosts('127.0.0.1:2200', '127.0.0.1:2201')
        def task():
            raise network_error
        with hide('everything'):
            execute(task)
        error_mock.assert_called_with('Network message',
                                      exception=network_error.wrapped,
                                      func=fabric.utils.abort) 
开发者ID:prestodb,项目名称:presto-admin,代码行数:19,代码来源:test_fabric_patches.py

示例8: test_base_exception_error

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def test_base_exception_error(self, error_mock):
        """
        base exception should call error
        """

        value_error = ValueError('error message')
        fabric.state.env.warn_only = True

        @parallel
        @hosts('127.0.0.1:2200', '127.0.0.1:2201')
        def task():
            raise value_error
        with hide('everything'):
            execute(task)
        # self.assertTrue(error_mock.is_called)
        args = error_mock.call_args
        self.assertEqual(args[0], ('error message',))
        self.assertEqual(type(args[1]['exception']), type(value_error))
        self.assertEqual(args[1]['exception'].args, value_error.args) 
开发者ID:prestodb,项目名称:presto-admin,代码行数:21,代码来源:test_fabric_patches.py

示例9: new_log

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def new_log():
    """Show only lines since the last time the log was echoed."""
    if os.path.exists("lnt.log"):
        lines = {line for line in open("lnt.log", 'r').readlines()}
    else:
        lines = set()
    with hide('warnings'):
        get('/srv/lnt/install/lnt.log', 'lnt.log', )
    new_lines = {line for line in open("lnt.log", 'r').readlines()}
    for l in new_lines - lines:
        print ' '.join(l.split()[2:]), 
开发者ID:llvm,项目名称:llvm-zorg,代码行数:13,代码来源:fabfile.py

示例10: _is_preindex_complete

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def _is_preindex_complete():
    with settings(warn_only=True), hide('warnings'):
        return sudo(
            ('{virtualenv_root}/bin/python '
            '{code_root}/manage.py preindex_everything '
            '--check').format(
                virtualenv_root=env.py3_virtualenv_root,
                code_root=env.code_root,
                user=env.user,
            ),
        ).succeeded 
开发者ID:dimagi,项目名称:commcare-cloud,代码行数:13,代码来源:db.py

示例11: presto_installed

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def presto_installed():
    with settings(hide('warnings', 'stdout'), warn_only=True):
        package_search = run('rpm -q presto')
        if not package_search.succeeded:
            package_search = run('rpm -q presto-server-rpm')
        return package_search.succeeded 
开发者ID:prestodb,项目名称:presto-admin,代码行数:8,代码来源:server.py

示例12: get_presto_version

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def get_presto_version():
    with settings(hide('warnings', 'stdout'), warn_only=True):
        version = run('rpm -q --qf \"%{VERSION}\\n\" presto')
        # currently we have two rpm names out so we need this retry
        if not version.succeeded:
            version = run('rpm -q --qf \"%{VERSION}\\n\" presto-server-rpm')
        version = version.strip()
        _LOGGER.debug('Presto rpm version: ' + version)
        return version 
开发者ID:prestodb,项目名称:presto-admin,代码行数:11,代码来源:server.py

示例13: get_platform_information

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def get_platform_information():
    with settings(hide('warnings', 'stdout'), warn_only=True):
        platform_info = run('uname -a')
        _LOGGER.debug('platform info: ' + platform_info)
        return platform_info 
开发者ID:prestodb,项目名称:presto-admin,代码行数:7,代码来源:collect.py

示例14: get_java_version

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def get_java_version():
    with settings(hide('warnings', 'stdout'), warn_only=True):
        version = run('java -version')
        _LOGGER.debug('java version: ' + version)
        return version 
开发者ID:prestodb,项目名称:presto-admin,代码行数:7,代码来源:collect.py

示例15: remove_file

# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import hide [as 别名]
def remove_file(path):
    script = ('if [ -f %(path)s ] ; '
              'then rm %(path)s ; '
              'else echo "%(could_not_remove)s \'%(name)s\'. '
              'No such file \'%(path)s\'"; fi')

    with hide('stderr', 'stdout'):
        return sudo(script %
                    {'path': path,
                     'name': os.path.splitext(os.path.basename(path))[0],
                     'could_not_remove': COULD_NOT_REMOVE}) 
开发者ID:prestodb,项目名称:presto-admin,代码行数:13,代码来源:catalog.py


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