parameters: (url, location, log = EmptyLogger())
return_statement: return possible
docstring: Downloads and unpacks a mingw-builds archive
docstring_summary: Downloads and unpacks a mingw-builds archive
docstring_tokens: Downloads and unpacks a mingw - builds archive
function: def download(url, location, log = EmptyLogger()):
      '''
      Downloads and unpacks a mingw-builds archive
      '''
      log.info('downloading MinGW')
      log.debug(' - url: %s', url)
      log.debug(' - location: %s', location)
  
      re_content = re.compile(r'attachment;[ \t]*filename=(")?([^"]*)(")?[\r\n]*')
  
      stream = request.urlopen(url)
      try:
          content = stream.getheader('Content-Disposition') or ''
      except AttributeError:
          content = stream.headers.getheader('Content-Disposition') or ''
      matches = re_content.match(content)
      if matches:
          filename = matches.group(2)
      else:
          parsed = parse.urlparse(stream.geturl())
          filename = os.path.basename(parsed.path)
  
      try:
          os.makedirs(location)
      except OSError as e:
          if e.errno == errno.EEXIST and os.path.isdir(location):
              pass
          else:
              raise
  
      archive = os.path.join(location, filename)
      with open(archive, 'wb') as out:
          while True:
              buf = stream.read(1024)
              if not buf:
                  break
              out.write(buf)
      unpack(archive, location, log = log)
      os.remove(archive)
  
      possible = os.path.join(location, 'mingw64')
      if not os.path.exists(possible):
          possible = os.path.join(location, 'mingw32')
          if not os.path.exists(possible):
              raise ValueError('Failed to find unpacked MinGW: ' + possible)
      return possible
function_tokens: def download ( url , location , log = EmptyLogger ( ) ) : log . info ( 'downloading MinGW' ) log . debug ( ' - url: %s' , url ) log . debug ( ' - location: %s' , location ) re_content = re . compile ( r'attachment;[ \t]*filename=(")?([^"]*)(")?[\r\n]*' ) stream = request . urlopen ( url ) try : content = stream . getheader ( 'Content-Disposition' ) or '' except AttributeError : content = stream . headers . getheader ( 'Content-Disposition' ) or '' matches = re_content . match ( content ) if matches : filename = matches . group ( 2 ) else : parsed = parse . urlparse ( stream . geturl ( ) ) filename = os . path . basename ( parsed . path ) try : os . makedirs ( location ) except OSError as e : if e . errno == errno . EEXIST and os . path . isdir ( location ) : pass else : raise archive = os . path . join ( location , filename ) with open ( archive , 'wb' ) as out : while True : buf = stream . read ( 1024 ) if not buf : break out . write ( buf ) unpack ( archive , location , log = log ) os . remove ( archive ) possible = os . path . join ( location , 'mingw64' ) if not os . path . exists ( possible ) : possible = os . path . join ( location , 'mingw32' ) if not os . path . exists ( possible ) : raise ValueError ( 'Failed to find unpacked MinGW: ' + possible ) return possible