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


Python moves.zip函数代码示例

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


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

示例1: test_trim_files

    def test_trim_files(self):
        source = 'file.tar.gz'
        tmp_dir = 'temp'
        files = [
            '\n'.join(['file1'] * 200),
            '\n'.join(['file2'] * 200),
            'this\nthat\nother',
            'this\nthat\nother',
            'this\nthat\nother'
        ]
        trim_opt = [
            True,
            False,
            3,
            1,
            0
        ]
        trim_100 = (['file1'] * 100)
        trim_100.append("List trimmed after 100 files.")
        expected = [
            trim_100,
            ['file2'] * 200,
            ['this', 'that', 'other'],
            ['this', 'List trimmed after 1 files.'],
            ['List trimmed after 0 files.'],
        ]

        for test_files, test_trim_opts, test_expected in zip(files, trim_opt, expected):
            with patch.dict(archive.__salt__, {'cmd.run': MagicMock(return_value=test_files)}):
                ret = archive.unrar(source, tmp_dir, trim_output=test_trim_opts)
                self.assertEqual(ret, test_expected)
开发者ID:bryson,项目名称:salt,代码行数:31,代码来源:archive_test.py

示例2: info

def info(package, conn=None):
    '''
    List info for a package
    '''
    if conn is None:
        conn = init()

    fields = (
        'package',
        'version',
        'release',
        'installed',
        'os',
        'os_family',
        'dependencies',
        'os_dependencies',
        'os_family_dependencies',
        'summary',
        'description',
    )
    data = conn.execute(
        'SELECT {0} FROM packages WHERE package=?'.format(','.join(fields)),
        (package, )
    )
    row = data.fetchone()
    if not row:
        return None

    formula_def = dict(list(zip(fields, row)))
    formula_def['name'] = formula_def['package']

    return formula_def
开发者ID:HowardMei,项目名称:saltstack,代码行数:32,代码来源:sqlite3.py

示例3: plugins

def plugins():
    '''
    Fetches the plugins added to the database server

    CLI Example::

        salt '*' drizzle.plugins
    '''

    # Initializing the required variables
    ret_val = {}
    count = 1
    drizzle_db = _connect()
    cursor = drizzle_db.cursor()

    # Fetching the plugins
    query = 'SELECT PLUGIN_NAME FROM DATA_DICTIONARY.PLUGINS WHERE IS_ACTIVE LIKE "YES"'
    cursor.execute(query)
    for iter, count in zip(list(range(cursor.rowcount)), list(range(1, cursor.rowcount+1))):
        table = cursor.fetchone()
        ret_val[count] = table[0]

    cursor.close()
    drizzle_db.close()
    return ret_val
开发者ID:beornf,项目名称:salt-contrib,代码行数:25,代码来源:drizzle.py

示例4: blkid

def blkid(device=None):
    '''
    Return block device attributes: UUID, LABEL, etc.  This function only works
    on systems where blkid is available.

    CLI Example:

    .. code-block:: bash

        salt '*' disk.blkid
        salt '*' disk.blkid /dev/sda
    '''
    args = ""
    if device:
        args = " " + device

    ret = {}
    blkid_result = __salt__['cmd.run_all']('blkid' + args, python_shell=False)

    if blkid_result['retcode'] > 0:
        return ret

    for line in blkid_result['stdout'].splitlines():
        if not line:
            continue
        comps = line.split()
        device = comps[0][:-1]
        info = {}
        device_attributes = re.split(('\"*\"'), line.partition(' ')[2])
        for key, value in zip(*[iter(device_attributes)]*2):
            key = key.strip('=').strip(' ')
            info[key] = value.strip('"')
        ret[device] = info

    return ret
开发者ID:DaveQB,项目名称:salt,代码行数:35,代码来源:disk.py

示例5: threads

def threads():
    '''
    This tests the performance of the processor's scheduler

    CLI Example:

    .. code-block:: bash

        salt '*' sysbench.threads
    '''

    # Test data
    thread_yields = [100, 200, 500, 1000]
    thread_locks = [2, 4, 8, 16]

    # Initializing the test variables
    test_command = 'sysbench --num-threads=64 --test=threads '
    test_command += '--thread-yields={0} --thread-locks={1} run '
    result = None
    ret_val = {}

    # Test begins!
    for yields, locks in zip(thread_yields, thread_locks):
        key = 'Yields: {0} Locks: {1}'.format(yields, locks)
        run_command = test_command.format(yields, locks)
        result = __salt__['cmd.run'](run_command)
        ret_val[key] = _parser(result)

    return ret_val
开发者ID:HowardMei,项目名称:saltstack,代码行数:29,代码来源:sysbench.py

示例6: tables

