Advertisement
QuarkDoe

SeaDAS 7.5 hotfix

Jan 21st, 2020
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.39 KB | None | 0 0
  1. diff --git a/modules/ProcUtils.py b/modules/ProcUtils.py
  2. index edceb41..7fb44f2 100644
  3. --- a/modules/ProcUtils.py
  4. +++ b/modules/ProcUtils.py
  5. @@ -6,7 +6,7 @@ SeaDAS library for commonly used functions within other python scripts
  6.  from __future__ import print_function
  7.  
  8.  import sys
  9. -
  10. +import requests
  11.  
  12.  #  ------------------ DANGER -------------------
  13.  #
  14. @@ -251,9 +251,50 @@ def _httpdl(url, request, localpath='.', outputfilename=None, ntries=5,
  15.  def httpdl(url, request, localpath='.', outputfilename=None, ntries=5,
  16.             uncompress=False, timeout=30., reqHeaders={}, verbose=False,
  17.             reuseConn=False, urlConn=None, chunk_size=DEFAULT_CHUNK_SIZE):
  18. -    urlConn, status = _httpdl(url, request, localpath, outputfilename, ntries,
  19. -                              uncompress, timeout, reqHeaders, verbose,
  20. -                              reuseConn, urlConn, chunk_size)
  21. +
  22. +    import requests
  23. +    import os
  24. +    import re
  25. +
  26. +    if not os.path.exists(localpath):
  27. +        os.umask(0o02)
  28. +        os.makedirs(localpath, mode=0o2775)
  29. +
  30. +    r = requests.get("https://%s%s" % (url,request), stream=True)
  31. +
  32. +    if r.status_code == 200 or r.status_code == 206:
  33. +
  34. +        if outputfilename:
  35. +            ofile = os.path.join(localpath, outputfilename)
  36. +        else:
  37. +            if 'content-disposition' in r.headers:
  38. +                ofile = os.path.join(localpath, r.headers.get('content-disposition').split('filename=')[1] )
  39. +            else:
  40. +                ofile = os.path.join(localpath, os.path.basename(request))
  41. +
  42. +        if r.status_code == 200:
  43. +            f = open(ofile, 'wb')
  44. +        else:
  45. +            f = open(ofile, 'ab')
  46. +
  47. +        for chunk in r.iter_content(chunk_size=chunk_size):
  48. +            if chunk: # filter out keep-alive new chunks
  49. +                f.write(chunk)
  50. +
  51. +        f.flush()
  52. +
  53. +        if re.search(".(Z|gz|bz2)$", ofile) and uncompress:
  54. +            compressStatus = uncompressFile(ofile)
  55. +            if compressStatus:
  56. +                status = compressStatus
  57. +        else:
  58. +            status = 0
  59. +    else:
  60. +        status = r.status_code
  61. +
  62. +#    urlConn, status = _httpdl(url, request, localpath, outputfilename, ntries,
  63. +#                              uncompress, timeout, reqHeaders, verbose,
  64. +#                              reuseConn, urlConn, chunk_size)
  65.      if reuseConn:
  66.          return (urlConn, status)
  67.      else:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement