chrome/test/mini_installer/installer_test.py
def ConfigureTempOnDrive(drive):
    """Ensures that TMP is on |drive|, restoring state on completion.

    This does not change the current Python runtime's idea of tempdir.
    """
    tmp_set = False
    old_tmp = None
    tmp_created = None
    # Set TMP to something reasonable if the default temp path is not on the
    # desired drive. Note that os.environ is used to mutate the environment
    # since doing so writes through to the process's underlying environment
    # block. Reads are performed directly in the off chance that code elsewhere
    # has modified the environment without going through os.environ.
    temp = win32api.GetTempPath()
    if not temp or os.path.splitdrive(temp)[0] != drive:
        # Try to use one of the standard Temp dir locations.
        for candidate in [os.getenv(v) for v in ['LOCALAPPDATA', 'windir']]:
            if candidate and os.path.splitdrive(candidate)[0] == drive:
                temp = os.path.join(candidate, 'Temp')
                if os.path.isdir(temp):
                    old_tmp = os.getenv('TMP')
                    os.environ['TMP'] = temp
                    tmp_set = True
                    break
        # Otherwise make a Temp dir at the root of the drive.
        if not tmp_set:
            temp = os.path.join(drive, os.sep, 'Temp')
            if not os.path.exists(temp):
                os.mkdir(temp)
                tmp_created = temp
            elif not os.path.isdir(temp):
                raise Exception(
                    'Cannot create %s without clobbering something' % temp)
            old_tmp = os.getenv('TMP')
            os.environ['TMP'] = temp
            tmp_set = True
    try:
        yield
    finally:
        if tmp_set:
            if old_tmp is None:
                del os.environ['TMP']
            else:
                os.environ['TMP'] = old_tmp
        if tmp_created:
            shutil.rmtree(tmp_created, True)
            if os.path.isdir(tmp_created):
                raise Exception('Failed to entirely delete directory %s' %
                                tmp_created)
Ensures that TMP is on |drive|, restoring state on completion.

    This does not change the current Python runtime's idea of tempdir.
    
Ensures that TMP is on |drive|, restoring state on completion.
This does not change the current Python runtime's idea of tempdir.
Ensures that TMP is on |drive| restoring state on completion . This does not change the current Python runtime ' s idea of tempdir .
def ConfigureTempOnDrive(drive):
    tmp_set = False
    old_tmp = None
    tmp_created = None
    temp = win32api.GetTempPath()
    if not temp or os.path.splitdrive(temp)[0] != drive:
        for candidate in [os.getenv(v) for v in ['LOCALAPPDATA', 'windir']]:
            if candidate and os.path.splitdrive(candidate)[0] == drive:
                temp = os.path.join(candidate, 'Temp')
                if os.path.isdir(temp):
                    old_tmp = os.getenv('TMP')
                    os.environ['TMP'] = temp
                    tmp_set = True
                    break
        if not tmp_set:
            temp = os.path.join(drive, os.sep, 'Temp')
            if not os.path.exists(temp):
                os.mkdir(temp)
                tmp_created = temp
            elif not os.path.isdir(temp):
                raise Exception(
                    'Cannot create %s without clobbering something' % temp)
            old_tmp = os.getenv('TMP')
            os.environ['TMP'] = temp
            tmp_set = True
    try:
        yield
    finally:
        if tmp_set:
            if old_tmp is None:
                del os.environ['TMP']
            else:
                os.environ['TMP'] = old_tmp
        if tmp_created:
            shutil.rmtree(tmp_created, True)
            if os.path.isdir(tmp_created):
                raise Exception('Failed to entirely delete directory %s' %
                                tmp_created)
def ConfigureTempOnDrive ( drive ) : tmp_set = False old_tmp = None tmp_created = None temp = win32api . GetTempPath ( ) if not temp or os . path . splitdrive ( temp ) [ 0 ] != drive : for candidate in [ os . getenv ( v ) for v in [ 'LOCALAPPDATA' , 'windir' ] ] : if candidate and os . path . splitdrive ( candidate ) [ 0 ] == drive : temp = os . path . join ( candidate , 'Temp' ) if os . path . isdir ( temp ) : old_tmp = os . getenv ( 'TMP' ) os . environ [ 'TMP' ] = temp tmp_set = True break if not tmp_set : temp = os . path . join ( drive , os . sep , 'Temp' ) if not os . path . exists ( temp ) : os . mkdir ( temp ) tmp_created = temp elif not os . path . isdir ( temp ) : raise Exception ( 'Cannot create %s without clobbering something' % temp ) old_tmp = os . getenv ( 'TMP' ) os . environ [ 'TMP' ] = temp tmp_set = True try : yield finally : if tmp_set : if old_tmp is None : del os . environ [ 'TMP' ] else : os . environ [ 'TMP' ] = old_tmp if tmp_created : shutil . rmtree ( tmp_created , True ) if os . path . isdir ( tmp_created ) : raise Exception ( 'Failed to entirely delete directory %s' % tmp_created )
Ensures that TMP is on |drive|, restoring state on completion.
Ensures that TMP is on |drive| restoring state on completion .
"""Ensures that TMP is on |drive|, restoring state on completion.

    This does not change the current Python runtime's idea of tempdir.
    """ # Set TMP to something reasonable if the default temp path is not on the # desired drive. Note that os.environ is used to mutate the environment # since doing so writes through to the process's underlying environment # block. Reads are performed directly in the off chance that code elsewhere # has modified the environment without going through os.environ. # Try to use one of the standard Temp dir locations. # Otherwise make a Temp dir at the root of the drive.
drive