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


Python utils.get_formatted_message函数代码示例

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


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

示例1: add

def add(name, connection_uri, id_file="", o=[], config=None):
    """
    Adds a new entry to sshconfig.
    """
    storm_ = get_storm_instance(config)

    try:

        # validate name
        if '@' in name:
            raise ValueError('invalid value: "@" cannot be used in name.')

        user, host, port = parse(
            connection_uri,
            user=get_default("user", storm_.defaults),
            port=get_default("port", storm_.defaults)
        )

        storm_.add_entry(name, host, user, port, id_file, o)

        print(get_formatted_message('{0} added to your ssh config. you can connect it by typing "ssh {0}".'.format(

            name
        ), 'success'))

    except ValueError as error:
        print(get_formatted_message(error, 'error'), file=sys.stderr)
开发者ID:uidzero,项目名称:storm,代码行数:27,代码来源:__main__.py

示例2: move

def move(name, entry_name, config=None):
    """
    Move an entry to the sshconfig.
    """
    storm_ = get_storm_instance(config)

    try:

        # validate name
        if '@' in name:
            raise ValueError('invalid value: "@" cannot be used in name.')

        storm_.clone_entry(name, entry_name, keep_original=False)

        print(
            get_formatted_message(
                '{0} moved in ssh config. you can '
                'connect it by typing "ssh {0}".'.format(
                    entry_name
                ),
            'success')
        )

    except ValueError as error:
        print(get_formatted_message(error, 'error'), file=sys.stderr)
开发者ID:Everaldosilva,项目名称:storm,代码行数:25,代码来源:__main__.py

示例3: list

def list(config=None):
    """
    Lists all hosts from ssh config.
    """
    storm_ = get_storm_instance(config)

    try:
        result = colored('Listing entries:', 'white', attrs=["bold", ]) + "\n\n"
        result_stack = ""
        for host in storm_.list_entries(True):

            if host.get("type") == 'entry':
                if not host.get("host") == "*":
                    result += "    {0} -> {1}@{2}:{3}".format(
                        colored(host["host"], 'green', attrs=["bold", ]),
                        host.get("options").get("user", get_default("user", storm_.defaults)),
                        host.get("options").get("hostname", "[hostname_not_specified]"),
                        host.get("options").get("port", get_default("port", storm_.defaults))
                    )

                    extra = False
                    for key, value in six.iteritems(host.get("options")):

                        if not key in ["user", "hostname", "port"]:
                            if not extra:
                                custom_options = colored('\n\t[custom options] ', 'white')
                                result += " {0}".format(custom_options)
                            extra = True

                            if isinstance(value, collections.Sequence):
                                if isinstance(value, builtins.list):
                                    value = ",".join(value)
                                    
                            result += "{0}={1} ".format(key, value)
                    if extra:
                        result = result[0:-1]

                    result += "\n\n"
                else:
                    result_stack = colored("   (*) General options: \n", "green", attrs=["bold",])
                    for key, value in six.iteritems(host.get("options")):
                        if isinstance(value, type([])):
                            result_stack += "\t  {0}: ".format(colored(key, "magenta"))
                            result_stack += ', '.join(value)
                            result_stack += "\n"
                        else:
                            result_stack += "\t  {0}: {1}\n".format(
                                colored(key, "magenta"),
                                value,
                            )
                    result_stack = result_stack[0:-1] + "\n"

        result += result_stack
        print(get_formatted_message(result, ""))
    except Exception as error:
        print(get_formatted_message(str(error), 'error'), file=sys.stderr)
开发者ID:uidzero,项目名称:storm,代码行数:56,代码来源:__main__.py

示例4: delete_all

def delete_all():
    """
    Deletes all hosts from ssh config.
    """
    storm_ = get_storm_instance(config)

    try:
        storm_.delete_all_entries()
        print(get_formatted_message('all entries deleted.', 'success'))
    except Exception as error:
        print(get_formatted_message(str(error), 'error'), file=sys.stderr)
开发者ID:LoicMahieu,项目名称:storm,代码行数:11,代码来源:__main__.py

示例5: delete

def delete(name, config=None):
    """
    Deletes a single host.
    """
    storm_ = get_storm_instance(config)

    try:
        storm_.delete_entry(name)
        print(get_formatted_message('hostname "{0}" deleted successfully.'.format(name), 'success'))
    except StormValueError as error:
        print(get_formatted_message(error, 'error'), file=sys.stderr)
开发者ID:LoicMahieu,项目名称:storm,代码行数:11,代码来源:__main__.py

示例6: backup

def backup(target_file, config=None):
    """
    Backups the main ssh configuration into target file.
    """
    storm_ = get_storm_instance(config)
    try:
        storm_.backup(target_file)
    except Exception as error:
        print(get_formatted_message(str(error), 'error'), file=sys.stderr)
开发者ID:antrepo,项目名称:storm,代码行数:9,代码来源:__main__.py

示例7: edit

def edit(name, connection_uri, id_file="", o=[], config=None):
    """
    Edits the related entry in ssh config.
    """
    storm_ = get_storm_instance(config)

    try:
        if ',' in name:
            name = " ".join(name.split(","))

        user, host, port = parse(connection_uri)

        storm_.edit_entry(name, host, user, port, id_file, o)
        print(get_formatted_message(
            '"{0}" updated successfully.'.format(
                name
            ), 'success'))
    except StormValueError as error:
        print(get_formatted_message(error, 'error'), file=sys.stderr)
开发者ID:LoicMahieu,项目名称:storm,代码行数:19,代码来源:__main__.py

示例8: clone

def clone(name, clone_name, config=None):
    """
    Clone an entry to the sshconfig.
    """
    storm_ = get_storm_instance(config)

    try:

        # validate name
        if '@' in name:
            raise ValueError('invalid value: "@" cannot be used in name.')

        storm_.clone_entry(name, clone_name)

        print(get_formatted_message('{0} added to your ssh config. you can connect it by typing "ssh {0}".'.format(
            clone_name
        ), 'success'))

    except ValueError as error:
        print(get_formatted_message(error, 'error'), file=sys.stderr)
开发者ID:uidzero,项目名称:storm,代码行数:20,代码来源:__main__.py

示例9: update

def update(name, connection_uri="", id_file="", o=[], config=None):
    """
    Enhanced version of the edit command featuring multiple edits using regular expressions to match entries
    """
    storm_ = get_storm_instance(config)
    settings = {}

    if id_file != "": 
        settings['identityfile'] = id_file

    for option in o:
        k, v = option.split("=")
        settings[k] = v

    try:
        storm_.update_entry(name, **settings)
        print(get_formatted_message(
            '"{0}" updated successfully.'.format(
                name
            ), 'success'))
    except StormValueError as error:
        print(get_formatted_message(error, 'error'), file=sys.stderr)
开发者ID:LoicMahieu,项目名称:storm,代码行数:22,代码来源:__main__.py

示例10: search

def search(search_text):
    """
    Searches entries by given search text.
    """
    storm_ = get_storm_instance(config)

    try:
        results = storm_.search_host(search_text)
        if len(results) == 0:
            print ('no results found.')

        if len(results) > 0:
            message = 'Listing results for {0}:\n'.format(search_text)
            message += "".join(results)
            print(message)
    except Exception as error:
        print(get_formatted_message(str(error), 'error'), file=sys.stderr)
开发者ID:LoicMahieu,项目名称:storm,代码行数:17,代码来源:__main__.py


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