9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce#!/usr/bin/python
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce# Copyright (c) 2010 Canonical Ltd.
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce#
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce# This program is free software; you can redistribute it and/or modify it
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce# under the terms of the GNU General Public License version 3 as published
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce# by the # Free Software Foundation
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce#
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce# lp-mark-bugs-released is distributed in the hope that it will be useful, but
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce# WITHOUT ANY WARRANTY; without even the implied warranty of
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce# General Public License for more details.
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce'''Mark bugs that are Fix Committed on a release to be Fix Released'''
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryceimport datetime
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryceimport os
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryceimport sys
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryceimport tempfile
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2brycefrom launchpadlib.launchpad import Launchpad
9091c524d0acf0836cd2cdb53903bb8abaa92df2brycefrom launchpadlib.errors import HTTPError
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
ac4dc8c32116eb4089277fd2ef8c3e4700a429a2bryceopt_dry_run = False
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2brycedef mark_released (bug):
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce if bug.status == 'Fix Committed':
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce print "Marking bug " + str(bug.bug.id) + " as 'Fix Released'"
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce bug.status = "Fix Released"
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce if not opt_dry_run:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce bug.lp_save()
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2brycedef main():
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce if len(sys.argv) != 3:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce print >> sys.stderr, '''Mark bugs 'Fix Committed' on a release as released
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce Usage: %s <project name> <version>''' % sys.argv[0]
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce sys.exit(1)
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce (project, version) = sys.argv[1:]
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce try:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce launchpad = Launchpad.login_with('ubuntu-dev-tools', 'production')
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce except Exception, error:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce print >> sys.stderr, 'Could not connect to Launchpad:', str(error)
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce sys.exit(2)
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce try:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce # Look up the project using the Launchpad instance.
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce proj = launchpad.projects[project]
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce # Find the release in the project's releases collection.
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce release = None
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce for rel in proj.releases:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce if rel.version == version:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce release = rel
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce break
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce if not release:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce print >> sys.stderr, '''Unable to find release: %s''' % version
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce sys.exit(1)
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce # Mark any fix committed bugs released
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce for task in release.milestone.searchTasks(status="Fix Committed"):
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce if task.milestone is None:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce for othertask in task.related_tasks:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce if othertask.milestone.name == release.milestone.name:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce mark_released(othertask)
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce else:
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce mark_released(task)
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce except HTTPError, error:
ac4dc8c32116eb4089277fd2ef8c3e4700a429a2bryce print 'An error happened in the upload: %s\n%s' %(
ac4dc8c32116eb4089277fd2ef8c3e4700a429a2bryce error.content,
ac4dc8c32116eb4089277fd2ef8c3e4700a429a2bryce error.__dict__)
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce sys.exit(1)
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryceif __name__ == '__main__':
9091c524d0acf0836cd2cdb53903bb8abaa92df2bryce main()