Commit 4d651c4d authored by aknecht2's avatar aknecht2
Browse files

Updated download util. Removed default username/password from tester.

parent 70423587
#!/usr/bin/python
import chipathlon
import chipathlon.utils
import argparse
parser = argparse.ArgumentParser(description="Download target file.")
......
......@@ -6,8 +6,8 @@ import chipathlon.workflow
import argparse
parser = argparse.ArgumentParser(description="Perform a join between the experiment and sample collections.")
parser.add_argument("--password", dest="password", default="nerpAusIrd)griUrlobIbfaifovript4", help="Database user password.")
parser.add_argument("--username", dest="username", default="aknecht", help="Database user.")
parser.add_argument("--password", dest="password", help="Database user password.")
parser.add_argument("--username", dest="username", help="Database user.")
parser.add_argument("--host", dest="host", default="hcc-anvil-175-9.unl.edu", help="Database host.")
args = parser.parse_args()
......
......@@ -17,10 +17,10 @@ def downloadFile(url, localpath, urltype="ftp://", retries=3, overwrite=False, c
success = False
if url[:7] == "http://":
urltype = ""
for i in range(0, retries):
print("Attempt #%s, downloading %s\n" % (i + 1, url))
try:
if not os.path.isfile(localpath) or overwrite:
if not os.path.isfile(localpath) or overwrite:
for i in range(0, retries):
print "Attempt #%s, downloading %s\n" % (i + 1, url)
try:
with open(localpath, "w") as fwh:
response = urllib2.urlopen(urltype + url)
data = response.read()
......@@ -28,19 +28,18 @@ def downloadFile(url, localpath, urltype="ftp://", retries=3, overwrite=False, c
if hashlib.md5(data).hexdigest() == md5:
fwh.write(data)
success = True
print("File saved successfully.\n")
print "File saved successfully.\n"
else:
print("MD5 mismatch. Retrying.\n")
print "MD5 mismatch (input=[%s], hexdigest=[%s]). Retrying.\n" % (md5, hashlib.md5(data).hexdigest())
else:
fwh.write(data)
success = True
print("File saved successfully.\n")
elif os.path.isfile(localpath) and not overwrite:
print("File already exists, skipping download.\n")
success = True
except Exception as e:
print(traceback.format_exc())
overwrite = True
if success:
return
print "File saved successfully.\n"
except Exception as e:
print(traceback.format_exc())
overwrite = True
if success:
return
else:
print "File already exists, skipping download.\n"
return
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment