mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
* get-branches:
- Rewrote option handling with optparse. - Added short version of GPL to header. - Fixed regular expressions to work with new Launchpad interface. - Use subprocess.call() on Bazaar instead of os.system().
This commit is contained in:
parent
1c7abae846
commit
4f9d3426b5
5
debian/changelog
vendored
5
debian/changelog
vendored
@ -11,6 +11,11 @@ ubuntu-dev-tools (0.36ubuntu1) intrepid; urgency=low
|
|||||||
- Added code to handle exceptions and short version of GPL.
|
- Added code to handle exceptions and short version of GPL.
|
||||||
- Rewrote option handling with optparse.
|
- Rewrote option handling with optparse.
|
||||||
- Filter bugs subscribed to the ubuntu-archive team.
|
- Filter bugs subscribed to the ubuntu-archive team.
|
||||||
|
* get-branches:
|
||||||
|
- Rewrote option handling with optparse.
|
||||||
|
- Added short version of GPL to header.
|
||||||
|
- Fixed regular expressions to work with new Launchpad interface.
|
||||||
|
- Use subprocess.call() on Bazaar instead of os.system().
|
||||||
* debian/copyright: Updated Authors and copyrights.
|
* debian/copyright: Updated Authors and copyrights.
|
||||||
|
|
||||||
[ Siegfried-Angel Gevatter Pujals ]
|
[ Siegfried-Angel Gevatter Pujals ]
|
||||||
|
142
get-branches
142
get-branches
@ -7,29 +7,89 @@
|
|||||||
# This script is used to checkout or branch all the Bazaar branches
|
# This script is used to checkout or branch all the Bazaar branches
|
||||||
# in a Launchpad team.
|
# in a Launchpad team.
|
||||||
|
|
||||||
import urllib2
|
|
||||||
import sys
|
|
||||||
import re
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import urllib2
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
usage = "Usage: get-branches <directory> <team> [checkout|branch]"
|
usage = "Usage: %prog [-d <directory>] -t <team> [-o <operation>]"
|
||||||
if len(sys.argv) < 3:
|
usage += "\nUsage: %prog <team>"
|
||||||
print >> sys.stderr, usage
|
optParser = OptionParser(usage)
|
||||||
|
optsParsed = 0
|
||||||
|
|
||||||
|
# Our options.
|
||||||
|
optParser.add_option("-d", "--directory", action = "store_true",
|
||||||
|
dest = "directory", help = "Directory to download branches to.")
|
||||||
|
optParser.add_option("-t", "--team", action = "store_true",
|
||||||
|
dest = "lpteam", help = "Launchpad team to download branches from.")
|
||||||
|
optParser.add_option("-o", "--operation", action = "store_true",
|
||||||
|
dest = "operation", help = "Whether to branch or checkout the " \
|
||||||
|
"Bazaar branches. May be either 'branch' or 'checkout'.")
|
||||||
|
|
||||||
|
(options, args) = optParser.parse_args()
|
||||||
|
|
||||||
|
# Parse our options.
|
||||||
|
# Dictionary settings.
|
||||||
|
if options.directory:
|
||||||
|
try:
|
||||||
|
directory = args[optsParsed]
|
||||||
|
optsParsed += 1
|
||||||
|
except IndexError:
|
||||||
|
print >> sys.stderr, "The '-d' option requires an argument."
|
||||||
|
optParser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if not os.path.isdir(directory): # Check that it is a directory.
|
||||||
|
print >> sys.stderr, "%s is not a directory." % directory
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
directory = os.path.abspath(args[0])
|
||||||
|
else:
|
||||||
|
# Otherwise use our current directory.
|
||||||
|
directory = os.getcwd()
|
||||||
|
|
||||||
|
# Launchpad team setting.
|
||||||
|
if options.lpteam:
|
||||||
|
try:
|
||||||
|
team = args[0]
|
||||||
|
optsParsed += 1
|
||||||
|
except IndexError:
|
||||||
|
print >> sys.stderr, "The '-t' option requires an argument."
|
||||||
|
optParser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Type of Bazaar operation to perform.
|
||||||
|
if options.operation:
|
||||||
|
try:
|
||||||
|
operation_type = args[optsParsed]
|
||||||
|
optsParsed += 1
|
||||||
|
except IndexError:
|
||||||
|
print >> sys.stderr, "The '-o' option requires an argument."
|
||||||
|
optParser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Got an argument, check if it is valid.
|
||||||
|
if operation_type.lower() not in ("branch", "checkout"):
|
||||||
|
print >> sys.stderr, "Invalid operation '%s' for '-o' flag." % \
|
||||||
|
operation_type
|
||||||
|
optParser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
operation_type = "branch"
|
||||||
|
|
||||||
|
# No flags, and no team name specified.
|
||||||
|
if not options.lpteam and not args:
|
||||||
|
print >> sys.stderr, "No team has been specified."
|
||||||
|
optParser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
elif args:
|
||||||
directory = os.path.abspath(sys.argv[1]))
|
team = args[optsParsed]
|
||||||
team = sys.argv[2]
|
|
||||||
operation_type = "branch"
|
|
||||||
if len(sys.argv) == 4:
|
|
||||||
operation_type = sys.argv[3]
|
|
||||||
|
|
||||||
pwd = os.getcwd()
|
pwd = os.getcwd()
|
||||||
try:
|
os.chdir(directory)
|
||||||
os.chdir(directory)
|
|
||||||
except:
|
|
||||||
print >> sys.stderr, "Directory '%s' not found." % directory
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.makedirs(team)
|
os.makedirs(team)
|
||||||
@ -37,34 +97,50 @@ def main():
|
|||||||
pass
|
pass
|
||||||
os.chdir(team)
|
os.chdir(team)
|
||||||
|
|
||||||
sock = urllib2.urlopen("http://code.launchpad.net/~%s" % team)
|
# Try to open the teams code page.
|
||||||
|
try:
|
||||||
|
sock = urllib2.urlopen("https://code.launchpad.net/~%s" % team)
|
||||||
|
except urllib2.HTTPError:
|
||||||
|
print >> sys.stderr, "The page http://code.launchpad.net/~%s does " \
|
||||||
|
"not exist." % team
|
||||||
|
print >> sys.stderr, "Perhaps invalid team name?"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
branch_list_page = sock.read()
|
branch_list_page = sock.read()
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
branch_page_urls_regex = r'.*<a href="/(~%s/.*)".*' % team
|
branch_page_urls_regex = r'.*<a href="/(~%s/.*)".*' % team
|
||||||
branch_page_urls = re.findall(branch_page_urls_regex, branch_list_page)
|
branch_page_urls = re.findall(branch_page_urls_regex, branch_list_page)
|
||||||
|
|
||||||
|
print "Downloading all branches for the team '%s'. This may take some " \
|
||||||
|
"time." % team
|
||||||
|
|
||||||
for url in branch_page_urls:
|
for url in branch_page_urls:
|
||||||
sock = urllib2.urlopen("http://code.launchpad.net/%s" % url)
|
sock = urllib2.urlopen("https://code.launchpad.net/%s" % url)
|
||||||
branch_page = sock.read()
|
branch_page = sock.read()
|
||||||
sock.close()
|
sock.close()
|
||||||
branch_url_regex = r'<th>Hosted on Launchpad:</th>.*\n.*<td>(.*)</td>'
|
|
||||||
|
branch_url_regex = r'<tt>bzr branch lp:~(.*)</tt>'
|
||||||
branch_url = re.findall(branch_url_regex, branch_page)
|
branch_url = re.findall(branch_url_regex, branch_page)
|
||||||
print branch_url[0]
|
print "Downloading branch:", branch_url[0]
|
||||||
|
|
||||||
if branch_url[0]:
|
if branch_url[0]:
|
||||||
product = branch_url[0].split("/")[-2]
|
product = branch_url[0].split("/")[-2]
|
||||||
branch_nick = branch_url[0].split("/")[-1]
|
branch_nick = branch_url[0].split("/")[-1]
|
||||||
if not os.path.exists(product):
|
|
||||||
os.makedirs(product)
|
if not os.path.exists(product):
|
||||||
os.chdir(product)
|
os.makedirs(product)
|
||||||
if not os.path.exists(branch_nick):
|
os.chdir(product)
|
||||||
os.system("bzr %s %s" % (operation_type, branch_url[0]))
|
|
||||||
else:
|
if not os.path.exists(branch_nick):
|
||||||
os.chdir(branch_nick)
|
subprocess.call(["bzr", operation_type, "lp:~%s" % branch_url[0]])
|
||||||
os.system("bzr merge --pull --remember")
|
else:
|
||||||
os.chdir(os.path.join(directory, team))
|
os.chdir(branch_nick)
|
||||||
|
subprocess.call(["bzr", "merge", "--pull", "--remember"])
|
||||||
|
os.chdir(os.path.join(directory, team))
|
||||||
|
|
||||||
os.chdir(pwd)
|
os.chdir(pwd)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user