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

Python utils.parse_search_values_from_opts函数代码示例

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

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



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

示例1: _parse_remove_values

def _parse_remove_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    try:
        devs = []
        if len(args) > 0:
            if new_cmd_format:
                print(Commands.remove.__doc__.strip())
                exit(EXIT_ERROR)

            for arg in args:
                devs.extend(builder.search_devs(
                    parse_search_value(arg)) or [])
        else:
            devs.extend(builder.search_devs(
                parse_search_values_from_opts(opts)))

        return devs
    except ValueError as e:
        print(e)
        exit(EXIT_ERROR)
开发者ID:BjoernT,项目名称:swift,代码行数:25,代码来源:ringbuilder.py


示例2: _parse_set_weight_values

def _parse_set_weight_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    try:
        devs = []
        if not new_cmd_format:
            if len(args) % 2 != 0:
                print(Commands.set_weight.__doc__.strip())
                exit(EXIT_ERROR)

            devs_and_weights = izip(islice(argvish, 0, len(argvish), 2),
                                    islice(argvish, 1, len(argvish), 2))
            for devstr, weightstr in devs_and_weights:
                devs.extend(builder.search_devs(
                    parse_search_value(devstr)) or [])
                weight = float(weightstr)
                _set_weight_values(devs, weight)
        else:
            if len(args) != 1:
                print(Commands.set_weight.__doc__.strip())
                exit(EXIT_ERROR)

            devs.extend(builder.search_devs(
                parse_search_values_from_opts(opts)) or [])
            weight = float(args[0])
            _set_weight_values(devs, weight)
    except ValueError as e:
        print(e)
        exit(EXIT_ERROR)
开发者ID:BjoernT,项目名称:swift,代码行数:33,代码来源:ringbuilder.py


示例3: _parse_set_info_values

def _parse_set_info_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    if not new_cmd_format:
        if len(args) % 2 != 0:
            print(Commands.search.__doc__.strip())
            exit(EXIT_ERROR)

        searches_and_changes = izip(islice(argvish, 0, len(argvish), 2),
                                    islice(argvish, 1, len(argvish), 2))

        for search_value, change_value in searches_and_changes:
            devs = builder.search_devs(parse_search_value(search_value))
            change = {}

            change_value = calculate_change_value(change_value, change,
                                                  'ip', 'port')

            if change_value.startswith('R'):
                change_value = change_value[1:]
                change_value = calculate_change_value(change_value, change,
                                                      'replication_ip',
                                                      'replication_port')
            if change_value.startswith('/'):
                i = 1
                while i < len(change_value) and change_value[i] != '_':
                    i += 1
                change['device'] = change_value[1:i]
                change_value = change_value[i:]
            if change_value.startswith('_'):
                change['meta'] = change_value[1:]
                change_value = ''
            if change_value or not change:
                raise ValueError('Invalid set info change value: %s' %
                                 repr(argvish[1]))
            _set_info_values(devs, change, opts)
    else:
        devs = builder.search_devs(parse_search_values_from_opts(opts))
        change = parse_change_values_from_opts(opts)
        _set_info_values(devs, change, opts)
开发者ID:bebule,项目名称:swift,代码行数:44,代码来源:ringbuilder.py


示例4: _parse_search_values

def _parse_search_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    try:
        search_values = {}
        if len(args) > 0:
            if new_cmd_format or len(args) != 1:
                print(Commands.search.__doc__.strip())
                exit(EXIT_ERROR)
            search_values = parse_search_value(args[0])
        else:
            search_values = parse_search_values_from_opts(opts)
        return search_values
    except ValueError as e:
        print(e)
        exit(EXIT_ERROR)
开发者ID:BjoernT,项目名称:swift,代码行数:20,代码来源:ringbuilder.py


示例5: _parse_set_info_values

def _parse_set_info_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    if not new_cmd_format:
        if len(args) % 2 != 0:
            print(Commands.search.__doc__.strip())
            exit(EXIT_ERROR)

        searches_and_changes = izip(islice(argvish, 0, len(argvish), 2),
                                    islice(argvish, 1, len(argvish), 2))

        for search_value, change_value in searches_and_changes:
            devs = builder.search_devs(parse_search_value(search_value))
            change = {}
            ip = ''
            if change_value and change_value[0].isdigit():
                i = 1
                while (i < len(change_value) and
                       change_value[i] in '0123456789.'):
                    i += 1
                ip = change_value[:i]
                change_value = change_value[i:]
            elif change_value and change_value.startswith('['):
                i = 1
                while i < len(change_value) and change_value[i] != ']':
                    i += 1
                i += 1
                ip = change_value[:i].lstrip('[').rstrip(']')
                change_value = change_value[i:]
            if ip:
                change['ip'] = validate_and_normalize_ip(ip)
            if change_value.startswith(':'):
                i = 1
                while i < len(change_value) and change_value[i].isdigit():
                    i += 1
                change['port'] = int(change_value[1:i])
                change_value = change_value[i:]
            if change_value.startswith('R'):
                change_value = change_value[1:]
                replication_ip = ''
                if change_value and change_value[0].isdigit():
                    i = 1
                    while (i < len(change_value) and
                           change_value[i] in '0123456789.'):
                        i += 1
                    replication_ip = change_value[:i]
                    change_value = change_value[i:]
                elif change_value and change_value.startswith('['):
                    i = 1
                    while i < len(change_value) and change_value[i] != ']':
                        i += 1
                    i += 1
                    replication_ip = \
                        change_value[:i].lstrip('[').rstrip(']')
                    change_value = change_value[i:]
                if replication_ip:
                    change['replication_ip'] = \
                        validate_and_normalize_ip(replication_ip)
                if change_value.startswith(':'):
                    i = 1
                    while i < len(change_value) and change_value[i].isdigit():
                        i += 1
                    change['replication_port'] = int(change_value[1:i])
                    change_value = change_value[i:]
            if change_value.startswith('/'):
                i = 1
                while i < len(change_value) and change_value[i] != '_':
                    i += 1
                change['device'] = change_value[1:i]
                change_value = change_value[i:]
            if change_value.startswith('_'):
                change['meta'] = change_value[1:]
                change_value = ''
            if change_value or not change:
                raise ValueError('Invalid set info change value: %s' %
                                 repr(argvish[1]))
            _set_info_values(devs, change)
    else:
        devs = builder.search_devs(parse_search_values_from_opts(opts))
        change = parse_change_values_from_opts(opts)
        _set_info_values(devs, change)
开发者ID:BjoernT,项目名称:swift,代码行数:85,代码来源:ringbuilder.py


示例6: test_parse_search_values_from_opts

    def test_parse_search_values_from_opts(self):
        argv = \
            ["--id", "1", "--region", "2", "--zone", "3",
             "--ip", "test.test.com",
             "--port", "6000",
             "--replication-ip", "r.test.com",
             "--replication-port", "7000",
             "--device", "sda3",
             "--meta", "some meta data",
             "--weight", "3.14159265359",
             "--change-ip", "change.test.test.com",
             "--change-port", "6001",
             "--change-replication-ip", "change.r.test.com",
             "--change-replication-port", "7001",
             "--change-device", "sdb3",
             "--change-meta", "some meta data for change"]
        expected = {
            'id': 1,
            'region': 2,
            'zone': 3,
            'ip': "test.test.com",
            'port': 6000,
            'replication_ip': "r.test.com",
            'replication_port': 7000,
            'device': "sda3",
            'meta': "some meta data",
            'weight': 3.14159265359,
        }
        new_cmd_format, opts, args = validate_args(argv)
        search_values = parse_search_values_from_opts(opts)
        self.assertEquals(search_values, expected)

        argv = \
            ["--id", "1", "--region", "2", "--zone", "3",
             "--ip", "127.0.0.1",
             "--port", "6000",
             "--replication-ip", "127.0.0.10",
             "--replication-port", "7000",
             "--device", "sda3",
             "--meta", "some meta data",
             "--weight", "3.14159265359",
             "--change-ip", "127.0.0.2",
             "--change-port", "6001",
             "--change-replication-ip", "127.0.0.20",
             "--change-replication-port", "7001",
             "--change-device", "sdb3",
             "--change-meta", "some meta data for change"]
        expected = {
            'id': 1,
            'region': 2,
            'zone': 3,
            'ip': "127.0.0.1",
            'port': 6000,
            'replication_ip': "127.0.0.10",
            'replication_port': 7000,
            'device': "sda3",
            'meta': "some meta data",
            'weight': 3.14159265359,
        }
        new_cmd_format, opts, args = validate_args(argv)
        search_values = parse_search_values_from_opts(opts)
        self.assertEquals(search_values, expected)

        argv = \
            ["--id", "1", "--region", "2", "--zone", "3",
             "--ip", "[127.0.0.1]",
             "--port", "6000",
             "--replication-ip", "[127.0.0.10]",
             "--replication-port", "7000",
             "--device", "sda3",
             "--meta", "some meta data",
             "--weight", "3.14159265359",
             "--change-ip", "[127.0.0.2]",
             "--change-port", "6001",
             "--change-replication-ip", "[127.0.0.20]",
             "--change-replication-port", "7001",
             "--change-device", "sdb3",
             "--change-meta", "some meta data for change"]
        new_cmd_format, opts, args = validate_args(argv)
        search_values = parse_search_values_from_opts(opts)
        self.assertEquals(search_values, expected)
