Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

products and components commands #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 46 additions & 6 deletions bugz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,28 @@
"""

import getpass
import json
import os
import re
import subprocess
import sys
import textwrap

import xmlrpc.client

from bugz.cli_argparser import make_arg_parser
from bugz.configfile import load_config
from bugz.exceptions import BugzError
from bugz.log import log_error, log_info
from bugz.settings import Settings
from bugz.utils import block_edit, get_content_type

try:
import readline
except ImportError:
pass


from bugz.cli_argparser import make_arg_parser
from bugz.configfile import load_config
from bugz.settings import Settings
from bugz.exceptions import BugzError
from bugz.log import log_error, log_info
from bugz.utils import block_edit, get_content_type


def list_bugs(buglist, settings):
Expand All @@ -61,6 +64,14 @@ def list_bugs(buglist, settings):
log_info("%i bug(s) found." % len(buglist))


def json_records(buglist):
for bug in buglist:
for k, v in list(bug.items()):
if isinstance(v, xmlrpc.client.DateTime):
bug[k] = str(v)
print(json.dumps(bug))


def prompt_for_bug(settings):
""" Prompt for the information for a bug
"""
Expand Down Expand Up @@ -631,6 +642,35 @@ def post(settings):
log_info('Bug %d submitted' % result['id'])


def products(settings):
product_objs = fetch_products(settings)
fmt = settings.format
if fmt is None:
fmt = '{product[name]}'
if settings.json:
json_records(product_objs)
else:
for product in product_objs:
print(fmt.format(product=product)[:settings.columns])

def components(settings):
product_objs = fetch_products(settings)
fmt = settings.format
if fmt is None:
fmt = '{product[name]:>20} {component[name]:>20} {component[description]:>20}'
if settings.json:
json_records(product_objs)
else:
for product in product_objs:
for component in product['components']:
print(fmt.format(product=product, component=component)[:settings.columns])


def fetch_products(settings):
product_ids = settings.call_bz(settings.bz.Product.get_accessible_products, dict())['ids']
return settings.call_bz(settings.bz.Product.get, dict(ids=product_ids))['products']


def search(settings):
"""Performs a search on the bugzilla database with
the keywords given on the title (or the body if specified).
Expand Down
28 changes: 28 additions & 0 deletions bugz/cli_argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,34 @@ def make_arg_parser():
help='default answer to confirmation question')
post_parser.set_defaults(func=bugz.cli.post)

products_parser = subparsers.add_parser('products',
argument_default=argparse.SUPPRESS, help='list available products')
products_parser.set_defaults(func=bugz.cli.products)
products_parser.add_argument(
'--json',
action='store_true',
help='format results as newline separated json records',
default=False)
products_parser.add_argument(
'--format',
type=str,
help='custom format. Format: {product[field]} (see --json)',
default=None)

components_parser = subparsers.add_parser('components',
argument_default=argparse.SUPPRESS, help='list available components')
components_parser.set_defaults(func=bugz.cli.components)
components_parser.add_argument(
'--json',
action='store_true',
help='format results as newline separated json records',
default=False)
components_parser.add_argument(
'--format',
type=str,
help='custom format. Format: {product[field]} (see --json)',
default=None)

search_parser = subparsers.add_parser('search',
argument_default=argparse.SUPPRESS,
help='search for bugs in bugzilla')
Expand Down