Mercurial > repos > melissacline > ucsc_xena_platform
diff xenaGetDataset.py @ 52:bb840cc2603d
better error handling
author | jingchunzhu |
---|---|
date | Thu, 13 Aug 2015 17:30:19 -0700 |
parents | 3167c1a26101 |
children |
line wrap: on
line diff
--- a/xenaGetDataset.py Thu Aug 13 10:24:12 2015 -0700 +++ b/xenaGetDataset.py Thu Aug 13 17:30:19 2015 -0700 @@ -3,20 +3,25 @@ import argparse import re import urllib2 - +import sys def main(): - parser = argparse.ArgumentParser() - parser.add_argument("dataHub", type=str) - parser.add_argument("datasetId", type=str) - parser.add_argument("datafile", type=str) - args = parser.parse_args() + try: + parser = argparse.ArgumentParser() + parser.add_argument("dataHub", type=str) + parser.add_argument("datasetId", type=str) + parser.add_argument("datafile", type=str) + parser.add_argument("GALAXY_URL", type=str) + args = parser.parse_args() + except: + print "too few input parameters" + sys.exit(2) + data = open(args.datafile, "w") datasetUrlHost = re.sub("/proj/", "/download/", args.dataHub) datasetIdTokens = re.split("/", args.datasetId) datasetUrl = datasetUrlHost + "/" + "/".join(datasetIdTokens[1:]) - data = open(args.datafile, "w") try: dd = urllib2.urlopen(datasetUrl) @@ -24,8 +29,10 @@ dd.close() data.close() except: - data.wriet("You entered dataset id: %s\n" % (args.datasetId)) - data.write("Dataset does not exist. check typo.") + data.write("There is an error\n\n") + data.write("You entered dataset id: %s\n" % (args.datasetId)) + data.write("Possible causes for error:\n") + data.write("1. Dataset does not exist. check type.\n") data.close() sys.exit(1)