From 477a2b16dd003411a26bd4914321381d7f8f2b67 Mon Sep 17 00:00:00 2001 From: Daniel Holbach Date: Fri, 27 Jul 2007 10:33:19 +0200 Subject: [PATCH] add 'get-branches' utility --- AUTHORS | 1 + get-branches | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 1 + 3 files changed, 70 insertions(+) create mode 100755 get-branches diff --git a/AUTHORS b/AUTHORS index 15755b2..ac64f37 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,3 +3,4 @@ Luke Yelavich Albin Tonnerre Michael Bienia Kees Cook +Martin Pitt diff --git a/get-branches b/get-branches new file mode 100755 index 0000000..d89b305 --- /dev/null +++ b/get-branches @@ -0,0 +1,68 @@ +#!/usr/bin/python + +# (C) 2007, Canonical +# Daniel Holbach +# GPLv3 + +import urllib2 +import sys +import re +import os + +def main(): + usage = "Usage: get-branches [checkout|branch]" + if len(sys.argv) < 3: + print >> sys.stderr, usage + sys.exit(1) + + directory = os.path.expanduser(sys.argv[1]) + team = sys.argv[2] + operation_type = "branch" + if len(sys.argv) == 4: + operation_type = sys.argv[3] + + pwd = os.getcwd() + try: + os.chdir(directory) + except: + print >> sys.stderr, "Directory '%s' not found." % directory + sys.exit(1) + + try: + os.makedirs(team) + except: + pass + os.chdir(team) + + sock = urllib2.urlopen("http://code.launchpad.net/~%s" % team) + branch_list_page = sock.read() + sock.close() + branch_page_urls_regex = r'.*Hosted on Launchpad:.*\n.*(.*)' + branch_url = re.findall(branch_url_regex, branch_page) + print branch_url[0] + if branch_url[0]: + product = branch_url[0].split("/")[-2] + branch_nick = branch_url[0].split("/")[-1] + if not os.path.exists(product): + os.makedirs(product) + os.chdir(product) + if not os.path.exists(branch_nick): + os.system("bzr %s %s" % (operation_type, branch_url[0])) + else: + os.chdir(branch_nick) + os.system("bzr merge --pull --remember") + os.chdir(directory) + + os.chdir(pwd) + sys.exit(0) + + +if __name__ == "__main__": + main() + diff --git a/setup.py b/setup.py index 53a8c14..23a7703 100755 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ setup(name='ubuntu-dev-tools', version=version, scripts=['404main', 'check-symbols', + 'get-branches', 'pbuilder-dist', 'update-maintainer', 'dch-repeat',