Example #1
0
def update_cmd(patch_id, commit_ref, state, delegate, archived):
    """Update a patch.

    Updates a Patch on the Patchwork instance. Some operations may
    require admin or maintainer permissions.
    """
    LOG.info('Updating patch: id=%d, commit_ref=%s, state=%s, archived=%s',
             patch_id, commit_ref, state, archived)

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

        delegate = users[0]['id']

    data = {}
    for key, value in [('commit_ref', commit_ref), ('state', state),
                       ('archived', archived), ('delegate', delegate)]:
        if value is None:
            continue

        data[key] = str(value)

    data = [('commit_ref', commit_ref), ('state', state),
            ('archived', archived), ('delegate', delegate)]

    patch = api.update('patches', patch_id, data)

    _show_patch(patch)
Example #2
0
def update_cmd(patch_ids, commit_ref, state, delegate, archived, fmt):
    """Update one or more patches.

    Updates one or more Patches on the Patchwork instance. Some operations may
    require admin or maintainer permissions.
    """
    for patch_id in patch_ids:
        LOG.debug(
            'Updating patch: id=%d, commit_ref=%s, state=%s, '
            'archived=%s', patch_id, commit_ref, state, archived)

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

            delegate = users[0]['id']

        data = []
        for key, value in [('commit_ref', commit_ref), ('state', state),
                           ('archived', archived), ('delegate', delegate)]:
            if value is None:
                continue

            data.append((key, value))

        patch = api.update('patches', patch_id, data)

        _show_patch(patch, fmt)
Example #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'))
Example #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'))
Example #5
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)
Example #6
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)
Example #7
0
def _get_bundle(bundle_id):
    """Fetch bundle by ID or name.

    Allow users to provide a string to search for bundles. This doesn't make
    sense to expose via the API since there's no uniqueness constraint on
    bundle names.
    """
    if bundle_id.isdigit():
        return api.detail('bundles', bundle_id)

    bundles = api.index('bundles', [('q', bundle_id)])
    if len(bundles) == 0:
        LOG.error('No matching bundle found: %s', bundle_id)
        sys.exit(1)
    elif len(bundles) > 1:
        LOG.error('More than one bundle found: %s', bundle_id)
        sys.exit(1)

    return bundles[0]
Example #8
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'))
Example #9
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)