def tables(schema):
    '''
    Displays all the tables that are
    present in the given schema

    CLI Example::

        salt '*' drizzle.tables schema_name
    '''

    # Initializing the required variables
    ret_val = {}
    drizzle_db = _connect()
    cursor = drizzle_db.cursor()

    # Fetching tables
    try:
        cursor.execute('SHOW TABLES IN {0}'.format(schema))
    except MySQLdb.OperationalError:
        return 'Unknown Schema'

    for iter, count in zip(list(range(cursor.rowcount)), list(range(1, cursor.rowcount+1))):
        table = cursor.fetchone()
        ret_val[count] = table[0]

    cursor.close()
    drizzle_db.close()
    return ret_val
开发者ID:beornf,项目名称:salt-contrib,代码行数:28,代码来源:drizzle.py

示例7: _recursive_compare

def _recursive_compare(v1, v2):
    '''
    Return v1 == v2. Compares list, dict, recursively.
    '''
    if isinstance(v1, list):
        if v2 is None:
            v2 = []
        if len(v1) != len(v2):
            return False
        v1.sort(key=_id_or_key)
        v2.sort(key=_id_or_key)
        for x, y in zip(v1, v2):
            if not _recursive_compare(x, y):
                return False
        return True
    elif isinstance(v1, dict):
        if v2 is None:
            v2 = {}
        v1 = dict(v1)
        v2 = dict(v2)
        if sorted(v1) != sorted(v2):
            return False
        for k in v1:
            if not _recursive_compare(v1[k], v2[k]):
                return False
        return True
    else:
        return v1 == v2
开发者ID:HowardMei,项目名称:saltstack,代码行数:28,代码来源:boto_datapipeline.py

示例8: _argspec_to_schema

def _argspec_to_schema(mod, spec):
    args = spec["args"]
    defaults = spec["defaults"] or []

    args_req = args[: len(args) - len(defaults)]
    args_defaults = list(zip(args[-len(defaults) :], defaults))

    types = {"title": mod, "description": mod}

    for i in args_req:
        types[i] = S.OneOfItem(
            items=(
                S.BooleanItem(title=i, description=i, required=True),
                S.IntegerItem(title=i, description=i, required=True),
                S.NumberItem(title=i, description=i, required=True),
                S.StringItem(title=i, description=i, required=True),
                # S.ArrayItem(title=i, description=i, required=True),
                # S.DictItem(title=i, description=i, required=True),
            )
        )

    for i, j in args_defaults:
        types[i] = S.OneOfItem(
            items=(
                S.BooleanItem(title=i, description=i, default=j),
                S.IntegerItem(title=i, description=i, default=j),
                S.NumberItem(title=i, description=i, default=j),
                S.StringItem(title=i, description=i, default=j),
                # S.ArrayItem(title=i, description=i, default=j),
                # S.DictItem(title=i, description=i, default=j),
            )
        )

    return type(mod, (S.Schema,), types).serialize()
开发者ID:DaveQB,项目名称:salt,代码行数:34,代码来源:sysmod.py

示例9: get

    def get(self, obj, matches=None, mt=None, lt=None, eq=None):
        '''
        Get objects from the table.

        :param table_name:
        :param matches: Regexp.
        :param mt: More than.
        :param lt: Less than.
        :param eq: Equals.
        :return:
        '''
        objects = []
        with gzip.open(os.path.join(self.db_path, obj._TABLE), 'rb') as table:
            header = None
            for data in csv.reader(table):
                if not header:
                    header = data
                    continue
                _obj = obj()
                for t_attr, t_data in zip(header, data):
                    t_attr, t_type = t_attr.split(':')
                    setattr(_obj, t_attr, self._to_type(t_data, t_type))
                if self.__criteria(_obj, matches=matches, mt=mt, lt=lt, eq=eq):
                    objects.append(_obj)
        return objects
开发者ID:bryson,项目名称:salt,代码行数:25,代码来源:fsdb.py

示例10: blkid

def blkid(device=None):
    '''
    Return block device attributes: UUID, LABEL, etc.

    CLI Example:

    .. code-block:: bash

        salt '*' disk.blkid
        salt '*' disk.blkid /dev/sda
    '''
    args = ""
    if device:
        args = " " + device

    ret = {}
    for line in __salt__['cmd.run_stdout']('blkid' + args).split('\n'):
        comps = line.split()
        device = comps[0][:-1]
        info = {}
        device_attributes = re.split(('\"*\"'), line.partition(' ')[2])
        for key, value in zip(*[iter(device_attributes)]*2):
            key = key.strip('=').strip(' ')
            info[key] = value.strip('"')
        ret[device] = info

    return ret
开发者ID:DavideyLee,项目名称:salt,代码行数:27,代码来源:disk.py

示例11: sig2

