start who-helped command line tool
cliff gives us multiple output formatters for the commands Change-Id: I1fce9edb49d6287cdafedd8851289f9ecc212fcd Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
ba50297e84
commit
48ca9c1ffd
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cliff import columns
|
||||
from cliff import lister
|
||||
|
||||
from goal_tools import gerrit
|
||||
from goal_tools import utils
|
||||
|
||||
|
||||
class DateColumn(columns.FormattableColumn):
|
||||
|
||||
def human_readable(self):
|
||||
return str(self._value)
|
||||
|
||||
def machine_readable(self):
|
||||
return str(self._value)
|
||||
|
||||
|
||||
class ListContributors(lister.Lister):
|
||||
"List the contributors to a set of reviews."
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super().get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'review_list',
|
||||
nargs='+',
|
||||
help='name(s) of files containing reviews to include in report',
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
columns = (
|
||||
'Review ID', 'Review URL', 'Role', 'Name', 'Email', 'Date',
|
||||
)
|
||||
|
||||
def make_rows():
|
||||
review_ids = utils.unique(
|
||||
gerrit.parse_review_lists(parsed_args.review_list)
|
||||
)
|
||||
for review_id in review_ids:
|
||||
review = gerrit.fetch_review(review_id, self.app.cache)
|
||||
for participant in review.participants:
|
||||
yield (
|
||||
review_id,
|
||||
review.url,
|
||||
participant.role,
|
||||
participant.name,
|
||||
participant.email,
|
||||
DateColumn(participant.date),
|
||||
)
|
||||
|
||||
return (columns, make_rows())
|
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from cliff import app
|
||||
from cliff import commandmanager
|
||||
import pbr.version
|
||||
|
||||
from goal_tools import caching
|
||||
|
||||
|
||||
class WhoHelped(app.App):
|
||||
|
||||
def __init__(self):
|
||||
version_info = pbr.version.VersionInfo('goal-tools')
|
||||
super().__init__(
|
||||
version=version_info.version_string(),
|
||||
description='contributor stats query tool',
|
||||
command_manager=commandmanager.CommandManager('who_helped'),
|
||||
deferred_help=False,
|
||||
)
|
||||
|
||||
def build_option_parser(self, description, version,
|
||||
argparse_kwargs=None):
|
||||
parser = super().build_option_parser(description, version,
|
||||
argparse_kwargs)
|
||||
parser.add_argument(
|
||||
'--cache-file',
|
||||
default='./who_helped.db',
|
||||
help=('cache file for data fetched from APIs '
|
||||
'(defaults to %(default)s)'),
|
||||
)
|
||||
return parser
|
||||
|
||||
def initialize_app(self, argv):
|
||||
# Quiet the urllib3 module output coming out of requests.
|
||||
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
||||
|
||||
# Open the cache file.
|
||||
if self.options.cache_file:
|
||||
self.cache = caching.Cache(self.options.cache_file)
|
||||
else:
|
||||
# Use a dictionary for a memory cache.
|
||||
self.cache = {}
|
||||
|
||||
|
||||
def main(argv=sys.argv[1:]):
|
||||
return WhoHelped().run(argv)
|
|
@ -4,3 +4,4 @@ appdirs>=1.4.3
|
|||
beautifulsoup4>=4.6.0
|
||||
requests
|
||||
pyyaml
|
||||
cliff
|
||||
|
|
Loading…
Reference in New Issue