def download_and_unzip_files(source_url, target_parent_dir, zip_root_name, target_root_name):
 if (not os.path.exists(os.path.join(target_parent_dir, target_root_name))):
  print ('Downloading and unzipping file %s to %s' % (zip_root_name, target_parent_dir))
  common.ensure_directory_exists(target_parent_dir)
  urllib.urlretrieve(source_url, TMP_UNZIP_PATH)
  try:
   with zipfile.ZipFile(TMP_UNZIP_PATH, 'r') as zfile:
    zfile.extractall(target_parent_dir)
   os.remove(TMP_UNZIP_PATH)
  except Exception:
   if os.path.exists(TMP_UNZIP_PATH):
    os.remove(TMP_UNZIP_PATH)
   req = urllib2.Request(source_url)
   req.add_header('User-agent', 'python')
   file_stream = StringIO.StringIO(urllib2.urlopen(req).read())
   with zipfile.ZipFile(file_stream, 'r') as zfile:
    zfile.extractall(target_parent_dir)
  os.rename(os.path.join(target_parent_dir, zip_root_name), os.path.join(target_parent_dir, target_root_name))

def download_and_unzip_files ( source_url , target_parent_dir , zip_root_name , target_root_name ) : if ( not os . path . exists ( os . path . join ( target_parent_dir , target_root_name ) ) ) : print ( 'Downloading and unzipping file %s to %s' % ( zip_root_name , target_parent_dir ) ) common . ensure_directory_exists ( target_parent_dir ) urllib . urlretrieve ( source_url , TMP_UNZIP_PATH ) try : with zipfile . ZipFile ( TMP_UNZIP_PATH , 'r' ) as zfile : zfile . extractall ( target_parent_dir ) os . remove ( TMP_UNZIP_PATH ) except Exception : if os . path . exists ( TMP_UNZIP_PATH ) : os . remove ( TMP_UNZIP_PATH ) req = urllib2 . Request ( source_url ) req . add_header ( 'User-agent' , 'python' ) file_stream = StringIO . StringIO ( urllib2 . urlopen ( req ) . read ( ) ) with zipfile . ZipFile ( file_stream , 'r' ) as zfile : zfile . extractall ( target_parent_dir ) os . rename ( os . path . join ( target_parent_dir , zip_root_name ) , os . path . join ( target_parent_dir , target_root_name ) )
downloads a zip file .