mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
* get-branches: Improved option handling.
This commit is contained in:
parent
ba12b9a4d6
commit
a26bfee8bb
1
debian/changelog
vendored
1
debian/changelog
vendored
@ -7,6 +7,7 @@ ubuntu-dev-tools (0.39ubuntu1) intrepid; urgency=low
|
|||||||
- Added support to request the rebuilding or rescoring of only one
|
- Added support to request the rebuilding or rescoring of only one
|
||||||
architecture.
|
architecture.
|
||||||
* hugdaylist: Improved number of bugs option handling.
|
* hugdaylist: Improved number of bugs option handling.
|
||||||
|
* get-branches: Improved option handling.
|
||||||
|
|
||||||
[ Siegfried-Angel Gevatter Pujals ]
|
[ Siegfried-Angel Gevatter Pujals ]
|
||||||
* debian/control:
|
* debian/control:
|
||||||
|
93
get-branches
93
get-branches
@ -21,7 +21,8 @@
|
|||||||
# ##################################################################
|
# ##################################################################
|
||||||
#
|
#
|
||||||
# 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.
|
# of a Launchpad team.
|
||||||
|
#
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -34,79 +35,49 @@ def main():
|
|||||||
usage = "Usage: %prog [-d <directory>] -t <team> [-o <operation>]"
|
usage = "Usage: %prog [-d <directory>] -t <team> [-o <operation>]"
|
||||||
usage += "\nUsage: %prog <team>"
|
usage += "\nUsage: %prog <team>"
|
||||||
optParser = OptionParser(usage)
|
optParser = OptionParser(usage)
|
||||||
optsParsed = 0
|
|
||||||
|
|
||||||
# Our options.
|
# Our options.
|
||||||
optParser.add_option("-d", "--directory", action = "store_true",
|
optParser.add_option("-d", "--directory", action = "store", type = "string",
|
||||||
dest = "directory", help = "Directory to download branches to.")
|
dest = "directory", default = ".",
|
||||||
optParser.add_option("-t", "--team", action = "store_true",
|
help = "Directory to download branches to.")
|
||||||
|
optParser.add_option("-t", "--team", action = "store", type = "string",
|
||||||
dest = "lpteam", help = "Launchpad team to download branches from.")
|
dest = "lpteam", help = "Launchpad team to download branches from.")
|
||||||
optParser.add_option("-o", "--operation", action = "store_true",
|
optParser.add_option("-o", "--operation", action = "store", type = "string",
|
||||||
dest = "operation", help = "Whether to branch or checkout the " \
|
dest = "operation", default = "branch",
|
||||||
"Bazaar branches. May be either 'branch' or 'checkout'.")
|
help = "Whether to branch or checkout the Bazaar branches. May be " \
|
||||||
|
"either 'branch' or 'checkout'.")
|
||||||
|
|
||||||
(options, args) = optParser.parse_args()
|
(options, args) = optParser.parse_args()
|
||||||
|
|
||||||
# Parse our options.
|
# Parse our options aka Russian roulette time.
|
||||||
# No flags, and no team name specified.
|
if len(args) != 1 and options.lpteam == None:
|
||||||
if not options.lpteam and not args:
|
optParser.error("No team has been specified.")
|
||||||
print >> sys.stderr, "No team has been specified."
|
|
||||||
optParser.print_help()
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if args:
|
|
||||||
team = args[0]
|
|
||||||
|
|
||||||
# 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 valid directory." % directory
|
|
||||||
optParser.print_help()
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
directory = os.path.abspath(args[0])
|
|
||||||
else:
|
|
||||||
# Otherwise use our current directory.
|
|
||||||
directory = os.getcwd()
|
|
||||||
|
|
||||||
# Launchpad team setting.
|
# Launchpad team setting.
|
||||||
if options.lpteam:
|
if options.lpteam:
|
||||||
try:
|
team = str(options.lpteam).lower()
|
||||||
team = args[optsParsed]
|
if args:
|
||||||
optsParsed += 1
|
team = str(args[0]).lower()
|
||||||
except IndexError:
|
|
||||||
print >> sys.stderr, "The '-t' option requires an argument."
|
directory = options.directory
|
||||||
optParser.print_help()
|
|
||||||
sys.exit(1)
|
# Dictionary settings.
|
||||||
|
if not os.path.isdir(directory): # Check that it is a directory.
|
||||||
|
optParser.error("%s is not a valid directory." % directory)
|
||||||
|
|
||||||
# Type of Bazaar operation to perform.
|
# Type of Bazaar operation to perform.
|
||||||
if options.operation:
|
operation_type = str(options.operation).lower()
|
||||||
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.
|
# Got an argument, check if it is valid.
|
||||||
if operation_type.lower() not in ("branch", "checkout"):
|
if operation_type.lower() not in ("branch", "checkout"):
|
||||||
print >> sys.stderr, "Invalid operation '%s' for '-o' flag." % \
|
optParser.error("Invalid operation '%s' for '-o' flag.") % \
|
||||||
operation_type
|
operation_type
|
||||||
optParser.print_help()
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
operation_type = "branch"
|
|
||||||
|
|
||||||
|
|
||||||
|
# Fetch our current directory to return to later.
|
||||||
pwd = os.getcwd()
|
pwd = os.getcwd()
|
||||||
|
|
||||||
|
# Change to the specified directory.
|
||||||
os.chdir(directory)
|
os.chdir(directory)
|
||||||
|
|
||||||
# Try to open the teams code page.
|
# Try to open the teams code page.
|
||||||
@ -124,19 +95,19 @@ def main():
|
|||||||
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
|
|
||||||
|
|
||||||
# Check the team actually has branches.
|
# Check the team actually has branches.
|
||||||
if len(branch_page_urls) == 0:
|
if len(branch_page_urls) == 0:
|
||||||
print "The team '%s' does not have any branches on Launchpad." % team
|
print "The team '%s' does not have any branches on Launchpad." % team
|
||||||
os.rmdir(team)
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
print "Downloading all branches for the team '%s'. This may take some " \
|
||||||
|
"time." % team
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.makedirs(team)
|
os.makedirs(team)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
os.chdir(team)
|
os.chdir(team)
|
||||||
|
|
||||||
for url in branch_page_urls:
|
for url in branch_page_urls:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user