예제 #1
0
def list_cmd(submitters, limit, page, sort, fmt, headers, name):
    """List series.

    List series on the Patchwork instance.
    """
    LOG.debug('List series: submitters=%s, limit=%r, page=%r, sort=%r',
              ','.join(submitters), limit, page, sort)

    params = []

    for submitter in submitters:
        if submitter.isdigit():
            params.append(('submitter', submitter))
        else:
            # we support server-side filtering by email (but not name) in 1.1
            if api.version() >= (1, 1) and '@' in submitter:
                params.append(('submitter', submitter))
            else:
                params.extend(
                    api.retrieve_filter_ids('people', 'submitter', submitter))

    params.extend([
        ('q', name),
        ('page', page),
        ('per_page', limit),
        ('order', sort),
    ])

    series = api.index('series', params)

    # Format and print output

    output = []

    for series_ in series:
        item = [
            series_.get('id'),
            arrow.get(series_.get('date')).humanize(),
            utils.trim(series_.get('name') or ''),
            series_.get('version'),
            '%s (%s)' % (series_.get('submitter').get('name'),
                         series_.get('submitter').get('email'))
        ]

        output.append([])
        for idx, header in enumerate(_list_headers):
            if header not in headers:
                continue

            output[-1].append(item[idx])

    utils.echo_via_pager(output, headers, fmt=fmt)
예제 #2
0
파일: bundle.py 프로젝트: matttbe/git-pw
def list_cmd(owners, limit, page, sort, fmt, headers, name):
    """List bundles.

    List bundles on the Patchwork instance.
    """
    LOG.debug('List bundles: owners=%s, limit=%r, page=%r, sort=%r',
              ','.join(owners), limit, page, sort)

    params = []

    for owner in owners:
        # we support server-side filtering by username (but not email) in 1.1
        if (api.version() >= (1, 1) and '@' not in owner) or owner.isdigit():
            params.append(('owner', owner))
        else:
            params.extend(api.retrieve_filter_ids('users', 'owner', owner))

    params.extend([
        ('q', name),
        ('page', page),
        ('per_page', limit),
        ('order', sort),
    ])

    bundles = api.index('bundles', params)

    # Format and print output

    output = []

    for bundle in bundles:
        item = [
            bundle.get('id'),
            utils.trim(bundle.get('name') or ''),
            bundle.get('owner').get('username'),
            'yes' if bundle.get('public') else 'no',
        ]

        output.append([])
        for idx, header in enumerate(_list_headers):
            if header not in headers:
                continue

            output[-1].append(item[idx])

    utils.echo_via_pager(output, headers, fmt=fmt)
예제 #3
0
파일: test_api.py 프로젝트: matttbe/git-pw
def test_version(mock_server):
    mock_server.return_value = 'https://example.com/api/1.1'

    assert api.version() == (1, 1)
예제 #4
0
def list_cmd(state, submitter, delegate, archived, limit, page, sort, fmt,
             headers, name):
    """List patches.

    List patches on the Patchwork instance.
    """
    LOG.debug(
        'List patches: states=%s, submitters=%s, delegates=%s, '
        'archived=%r', ','.join(state), ','.join(submitter),
        ','.join(delegate), archived)

    params = []

    for state in state:
        params.append(('state', state))

    for subm in submitter:
        # we support server-side filtering by email (but not name) in 1.1
        if (api.version() >= (1, 1) and '@' in subm) or subm.isdigit():
            params.append(('submitter', subm))
        else:
            params.extend(api.retrieve_filter_ids('people', 'submitter', subm))

    for delg in delegate:
        # we support server-side filtering by username (but not email) in 1.1
        if (api.version() >= (1, 1) and '@' not in delg) or delg.isdigit():
            params.append(('delegate', delg))
        else:
            params.extend(api.retrieve_filter_ids('users', 'delegate', delg))

    params.extend([
        ('q', name),
        ('archived', 'true' if archived else 'false'),
        ('page', page),
        ('per_page', limit),
        ('order', sort),
    ])

    patches = api.index('patches', params)

    # Format and print output

    output = []

    for patch in patches:
        item = [
            patch.get('id'),
            arrow.get(patch.get('date')).humanize(),
            utils.trim(patch.get('name')),
            '%s (%s)' % (patch.get('submitter').get('name'),
                         patch.get('submitter').get('email')),
            patch.get('state'),
            'yes' if patch.get('archived') else 'no',
            (patch.get('delegate') or {}).get('username', ''),
        ]

        output.append([])
        for idx, header in enumerate(_list_headers):
            if header not in headers:
                continue

            output[-1].append(item[idx])

    utils.echo_via_pager(output, headers, fmt=fmt)
예제 #5
0
파일: test_api.py 프로젝트: matttbe/git-pw
def test_version_missing(mock_server):
    mock_server.return_value = 'https://example.com/api'

    assert api.version() == (1, 0)