<s> import os <EOL> import shutil <EOL> import tempfile <EOL> from blueprint import util <EOL> class cd ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , new_cwd ) : <EOL> self . new_cwd = new_cwd <EOL> def __enter__ ( self ) : <EOL> self . old_cwd = os . getcwd ( ) <EOL> os . chdir ( self . new_cwd ) <EOL> return self <EOL> def __exit__ ( self , exc_type , exc_value , traceback ) : <EOL> os . chdir ( self . old_cwd ) <EOL> class mkdtemp ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , dir = None ) : <EOL> self . cwd = os . getcwd ( ) <EOL> if dir is None : <EOL> dir = tempfile . gettempdir ( ) <EOL> self . tempdir = tempfile . mkdtemp ( dir = dir ) <EOL> if util . via_sudo ( ) : <EOL> uid = int ( os . environ [ '<STR_LIT>' ] ) <EOL> gid = int ( os . environ [ '<STR_LIT>' ] ) <EOL> os . chown ( self . tempdir , uid , gid ) <EOL> def __enter__ ( self ) : <EOL> os . chdir ( self . tempdir ) <EOL> return self <EOL> def __exit__ ( self , exc_type , exc_value , traceback ) : <EOL> os . chdir ( self . cwd ) <EOL> shutil . rmtree ( self . tempdir ) </s>
