@contextlib.contextmanager
def temporary_chown(path, owner_uid=None):
 if (owner_uid is None):
  owner_uid = os.getuid()
 orig_uid = os.stat(path).st_uid
 if (orig_uid != owner_uid):
  execute('chown', owner_uid, path, run_as_root=True)
 try:
  (yield)
 finally:
  if (orig_uid != owner_uid):
   execute('chown', orig_uid, path, run_as_root=True)

@ contextlib . contextmanager def temporary_chown ( path , owner_uid = None ) : if ( owner_uid is None ) : owner_uid = os . getuid ( ) orig_uid = os . stat ( path ) . st_uid if ( orig_uid != owner_uid ) : execute ( 'chown' , owner_uid , path , run_as_root = True ) try : ( yield ) finally : if ( orig_uid != owner_uid ) : execute ( 'chown' , orig_uid , path , run_as_root = True )
temporarily chown a path .