[Checkins] SVN: zope.bugchecker/trunk/src/zope/bugchecker/bugchecker.py Add options to set day count, states, verbosity, and a project group.
Tres Seaver
tseaver at palladion.com
Wed Apr 14 13:48:53 EDT 2010
Log message for revision 110908:
Add options to set day count, states, verbosity, and a project group.
Use the project_group to determine a list of project names if none are
supplied.
Changed:
U zope.bugchecker/trunk/src/zope/bugchecker/bugchecker.py
-=-
Modified: zope.bugchecker/trunk/src/zope/bugchecker/bugchecker.py
===================================================================
--- zope.bugchecker/trunk/src/zope/bugchecker/bugchecker.py 2010-04-14 16:59:49 UTC (rev 110907)
+++ zope.bugchecker/trunk/src/zope/bugchecker/bugchecker.py 2010-04-14 17:48:53 UTC (rev 110908)
@@ -11,38 +11,77 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
+# Created by Charlie Clark on 2010-04-06.
+#
+# Uses lauchpadlib, https://edge.launchpad.net/+apidoc/1.0.htmls
+# Particularly the projects 'collection' and project and bug_task 'entries'
+#
+# N.B. bug_tasks are not the same as bugs.
##############################################################################
-"""
-bugtracker.py
+# $Id$
+""" checkbugs
-$Id$
+Check which Launchpad bugs for a project or project have been marked as
+in a given status (default 'New') for at least a number of days (default 14).
-Check which bugs have been marked as 'new' for at least
-14 days
+Usage:
-Uses lauchpadlib
-https://edge.launchpad.net/+apidoc/1.0.htmls
-Particularly the projects 'collection' and project and bug_task 'entries'
-N.B. bug_tasks are not the same as bugs.
+ $ checkbugs [OPTIONS] [project-name]*
-Created by Charlie Clark on 2010-04-06.
+Options
+-------
+
+--help, -h, -? Display this usage message and exit.
+
+--version, -V Print the version of the script and exit.
+
+--quiet, -q Emit less output.
+
+--verbose, -v Emit more output.
+
+--num-days, -n Set the number of days old a bug must be to be reported
+ (defaults to 14).
+
+--state, -s Set the state used to find bugs (defaults to "New";
+ allowed values include:
+
+ New
+ "Incomplete (with response)",
+ "Incomplete (without response)"
+ Incomplete
+ Invalid
+ "Won't Fix"
+ Confirmed
+ Triaged
+ "In Progress"
+ "Fix Committed"
+ "Fix Released"
+
+ May be repeated.
+
+ Note that you need to quote any values containing spaces.
+
+--project-group, -g Supply a named project group. If no project names are
+ passed, use the project group to look up a list of project
+ names
"""
import datetime
+import getopt
+import sys
+
from launchpadlib.launchpad import Launchpad
-today = datetime.date.today()
-two_weeks = datetime.timedelta(days=14)
-report_date = today - two_weeks
-
class BugTracker(object):
"""Check the BugTracker for new bugs"""
- def __init__(self, project):
+ def __init__(self, launchpad, project, report_date, states, verbose):
"""Log into launchpad and get the Zope 3 project
"""
self.project = project
- launchpad = Launchpad.login_anonymously("Zope Bugtracker", "edge")
+ self.report_date = report_date
+ self.states = states
+ self.verbose = verbose
self.project = launchpad.projects[project]
self.bugs = []
@@ -51,27 +90,89 @@
two weeks ago.
Have to fumble with the reported creation date as it has a timezone
"""
- bugs = self.project.searchTasks(status=('New',))
+ bugs = self.project.searchTasks(status=tuple(self.states))
for (idx, bug) in enumerate(bugs):
date_created = datetime.date(*bug.date_created.timetuple()[:3])
- if date_created < report_date:
- self.bugs.append("%s\n%s" % (bug.title, bug.bug_link))
+ if date_created < self.report_date:
+ self.bugs.append({'title': bug.title,
+ 'link': bug.bug_link,
+ 'created': date_created.isoformat(),
+ 'status': bug.status,
+ })
def report(self):
"""Return a printable summary
"""
lines = ['Languishing bugs for: %s' % self.project]
- lines.extend(self.bugs)
+ for bug in self.bugs:
+ if self.verbose:
+ fmt = '%(title)s\n %(status)s %(created)s\n %(link)s'
+ else:
+ fmt = '%(title)s\n %(link)s'
+ lines.append(fmt % bug)
return "\n\n".join(lines)
-def main(*projects):
- if not projects:
- import sys
- projects = sys.argv[1:] or ['zope3']
+def get_projects_from_group(launchpad, project_group):
+ return [x['name'] for x in launchpad.project_groups[project_group]]
+
+def main():
+ verbose = 1
+ days = 14
+ states = []
+ project_group = None
+ try:
+ options, args = getopt.gnu_getopt(sys.argv[1:],
+ '?hqvn:s:g:',
+ ['help',
+ 'verbose',
+ 'quiet',
+ 'num-days=',
+ 'state=',
+ 'project-group=',
+ ])
+ except getopt.GetoptError, e:
+ print __doc__
+ print
+ print str(e)
+ sys.exit(1)
+
+ for k, v in options:
+ if k in ('-h', '-?', '--help'):
+ print __doc__
+ sys.exit(2)
+ elif k in ('-q', '--quiet'):
+ verbose = 0
+ elif k in ('-v', '--verbose'):
+ verbose += 1
+ elif k in ('-n', '--num-days'):
+ days = int(v)
+ elif k in ('-s', '--state'):
+ states.append(v)
+ elif k in ('-g', '--project-group'):
+ project_group = v
+ else:
+ print __doc__
+ sys.exit(1)
+
+ today = datetime.date.today()
+ delta = datetime.timedelta(days=days)
+ report_date = today - delta
+ launchpad = Launchpad.login_anonymously("Zope Bugtracker", "edge")
+
+ if args:
+ projects = args
+ elif project_group is not None:
+ projects = get_projects_from_group(launchpad, project_group)
+ else:
+ projects = ['zope3']
+
+ if not states:
+ states.append('New')
+
for project in projects:
- Tracker = BugTracker(project)
+ Tracker = BugTracker(launchpad, project, report_date, states, verbose)
Tracker.get()
print Tracker.report()
if __name__ == '__main__':
- main(sys.argv[1:])
+ main()
More information about the checkins
mailing list