def sig2(method, endpoint, params, provider, aws_api_version):
    '''
    Sign a query against AWS services using Signature Version 2 Signing
    Process. This is documented at:

    http://docs.aws.amazon.com/general/latest/gr/signature-version-2.html
    '''
    timenow = datetime.datetime.utcnow()
    timestamp = timenow.strftime('%Y-%m-%dT%H:%M:%SZ')

    params_with_headers = params.copy()
    params_with_headers['AWSAccessKeyId'] = provider.get('id', '')
    params_with_headers['SignatureVersion'] = '2'
    params_with_headers['SignatureMethod'] = 'HmacSHA256'
    params_with_headers['Timestamp'] = '{0}'.format(timestamp)
    params_with_headers['Version'] = aws_api_version
    keys = sorted(params_with_headers.keys())
    values = list(list(map(params_with_headers.get, keys)))
    querystring = urlencode(list(zip(keys, values)))

    canonical = '{0}\n{1}\n/\n{2}'.format(
        method.encode('utf-8'),
        endpoint.encode('utf-8'),
        querystring.encode('utf-8'),
    )

    hashed = hmac.new(provider['key'], canonical, hashlib.sha256)
    sig = binascii.b2a_base64(hashed.digest())
    params_with_headers['Signature'] = sig.strip()
    return params_with_headers
开发者ID:DavideyLee,项目名称:salt,代码行数:30,代码来源:aws.py

示例12: dict_from_line

    def dict_from_line(cls, line):
        if line.startswith('#'):
            raise cls.ParseError("Comment!")

        comps = line.split()
        if len(comps) != 7:
            raise cls.ParseError("Invalid Entry!")

        return dict(zip(cls.vfstab_keys, comps))
开发者ID:bryson,项目名称:salt,代码行数:9,代码来源:mount.py

示例13: work

 def work(self, item):
     ret = {'channel': item['channel']}
     if isinstance(item['data'], six.integer_types):
         ret['code'] = item['data']
     elif item['channel'] == '+switch-master':
         ret.update(dict(list(zip(
             ('master', 'old_host', 'old_port', 'new_host', 'new_port'), item['data'].split(' ')
         ))))
     elif item['channel'] in ('+odown', '-odown'):
         ret.update(dict(list(zip(
             ('master', 'host', 'port'), item['data'].split(' ')[1:]
         ))))
     else:
         ret = {
             'channel': item['channel'],
             'data': item['data'],
         }
     self.fire_master(ret, '{0}/{1}'.format(self.tag, item['channel']))
开发者ID:bryson,项目名称:salt,代码行数:18,代码来源:redis_sentinel.py

示例14: _iostats_dict

def _iostats_dict(header, stats):
    '''
    Transpose collected data, average it, stomp it in dict using header

    Use Decimals so we can properly calc & round, convert to float 'caus' we can't transmit Decimals over 0mq
    '''
    stats = [float((sum(stat) / len(stat)).quantize(decimal.Decimal('.01'))) for stat in zip(*stats)]
    stats = dict(zip(header, stats))
    return stats
开发者ID:HowardMei,项目名称:saltstack,代码行数:9,代码来源:disk.py

示例15: test_extracted_tar

    def test_extracted_tar(self):
        '''
        archive.extracted tar options
        '''

        source = '/tmp/file.tar.gz'
        tmp_dir = os.path.join(tempfile.gettempdir(), 'test_archive', '')
        test_tar_opts = [
            '--no-anchored foo',
            'v -p --opt',
            '-v -p',
            '--long-opt -z',
            'z -v -weird-long-opt arg',
        ]
        ret_tar_opts = [
            ['tar', 'x', '--no-anchored', 'foo', '-f'],
            ['tar', 'xv', '-p', '--opt', '-f'],
            ['tar', 'x', '-v', '-p', '-f'],
            ['tar', 'x', '--long-opt', '-z', '-f'],
            ['tar', 'xz', '-v', '-weird-long-opt', 'arg', '-f'],
        ]

        mock_true = MagicMock(return_value=True)
        mock_false = MagicMock(return_value=False)
        ret = {'stdout': ['saltines', 'cheese'], 'stderr': 'biscuits', 'retcode': '31337', 'pid': '1337'}
        mock_run = MagicMock(return_value=ret)
        mock_source_list = MagicMock(return_value=(source, None))
        state_single_mock = MagicMock(return_value={'local': {'result': True}})
        list_mock = MagicMock(return_value={
            'dirs': [],
            'files': ['saltines', 'cheese'],
            'top_level_dirs': [],
            'top_level_files': ['saltines', 'cheese'],
        })

        with patch.dict(archive.__opts__, {'test': False,
                                           'cachedir': tmp_dir}):
            with patch.dict(archive.__salt__, {'file.directory_exists': mock_false,
                                               'file.file_exists': mock_false,
                                               'state.single': state_single_mock,
                                               'file.makedirs': mock_true,
                                               'cmd.run_all': mock_run,
                                               'archive.list': list_mock,
                                               'file.source_list': mock_source_list}):
                filename = os.path.join(
                    tmp_dir,
                    'files/test/_tmp_file.tar.gz'
                )
                for test_opts, ret_opts in zip(test_tar_opts, ret_tar_opts):
                    ret = archive.extracted(tmp_dir,
                                            source,
                                            options=test_opts,
                                            enforce_toplevel=False)
                    ret_opts.append(filename)
                    mock_run.assert_called_with(ret_opts, cwd=tmp_dir, python_shell=False)
开发者ID:bryson,项目名称:salt,代码行数:55,代码来源:archive_test.py


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