Merge lp:~jelmer/lptools/migrate-get-branches into lp:lptools

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 23
Proposed branch: lp:~jelmer/lptools/migrate-get-branches
Merge into: lp:lptools
Diff against target: 177 lines (+167/-0)
2 files modified
bin/lp-get-branches (+120/-0)
doc/lp-get-branches.1 (+47/-0)
To merge this branch: bzr merge lp:~jelmer/lptools/migrate-get-branches
Reviewer Review Type Date Requested Status
lptools Hackers Pending
Review via email: mp+72569@code.launchpad.net

Description of the change

Import lp-get-branches from ubuntu-dev-tools.

At the moment this still uses subprocess to call out to the bzr executable, it would be nice if it could be migrated to use bzrlib in the future.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'bin/lp-get-branches'
2--- bin/lp-get-branches 1970-01-01 00:00:00 +0000
3+++ bin/lp-get-branches 2011-08-23 13:18:07 +0000
4@@ -0,0 +1,120 @@
5+#!/usr/bin/python
6+# -*- coding: utf-8 -*-
7+#
8+# Copyright (C) 2007 Canonical Ltd.
9+# Created by Daniel Holbach <daniel.holbach@ubuntu.com>
10+# Modified by Jonathan Patrick Davies <jpds@ubuntu.com>
11+#
12+# ##################################################################
13+#
14+# This program is free software; you can redistribute it and/or
15+# modify it under the terms of the GNU General Public License
16+# as published by the Free Software Foundation; version 3.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU General Public License for more details.
22+#
23+# See file /usr/share/common-licenses/GPL-3 for more details.
24+#
25+# ##################################################################
26+#
27+# This script is used to checkout or branch all the Bazaar branches
28+# of a Launchpad team.
29+#
30+
31+import os
32+import subprocess
33+import sys
34+from lptools import config
35+from optparse import OptionParser
36+
37+def main():
38+ usage = "Usage: %prog [-d <directory>] -t <team> [-o <operation>]"
39+ usage += "\nUsage: %prog <team>"
40+ opt_parser = OptionParser(usage)
41+
42+ # Our options.
43+ opt_parser.add_option("-d", "--directory", action="store", type="string",
44+ dest="directory", default=os.getcwd(),
45+ help="Directory to download branches to.")
46+ opt_parser.add_option("-t", "--team", action="store", type="string",
47+ dest="lpteam",
48+ help="Launchpad team to download branches from.")
49+ opt_parser.add_option("-o", "--operation", action="store", type="string",
50+ dest="operation", default="branch",
51+ help="Whether to branch or checkout the Bazaar "
52+ "branches. May be either 'branch' or "
53+ "'checkout'.")
54+
55+ (options, args) = opt_parser.parse_args()
56+
57+ launchpad = config.get_launchpad("get-branches")
58+
59+ # Fetch our current directory to return to later.
60+ pwd = os.getcwd()
61+
62+ # Parse our options.
63+ if len(args) != 1 and options.lpteam == None:
64+ opt_parser.error("No team has been specified.")
65+
66+ # Dictionary settings.
67+ directory = options.directory
68+ if not os.path.isdir(directory): # Check that it is a directory.
69+ opt_parser.error("%s is not a valid directory." % directory)
70+ os.chdir(directory)
71+
72+ # Type of Bazaar operation to perform.
73+ operation_type = options.operation.lower()
74+ if operation_type not in ("branch", "checkout"):
75+ opt_parser.error("Invalid operation '%s' for '-o' flag." % \
76+ operation_type)
77+
78+ # Launchpad team setting.
79+ if options.lpteam:
80+ team = options.lpteam.lower()
81+ if args:
82+ team = args[0].lower()
83+ try:
84+ team = launchpad.people[team]
85+ except KeyError:
86+ print >> sys.stderr, "E: The team '%s' doesn't exist." % team
87+
88+ # Get a list of branches
89+ branches = team.getBranches()
90+
91+ print "Downloading all branches for the '%s' team. This may take some " \
92+ "time." % team.display_name
93+
94+ try:
95+ os.makedirs(team.name)
96+ except:
97+ pass
98+
99+ os.chdir(team.name)
100+
101+ for branch in branches:
102+ project_name = branch.project.name
103+ if not os.path.exists(project_name):
104+ os.makedirs(project_name)
105+ os.chdir(project_name)
106+
107+ if not os.path.exists(branch.name):
108+ print "Branching %s ..." % branch.display_name
109+ cmd = ["bzr", operation_type, branch.bzr_identity, branch.name]
110+ subprocess.call(cmd)
111+ else:
112+ print "Merging %s ..." % branch.display_name
113+ os.chdir(branch.name)
114+ subprocess.call(["bzr", "merge", "--pull", "--remember"])
115+ os.chdir(os.path.join(directory, team.name))
116+
117+ os.chdir(pwd)
118+ sys.exit(0)
119+
120+if __name__ == "__main__":
121+ try:
122+ main()
123+ except KeyboardInterrupt:
124+ print "Operation was interrupted by user."
125
126=== added directory 'doc'
127=== added file 'doc/lp-get-branches.1'
128--- doc/lp-get-branches.1 1970-01-01 00:00:00 +0000
129+++ doc/lp-get-branches.1 2011-08-23 13:18:07 +0000
130@@ -0,0 +1,47 @@
131+.TH get\-branches "1" "11 August 2008" "ubuntu-dev-tools"
132+.SH NAME
133+get\-branches - downloads all branches related to a Launchpad team or person
134+
135+.SH SYNOPSIS
136+.B get\-branches
137+.RB [ \-d
138+.IR directory ]
139+.RB [ \-o
140+.BR branch | checkout ]
141+.B \-t
142+.I team
143+.br
144+.B get\-branches
145+.I team
146+.br
147+.B get\-branches \-\-help
148+
149+.SH DESCRIPTION
150+\fBget\-branches\fR uses the LP API to get a list of branches for a person or
151+team and calls Bazaar to download all branches.
152+
153+.SH OPTIONS
154+Listed below are the command line options for \fBget\-branches\fR:
155+.TP
156+.BR \-h ", " \-\-help
157+Display a help message and exit.
158+.TP
159+.BR \-d ", " \-\-directory
160+Download branches to a directory other than the current directory.
161+.TP
162+.BR \-o ", " \-\-operation
163+Specifies which Bazaar operation to use when downloading the branches; may be
164+either \fIbranch\fR or \fIcheckout\fR.
165+.TP
166+.BR \-t ", " \-\-team
167+Specifies which Launchpad team/person to download branches from.
168+This option is required.
169+
170+.SH AUTHORS
171+\fBget\-branches\fR was written by Daniel Holbach <daniel.holbach@ubuntu.com>,
172+and this manual page was written by Jonathan Patrick Davies <jpds@ubuntu.com>.
173+.PP
174+Both are released under the terms of the GNU General Public License, version 3.
175+
176+.SH SEE ALSO
177+.B bzr(1)

Subscribers

People subscribed via source and target branches