Bugzilla – Attachment 78586 Details for
Bug 54110
Create script to identify most active bug wranglers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Improved version of qawrangler-stats.py
qawrangler-stats.py (text/x-python), 5.33 KB, created by
Marc Garcia
on 2013-04-28 23:28:07 UTC
(
hide
)
Description:
Improved version of qawrangler-stats.py
Filename:
MIME Type:
Creator:
Marc Garcia
Created:
2013-04-28 23:28:07 UTC
Size:
5.33 KB
patch
obsolete
>#!/usr/bin/env python3 ># ># This file is part of the LibreOffice project. ># ># This Source Code Form is subject to the terms of the Mozilla Public ># License, v. 2.0. If a copy of the MPL was not distributed with this ># file, You can obtain one at http://mozilla.org/MPL/2.0/. ># ># This file incorporates work covered by the following license notice: ># ># Licensed to the Apache Software Foundation (ASF) under one or more ># contributor license agreements. See the NOTICE file distributed ># with this work for additional information regarding copyright ># ownership. The ASF licenses this file to you 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 . ># ># ># qawrangler-stats.py ># ># Returns statistics of most active commiters and reporters for a given ># month. ># ># For usage information, run: ># qawrangler-stats.py -h ># > >import sys >import re >import datetime >import gzip >import argparse >import csv >from urllib.request import urlopen, URLError >from io import BytesIO >from collections import Counter, OrderedDict > >URL = 'http://lists.freedesktop.org/archives/libreoffice-bugs/{}.txt.gz' >ENTITIES = OrderedDict({ > 'commiters': re.compile(r'^(.+)\schanged:$', re.MULTILINE), > 'reporters': re.compile(r'^\s*Reporter:\s(.+)$', re.MULTILINE), >}) > >def get_parser(): > """Returns an argparse instance, setting the arguments for the script""" > parser = argparse.ArgumentParser( > description='LibreOffice contributor statistics') > parser.add_argument('-m', '--month', dest='month', type=int, > default=datetime.date.today().month, > help='month to generate statistics from (default is current month)') > parser.add_argument('-y', '--year', dest='year', type=int, > default=datetime.date.today().year, > help='year to generate statistics from (default is current year)') > parser.add_argument('-n', '--num', dest='num', type=int, default=None, > help='number of top contributors of each category (default is all)') > parser.add_argument('--csv', dest='csv', action='store_true', > help='output information in CSV format') > > return parser > >def get_fname(date): > """Returns the `Libreoffice-bugs Archives' file name for a given a @date > datetime object. Note that only year and month are relevant, day is > ignored""" > return '{}-{}'.format(date.year, date.strftime('%B')) > >def get_data(url): > """Fetches and uncompresses the `Libreoffice-bugs Archives' file given its > @url. The return of the function is the content of the gile as a string""" > try: > resp = urlopen(url) > except URLError: > sys.stderr.write('Error fetching {}'.format(url)) > sys.exit(1) > else: > with gzip.GzipFile(fileobj=BytesIO(resp.read())) as f: > return f.read().decode('us-ascii') > >def get_entity_values(data, pattern, num): > """Returns the first @num matches of a @pattern in the @data string. If > @num is None, all matches are returned""" > values = re.findall(pattern, data) > return Counter(values).most_common(num) > >def nice_print(values_dict, num_output, date): > """Prints to stdout the output of the script in a human readable way. > @values_dict is a dict containing a key for each entity (e.g. commiters, > reporters, etc), and as values, a list of tuples containing the name and > the number of occurrences. An example: > > >>> { > >>> 'commiters': [ > >>> ('Commiter 1 <commiter1@his_email.com>', 30), > >>> # 30 is the number of times he commited > >>> ('Commiter 2 <commiter2@his_email.com>', 15), > >>> ] > >>> } > > @num_output is the number of top values in each categories are requested > to be displayed (e.g. number of top commiters), and @date is a datetime > object containing the requested year and month""" > print('=== {} ==='.format(date.strftime('%B %Y'))) > print() > for name, values in values_dict.items(): > print('--- Top {} {} ---'.format(num_output or '', name)) > print('\n'.join('{0:75}{1:5d}'.format(*v) for v in values)) > print() > >def csv_print(values_dict): > """Print to stdout the output of the script in CSV format. @values_dict > has the same format as for the `nice_print' function. The CSV file has > the default format for Python's csv module (comma delimited, strings > quoted when necessary)""" > writer = csv.writer(sys.stdout) > for entity_name, values in values_dict.items(): > for val_name, val_count in values: > writer.writerow([entity_name, val_name, val_count]) > >def main(args): > """Main function of the program. > * Fetches the file for the requested month and date > * For each defined entity, gathers each match of its pattern, > and counts the number of occurrences > * Prints the retrieved information to stdout in the requested format > """ > date = datetime.date(args.year, args.month, 1) > fname = get_fname(date) > url = URL.format(fname) > data = get_data(url) > values = OrderedDict() > for name, regex in ENTITIES.items(): > values[name] = get_entity_values(data, regex, args.num) > > if args.csv: > csv_print(values) > else: > nice_print(values, args.num, date) > >if __name__ == '__main__': > parser = get_parser() > args = parser.parse_args() > main(args) >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 54110
:
66182
|
66235
|
66241
|
66242
|
66244
|
66247
|
78586
|
78598