Port grab-attachments to optparse

This commit is contained in:
Stefano Rivera 2010-12-21 22:33:53 +02:00
parent 3f776be478
commit eedb60b296

View File

@ -18,30 +18,28 @@
# #
# ################################################################## # ##################################################################
from optparse import OptionParser
import os import os
import sys import sys
from ubuntutools.lp.libsupport import get_launchpad from ubuntutools.lp.libsupport import get_launchpad
USAGE = "grab-attachments <bug numbers>" USAGE = "grab-attachments <bug numbers>"
def main(): def main():
if len(sys.argv) == 1: p = OptionParser('Usage: %prog [options] <bug numbers>')
print >> sys.stderr, USAGE opts, args = p.parse_args()
sys.exit(1) if len(args) < 1:
p.error('No bug numbers provided')
if sys.argv[1] in ["--help", "-h"]:
print USAGE
sys.exit(0)
try: try:
launchpad = get_launchpad("ubuntu-dev-tools") launchpad = get_launchpad("ubuntu-dev-tools")
for arg in sys.argv[1:]: for arg in args:
try: try:
number = int(arg) number = int(arg)
except: except:
print >> sys.stderr, "'%s' is not a valid bug number." % arg p.error("'%s' is not a valid bug number." % arg)
sys.exit(1)
b = launchpad.bugs[number] b = launchpad.bugs[number]