예제 #1
0
def newTempDir():
    """Generate a new temporary directory name, set it as the current Temp
    Dir."""
    global _tempDir
    from bolt import Path
    _tempDir = Path.tempDir()
    return _tempDir
예제 #2
0
파일: env.py 프로젝트: Skarfoze/wrye-bash
def shellMakeDirs(dirs, parent=None):
    if not dirs: return
    dirs = [dirs] if not isinstance(dirs, (list, tuple, set)) else dirs
    #--Skip dirs that already exist
    dirs = [x for x in dirs if not x.exists()]

    #--Check for dirs that are impossible to create (the drive they are
    #  supposed to be on doesn't exist
    def _filterUnixPaths(path):
        return _os.name != 'posix' and not path.s.startswith(u"\\")\
               and not path.drive().exists()

    errorPaths = [d for d in dirs if _filterUnixPaths(d)]
    if errorPaths:
        raise NonExistentDriveError(errorPaths)
    #--Checks complete, start working
    tempDirs, fromDirs, toDirs = [], [], []
    try:
        for folder in dirs:
            # Attempt creating the directory via normal methods, only fall back
            # to shellMove if UAC or something else stopped it
            try:
                folder.makedirs()
            except:
                # Failed, try the UAC workaround
                tmpDir = Path.tempDir()
                tempDirs.append(tmpDir)
                toMake = []
                toMakeAppend = toMake.append
                while not folder.exists() and folder != folder.head:
                    # Need to test against dir == dir.head to prevent
                    # infinite recursion if the final bit doesn't exist
                    toMakeAppend(folder.tail)
                    folder = folder.head
                if not toMake:
                    continue
                toMake.reverse()
                base = tmpDir.join(toMake[0])
                toDir = folder.join(toMake[0])
                tmpDir.join(*toMake).makedirs()
                fromDirs.append(base)
                toDirs.append(toDir)
        if fromDirs:
            # fromDirs will only get filled if folder.makedirs() failed
            shellMove(fromDirs, toDirs, parent=parent)
    finally:
        for tmpDir in tempDirs:
            tmpDir.rmtree(safety=tmpDir.stail)
예제 #3
0
파일: env.py 프로젝트: Skarfoze/wrye-bash
def testUAC(gameDataPath):
    if _os.name != 'nt':  # skip this when not in Windows
        return False
    print 'testing UAC'
    tmpDir = Path.tempDir()
    tempFile = tmpDir.join(u'_tempfile.tmp')
    dest = gameDataPath.join(u'_tempfile.tmp')
    with tempFile.open('wb'):
        pass  # create the file
    try:  # to move it into the Game/Data/ directory
        shellMove(tempFile, dest, silent=True)
    except AccessDeniedError:
        return True
    finally:
        shellDeletePass(tmpDir)
        shellDeletePass(dest)
    return False