Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Replace getopt with argparse
Browse files Browse the repository at this point in the history
  • Loading branch information
sdvcrx committed Mar 20, 2014
1 parent 396ff26 commit e115387
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions bddown_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import subprocess
import json
import getopt
import argparse
import logging
from time import time

Expand Down Expand Up @@ -162,15 +162,20 @@ class GetFilenameError(Exception):
def download(args):
limit = global_config.limit
output_dir = global_config.dir
secret = ""
optlist, links = getopt.getopt(args, 'lDS', ['limit=', 'dir=', 'secret='])
for k, v in optlist:
if k == '--limit':
limit = v
elif k == '--dir':
output_dir = os.path.expanduser(v)
elif k == '--secret':
secret = v
parser = argparse.ArgumentParser(description="download command arg parser")
parser.add_argument('-L', '--limit', action="store", dest='limit', help="Max download speed limit.")
parser.add_argument('-D', '--dir', action="store", dest='output_dir', help="Download task to dir.")
parser.add_argument('-S', '--secret', action="store", dest='secret', help="Retrieval password.", default="")
if not args:
parser.print_help()
exit(1)
namespace, links = parser.parse_known_args(args)
secret = namespace.secret
if namespace.limit:
limit = namespace.limit
if namespace.output_dir:
output_dir = namespace.output_dir

links = filter(check_url, links) # filter the wrong url
links = map(add_http, links) # add 'http://'
for url in links:
Expand Down

0 comments on commit e115387

Please sign in to comment.