2007-07-27 10:33:19 +02:00
|
|
|
#!/usr/bin/python
|
2007-11-07 20:05:37 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-10 21:57:25 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# Copyright (C) 2007 Canonical Ltd.
|
2007-08-04 13:52:30 +02:00
|
|
|
# Created by Daniel Holbach <daniel.holbach@ubuntu.com>
|
2008-08-10 21:57:25 +01:00
|
|
|
# Modified by Jonathan Patrick Davies <jpds@ubuntu.com>
|
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# ##################################################################
|
2008-08-10 21:57:25 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; version 3.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2008-08-10 21:57:25 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# See file /usr/share/common-licenses/GPL-3 for more details.
|
2008-08-10 21:57:25 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# ##################################################################
|
2007-08-04 13:52:30 +02:00
|
|
|
#
|
|
|
|
# This script is used to checkout or branch all the Bazaar branches
|
2008-08-14 10:43:20 +01:00
|
|
|
# of a Launchpad team.
|
|
|
|
#
|
2007-07-27 10:33:19 +02:00
|
|
|
|
|
|
|
import os
|
2008-08-10 21:53:43 +01:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
from optparse import OptionParser
|
2010-04-16 12:29:02 +02:00
|
|
|
from ubuntutools.lp.lpapicache import PersonTeam
|
2007-07-27 10:33:19 +02:00
|
|
|
|
|
|
|
def main():
|
2008-08-10 21:53:43 +01:00
|
|
|
usage = "Usage: %prog [-d <directory>] -t <team> [-o <operation>]"
|
|
|
|
usage += "\nUsage: %prog <team>"
|
|
|
|
optParser = OptionParser(usage)
|
|
|
|
|
|
|
|
# Our options.
|
2008-08-14 10:43:20 +01:00
|
|
|
optParser.add_option("-d", "--directory", action = "store", type = "string",
|
2010-04-08 09:55:27 -05:00
|
|
|
dest = "directory", default = os.getcwd(),
|
2008-08-14 10:43:20 +01:00
|
|
|
help = "Directory to download branches to.")
|
|
|
|
optParser.add_option("-t", "--team", action = "store", type = "string",
|
|
|
|
dest = "lpteam", help = "Launchpad team to download branches from.")
|
|
|
|
optParser.add_option("-o", "--operation", action = "store", type = "string",
|
|
|
|
dest = "operation", default = "branch",
|
|
|
|
help = "Whether to branch or checkout the Bazaar branches. May be " \
|
|
|
|
"either 'branch' or 'checkout'.")
|
2008-08-10 21:53:43 +01:00
|
|
|
|
|
|
|
(options, args) = optParser.parse_args()
|
|
|
|
|
2010-04-16 12:29:02 +02:00
|
|
|
# Fetch our current directory to return to later.
|
|
|
|
pwd = os.getcwd()
|
|
|
|
|
2008-12-30 10:23:00 +00:00
|
|
|
# Parse our options.
|
2008-08-14 10:43:20 +01:00
|
|
|
if len(args) != 1 and options.lpteam == None:
|
|
|
|
optParser.error("No team has been specified.")
|
|
|
|
|
|
|
|
# Dictionary settings.
|
2010-04-16 12:29:02 +02:00
|
|
|
directory = options.directory
|
2008-08-14 10:43:20 +01:00
|
|
|
if not os.path.isdir(directory): # Check that it is a directory.
|
|
|
|
optParser.error("%s is not a valid directory." % directory)
|
2010-04-16 12:29:02 +02:00
|
|
|
os.chdir(directory)
|
2008-08-10 21:53:43 +01:00
|
|
|
|
2010-04-16 12:29:02 +02:00
|
|
|
# Type of Bazaar operation to perform.
|
|
|
|
operation_type = options.operation.lower()
|
2008-08-14 10:50:04 +01:00
|
|
|
if operation_type not in ("branch", "checkout"):
|
|
|
|
optParser.error("Invalid operation '%s' for '-o' flag." % \
|
|
|
|
operation_type)
|
2008-08-10 21:53:43 +01:00
|
|
|
|
2010-04-16 12:29:02 +02:00
|
|
|
# Launchpad team setting.
|
|
|
|
if options.lpteam:
|
|
|
|
team = options.lpteam.lower()
|
|
|
|
if args:
|
|
|
|
team = args[0].lower()
|
|
|
|
try:
|
|
|
|
team = PersonTeam(team)
|
|
|
|
except KeyError:
|
|
|
|
print >> sys.stderr, "E: The team '%s' doesn't exist." % team
|
2008-08-14 10:43:20 +01:00
|
|
|
|
2010-04-16 12:29:02 +02:00
|
|
|
# Get a list of branches
|
|
|
|
branches = team.getBranches()
|
2007-07-27 10:33:19 +02:00
|
|
|
|
2010-04-16 12:29:02 +02:00
|
|
|
print "Downloading all branches for the '%s' team. This may take some " \
|
|
|
|
"time." % team.display_name
|
2008-08-14 10:43:20 +01:00
|
|
|
|
2008-08-12 00:09:01 +01:00
|
|
|
try:
|
2010-04-16 12:29:02 +02:00
|
|
|
os.makedirs(team.name)
|
2008-08-12 00:09:01 +01:00
|
|
|
except:
|
|
|
|
pass
|
2008-08-14 10:43:20 +01:00
|
|
|
|
2010-04-16 12:29:02 +02:00
|
|
|
os.chdir(team.name)
|
2010-04-08 09:55:27 -05:00
|
|
|
|
2010-04-16 12:29:02 +02:00
|
|
|
for branch in branches:
|
|
|
|
project_name = branch.project.name
|
|
|
|
if not os.path.exists(project_name):
|
|
|
|
os.makedirs(project_name)
|
|
|
|
os.chdir(project_name)
|
2008-08-10 21:53:43 +01:00
|
|
|
|
2010-04-16 12:29:02 +02:00
|
|
|
if not os.path.exists(branch.name):
|
|
|
|
print "Branching %s ..." % branch.display_name
|
|
|
|
subprocess.call(["bzr", operation_type, branch.bzr_identity, branch.name])
|
2008-08-10 21:53:43 +01:00
|
|
|
else:
|
2010-04-16 12:29:02 +02:00
|
|
|
print "Merging %s ..." % branch.display_name
|
|
|
|
os.chdir(branch.name)
|
2008-08-10 21:53:43 +01:00
|
|
|
subprocess.call(["bzr", "merge", "--pull", "--remember"])
|
2010-04-16 12:29:02 +02:00
|
|
|
os.chdir(os.path.join(directory, team.name))
|
|
|
|
|
2007-07-27 10:33:19 +02:00
|
|
|
os.chdir(pwd)
|
|
|
|
sys.exit(0)
|
2010-04-16 12:29:02 +02:00
|
|
|
|
2007-07-27 10:33:19 +02:00
|
|
|
if __name__ == "__main__":
|
2008-09-01 22:29:32 +01:00
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print "Operation was interrupted by user."
|