Skip to content

Instantly share code, notes, and snippets.

@ttx
Created June 28, 2013 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttx/5883868 to your computer and use it in GitHub Desktop.
Save ttx/5883868 to your computer and use it in GitHub Desktop.
Script to automatically adjust series goal based on target milestone in Launchpad blueprints
#!/usr/bin/python
#
# Script to automatically adjust series goal based on target milestone
# in Launchpad blueprints
#
# Copyright 2013 Thierry Carrez <thierry@openstack.org>
# All Rights Reserved.
#
# 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 argparse import ArgumentParser
from launchpadlib.launchpad import Launchpad
# Parse arguments
parser = ArgumentParser(description="Adjust series goal based on milestone")
parser.add_argument('projectname', help='The project to act on')
parser.add_argument('seriesname', help='The series to act on')
parser.add_argument('--dryrun', action='store_true',
help='Just show what would be done')
args = parser.parse_args()
# Log into LP
lp = Launchpad.login_with('adjust-series-goal', 'production', version='devel')
project = lp.projects[args.projectname]
series = project.getSeries(name=args.seriesname)
# Get the milestones for the series
milestones = []
for ms in series.active_milestones_collection:
milestones.append(ms)
# Get the blueprints in the series
proposed = []
for bp in series.all_specifications:
if not bp.is_complete:
if bp.milestone not in milestones:
if not bp.has_accepted_goal:
# Blueprint is in series, no milestone, proposed/declined
if args.dryrun:
print "CLEAR (proposed/declined) %s" % bp.name
else:
bp.proposeGoal(goal=None)
bp.priority = "Undefined"
bp.save()
else:
# Blueprint is in series, no milestone, accepted
if args.dryrun:
print "CLEAR (accepted) %s" % bp.name
else:
bp.proposeGoal(goal=None)
bp.priority = "Undefined"
bp.save()
else:
if not bp.has_accepted_goal:
# Blueprint is in series, has milestone, proposed/declined
if args.dryrun:
print "APPROVE (proposed/declined) %s" % bp.name
else:
bp.acceptGoal()
# Get the blueprints with seriesgoal set
accepted = series.valid_specifications
# Find targeted blueprints that are not in the series
for bp in project.valid_specifications:
if bp.milestone in milestones and bp not in accepted:
# Blueprint has milestone, but is not accepted for the series yet
if args.dryrun:
print "SET %s" % bp.name
else:
bp.proposeGoal(goal=series)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment