@contextlib.contextmanager
def archive_context(filename):
 tmpdir = tempfile.mkdtemp()
 log.warn('Extracting in %s', tmpdir)
 old_wd = os.getcwd()
 try:
  os.chdir(tmpdir)
  with ContextualZipFile(filename) as archive:
   archive.extractall()
  subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
  os.chdir(subdir)
  log.warn('Now working in %s', subdir)
  (yield)
 finally:
  os.chdir(old_wd)
  shutil.rmtree(tmpdir)

@ contextlib . contextmanager def archive_context ( filename ) : tmpdir = tempfile . mkdtemp ( ) log . warn ( 'Extracting in %s' , tmpdir ) old_wd = os . getcwd ( ) try : os . chdir ( tmpdir ) with ContextualZipFile ( filename ) as archive : archive . extractall ( ) subdir = os . path . join ( tmpdir , os . listdir ( tmpdir ) [ 0 ] ) os . chdir ( subdir ) log . warn ( 'Now working in %s' , subdir ) ( yield ) finally : os . chdir ( old_wd ) shutil . rmtree ( tmpdir )
unzip filename to a temporary directory .