Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/modules/ProcUtils.py b/modules/ProcUtils.py
- index edceb41..7fb44f2 100644
- --- a/modules/ProcUtils.py
- +++ b/modules/ProcUtils.py
- @@ -6,7 +6,7 @@ SeaDAS library for commonly used functions within other python scripts
- from __future__ import print_function
- import sys
- -
- +import requests
- # ------------------ DANGER -------------------
- #
- @@ -251,9 +251,50 @@ def _httpdl(url, request, localpath='.', outputfilename=None, ntries=5,
- def httpdl(url, request, localpath='.', outputfilename=None, ntries=5,
- uncompress=False, timeout=30., reqHeaders={}, verbose=False,
- reuseConn=False, urlConn=None, chunk_size=DEFAULT_CHUNK_SIZE):
- - urlConn, status = _httpdl(url, request, localpath, outputfilename, ntries,
- - uncompress, timeout, reqHeaders, verbose,
- - reuseConn, urlConn, chunk_size)
- +
- + import requests
- + import os
- + import re
- +
- + if not os.path.exists(localpath):
- + os.umask(0o02)
- + os.makedirs(localpath, mode=0o2775)
- +
- + r = requests.get("https://%s%s" % (url,request), stream=True)
- +
- + if r.status_code == 200 or r.status_code == 206:
- +
- + if outputfilename:
- + ofile = os.path.join(localpath, outputfilename)
- + else:
- + if 'content-disposition' in r.headers:
- + ofile = os.path.join(localpath, r.headers.get('content-disposition').split('filename=')[1] )
- + else:
- + ofile = os.path.join(localpath, os.path.basename(request))
- +
- + if r.status_code == 200:
- + f = open(ofile, 'wb')
- + else:
- + f = open(ofile, 'ab')
- +
- + for chunk in r.iter_content(chunk_size=chunk_size):
- + if chunk: # filter out keep-alive new chunks
- + f.write(chunk)
- +
- + f.flush()
- +
- + if re.search(".(Z|gz|bz2)$", ofile) and uncompress:
- + compressStatus = uncompressFile(ofile)
- + if compressStatus:
- + status = compressStatus
- + else:
- + status = 0
- + else:
- + status = r.status_code
- +
- +# urlConn, status = _httpdl(url, request, localpath, outputfilename, ntries,
- +# uncompress, timeout, reqHeaders, verbose,
- +# reuseConn, urlConn, chunk_size)
- if reuseConn:
- return (urlConn, status)
- else:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement