def unzip_archive(archive):
 assert os.path.exists(archive), ('File not found - %s' % archive)
 tmpdir = os.path.join(tempfile.gettempdir(), os.path.basename(archive))
 assert (tmpdir != archive)
 if os.path.exists(tmpdir):
  pass
 elif tarfile.is_tarfile(archive):
  print 'Extracting tarfile ...'
  with tarfile.open(archive) as tf:
   tf.extractall(path=tmpdir)
 elif zipfile.is_zipfile(archive):
  print 'Extracting zipfile ...'
  with zipfile.ZipFile(archive) as zf:
   zf.extractall(path=tmpdir)
 else:
  raise ValueError(('Unknown file type for %s' % os.path.basename(archive)))
 return tmpdir

def unzip_archive ( archive ) : assert os . path . exists ( archive ) , ( 'File not found - %s' % archive ) tmpdir = os . path . join ( tempfile . gettempdir ( ) , os . path . basename ( archive ) ) assert ( tmpdir != archive ) if os . path . exists ( tmpdir ) : pass elif tarfile . is_tarfile ( archive ) : print 'Extracting tarfile ...' with tarfile . open ( archive ) as tf : tf . extractall ( path = tmpdir ) elif zipfile . is_zipfile ( archive ) : print 'Extracting zipfile ...' with zipfile . ZipFile ( archive ) as zf : zf . extractall ( path = tmpdir ) else : raise ValueError ( ( 'Unknown file type for %s' % os . path . basename ( archive ) ) ) return tmpdir
unzips an archive into a temporary directory returns a link to that directory arguments: archive -- the path to an archive file .