Пример #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
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
def list_cmd(submitter, limit, page, sort, name):
    """List series.

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

    params = []

    # TODO(stephenfin): It should be possible to filter series by submitter
    # email
    for subm in submitter:
        people = api.index('people', {'q': subm})
        if len(people) == 0:
            LOG.error('No matching submitter found: %s', subm)
            sys.exit(1)
        elif len(people) > 1:
            LOG.error('More than one submitter found: %s', subm)
            sys.exit(1)

        params.append(('submitter', people[0]['id']))

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

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

    # Format and print output

    headers = ['ID', 'Date', 'Name', 'Version', 'Submitter']

    output = [[
        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'))
    ] for series_ in series]

    click.echo_via_pager(tabulate(output, headers, tablefmt='psql'))
Пример #4
0
def list_cmd(owner, limit, page, sort, name):
    """List bundles.

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

    params = []

    # TODO(stephenfin): It should be possible to filter bundles by owner email
    for own in owner:
        users = api.index('users', {'q': own})
        if len(users) == 0:
            LOG.error('No matching owner found: %s', own)
            sys.exit(1)
        elif len(users) > 1:
            LOG.error('More than one owner found: %s', own)
            sys.exit(1)

        params.append(('owner', users[0]['id']))

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

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

    # Format and print output

    headers = ['ID', 'Name', 'Owner', 'Public']

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

    click.echo_via_pager(tabulate(output, headers, tablefmt='psql'))
Пример #5
0
def list_cmd(state, submitter, delegate, archived, limit, page, sort, name):
    """List patches.

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

    params = []

    # TODO(stephenfin): It should be possible to filter patches submitter email
    for subm in submitter:
        people = api.index('people', {'q': subm})
        if len(people) == 0:
            LOG.error('No matching submitter found: %s', subm)
            sys.exit(1)
        elif len(people) > 1:
            LOG.error('More than one submitter found: %s', subm)
            sys.exit(1)

        params.append(('submitter', people[0]['id']))

    for delg in delegate:
        users = api.index('users', {'q': delg})
        if len(users) == 0:
            LOG.error('No matching delegates found: %s', delg)
            sys.exit(1)
        elif len(users) > 1:
            LOG.error('More than one delegate found: %s', delg)
            sys.exit(1)

        params.append(('delegate', users[0]['id']))

    params.extend([
        ('q', name),
        ('project', CONF.project),
        # TODO(stephenfin): Perhaps we could use string values. Refer to
        # https://github.com/carltongibson/django-filter/pull/378
        ('archived', 3 if archived else 1),
        ('page', page),
        ('per_page', limit),
        ('order', sort),
    ])

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

    # Format and print output

    headers = [
        'ID', 'Date', 'Name', 'Submitter', 'State', 'Archived', 'Delegate'
    ]

    output = [[
        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').get('username')
         if patch.get('delegate') else ''),
    ] for patch in patches]

    click.echo_via_pager(tabulate(output, headers, tablefmt='psql'))
Пример #6
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)