diff --git a/debian/changelog b/debian/changelog index b4e726e..a925bf4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,7 @@ ubuntu-dev-tools (0.39ubuntu1) intrepid; urgency=low - Added support to request the rebuilding or rescoring of only one architecture. * hugdaylist: Improved number of bugs option handling. + * get-branches: Improved option handling. [ Siegfried-Angel Gevatter Pujals ] * debian/control: diff --git a/get-branches b/get-branches index 28eaafb..3bd4364 100755 --- a/get-branches +++ b/get-branches @@ -21,7 +21,8 @@ # ################################################################## # # This script is used to checkout or branch all the Bazaar branches -# in a Launchpad team. +# of a Launchpad team. +# import os import re @@ -34,79 +35,49 @@ def main(): usage = "Usage: %prog [-d ] -t [-o ]" usage += "\nUsage: %prog " 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'.") + optParser.add_option("-d", "--directory", action = "store", type = "string", + dest = "directory", default = ".", + 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'.") (options, args) = optParser.parse_args() - # Parse our options. - # 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) + # Parse our options aka Russian roulette time. + if len(args) != 1 and options.lpteam == None: + optParser.error("No team has been specified.") - 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. if options.lpteam: - try: - team = args[optsParsed] - optsParsed += 1 - except IndexError: - print >> sys.stderr, "The '-t' option requires an argument." - optParser.print_help() - sys.exit(1) + team = str(options.lpteam).lower() + if args: + team = str(args[0]).lower() + directory = options.directory + + # 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. - 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) + operation_type = str(options.operation).lower() - # 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" + # Got an argument, check if it is valid. + if operation_type.lower() not in ("branch", "checkout"): + optParser.error("Invalid operation '%s' for '-o' flag.") % \ + operation_type + + # Fetch our current directory to return to later. pwd = os.getcwd() + + # Change to the specified directory. os.chdir(directory) # Try to open the teams code page. @@ -124,19 +95,19 @@ def main(): branch_page_urls_regex = r'.*