开发者ID:bigdig,项目名称:swift,代码行数:81,代码来源:test_utils.py


示例7: _parse_set_info_values

def _parse_set_info_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    if not new_cmd_format:
        if len(args) % 2 != 0:
            print(Commands.search.__doc__.strip())
            exit(EXIT_ERROR)

        searches_and_changes = izip(islice(argvish, 0, len(argvish), 2), islice(argvish, 1, len(argvish), 2))

        for search_value, change_value in searches_and_changes:
            devs = builder.search_devs(parse_search_value(search_value))
            change = {}
            ip = ""
            if len(change_value) and change_value[0].isdigit():
                i = 1
                while i < len(change_value) and change_value[i] in "0123456789.":
                    i += 1
                ip = change_value[:i]
                change_value = change_value[i:]
            elif len(change_value) and change_value[0] == "[":
                i = 1
                while i < len(change_value) and change_value[i] != "]":
                    i += 1
                i += 1
                ip = change_value[:i].lstrip("[").rstrip("]")
                change_value = change_value[i:]
            if ip:
                change["ip"] = validate_and_normalize_ip(ip)
            if change_value.startswith(":"):
                i = 1
                while i < len(change_value) and change_value[i].isdigit():
                    i += 1
                change["port"] = int(change_value[1:i])
                change_value = change_value[i:]
            if change_value.startswith("R"):
                change_value = change_value[1:]
                replication_ip = ""
                if len(change_value) and change_value[0].isdigit():
                    i = 1
                    while i < len(change_value) and change_value[i] in "0123456789.":
                        i += 1
                    replication_ip = change_value[:i]
                    change_value = change_value[i:]
                elif len(change_value) and change_value[0] == "[":
                    i = 1
                    while i < len(change_value) and change_value[i] != "]":
                        i += 1
                    i += 1
                    replication_ip = change_value[:i].lstrip("[").rstrip("]")
                    change_value = change_value[i:]
                if replication_ip:
                    change["replication_ip"] = validate_and_normalize_ip(replication_ip)
                if change_value.startswith(":"):
                    i = 1
                    while i < len(change_value) and change_value[i].isdigit():
                        i += 1
                    change["replication_port"] = int(change_value[1:i])
                    change_value = change_value[i:]
            if change_value.startswith("/"):
                i = 1
                while i < len(change_value) and change_value[i] != "_":
                    i += 1
                change["device"] = change_value[1:i]
                change_value = change_value[i:]
            if change_value.startswith("_"):
                change["meta"] = change_value[1:]
                change_value = ""
            if change_value or not change:
                raise ValueError("Invalid set info change value: %s" % repr(argvish[1]))
            _set_info_values(devs, change)
    else:
        devs = builder.search_devs(parse_search_values_from_opts(opts))
        change = parse_change_values_from_opts(opts)
        _set_info_values(devs, change)
开发者ID:iloveyou416068,项目名称:swift-1,代码行数:79,代码来源:ringbuilder.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.tiers_for_dev函数代码示例发布时间:2022-05-27
下一篇:
Python utils.parse_search_value函数代码示例发布时间: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