Exemplo n.º 1
0
def normBinaryName(path, isPathPreserved=False, isGui=False):
    if path is None: return None
    if not isPathPreserved: path = fileBaseName(path)
    base, ext = splitExt(path)
    if IS_MACOS and isGui:
        return "%s%s" % (base, _MACOS_APP_EXT)
    if IS_WINDOWS: return base + (".exe" if ext == "" else ext)
    return base
Exemplo n.º 2
0
def normIconName(path, isPathPreserved=False):
    if path is None: return None
    if not isPathPreserved: path = fileBaseName(path)
    base, _ = splitExt(path)
    if IS_WINDOWS: return "%s%s" % (base, _WINDOWS_ICON_EXT)
    elif IS_MACOS: return "%s%s" % (base, _MACOS_ICON_EXT)
    elif IS_LINUX: return "%s%s" % (base, _LINUX_ICON_EXT)
    raise Exception(__NOT_SUPPORTED_MSG)
    return base
Exemplo n.º 3
0
def __moveToDir(srcPath, destDirPath):
    """ Moves 1 item (recursively) """
    srcPath = absPath(srcPath)
    destDirPath = absPath(destDirPath)
    srcTail = fileBaseName(normpath(srcPath))
    destPath = joinPath(destDirPath, srcTail)
    if srcPath == destPath: return
    __removeFromDir(srcTail, destDirPath)
    if not isDir(destDirPath): makeDir(destDirPath)
    move(srcPath, destDirPath)
    print('Moved "%s" to "%s"' % (srcPath, destPath))
    return destPath
Exemplo n.º 4
0
def __copyToDir(srcPath, destDirPath):
    """ Copies 1 item (recursively) """
    srcPath = absPath(srcPath)
    destDirPath = absPath(destDirPath)
    srcTail = fileBaseName(normpath(srcPath))
    destPath = joinPath(destDirPath, srcTail)
    if srcPath == destPath: return
    __removeFromDir(srcTail, destDirPath)
    if isFile(srcPath): copyFile(srcPath, destPath)
    elif isDir(srcPath): copyDir(srcPath, destPath)
    print('Copied "%s" to "%s"' % (srcPath, destPath))
    return destPath
Exemplo n.º 5
0
    def _macMountDmg(dmgPath):
        def _toRet(isNew, mountPath, appPath, binPath):
            return (isNew, mountPath, appPath if isFile(appPath) else None,
                    binPath if isFile(binPath) else None)

        #example mount path:
        #   /Volumes/QtInstallerFramework-mac-x64/QtInstallerFramework-mac-x64.app/Contents/MacOS/QtInstallerFramework-mac-x64
        dmgBaseName = splitExt(fileBaseName(dmgPath))[0]
        mountPath = joinPath(PATH_DELIM, joinPath("Volumes", dmgBaseName))
        appPath = joinPath(mountPath, "%s.app" % (dmgBaseName, ))
        binPath = __INTERNAL_MACOS_APP_BINARY_TMPLT % (
            normBinaryName(appPath, isPathPreserved=True, isGui=True),
            normBinaryName(appPath, isPathPreserved=False, isGui=False))
        if isDir(mountPath):
            return _toRet(False, mountPath, appPath, binPath)
        _system('hdiutil mount "%s"' % (dmgPath, ))
        if isDir(mountPath):
            return _toRet(True, mountPath, appPath, binPath)
        raise Exception("Failed to mount %s to %s" % (dmgPath, mountPath))
Exemplo n.º 6
0
def toZipFile(sourceDir,
              zipDest=None,
              removeScr=True,
              isWrapperDirIncluded=False):
    sourceDir = absPath(sourceDir)
    if zipDest is None:
        zipDest = sourceDir  # make_archive adds extension
    else:
        if isFile(zipDest): removeFile(zipDest)
        zipDest, _ = splitExt(zipDest)
    if isWrapperDirIncluded:
        filePath = make_archive(zipDest, 'zip', dirPath(sourceDir),
                                fileBaseName(sourceDir))
    else:
        filePath = make_archive(zipDest, 'zip', sourceDir)
    print('Created zip file: "%s"' % (filePath, ))
    if removeScr:
        removeDir(sourceDir)
        print('Removed directory: "%s"' % (sourceDir, ))
    return filePath
Exemplo n.º 7
0
def download(url, saveToPath=None, preserveName=True):
    print("Downloading: %s..." % (url, ))
    download._priorPct = 0

    def __ondownLoadProgress(blockCount, blockSize, fileSize):
        if fileSize != -1:
            pct = int(100 * ((blockCount * blockSize) / fileSize))
            if pct - download._priorPct >= 10:
                download._priorPct = pct
                stdout.write("Done!\n" if pct ==
                             100 else "{0}%...".format(pct))
                stdout.flush()

    if saveToPath is None and preserveName:
        downloadDir = tempDirPath()
        downloadName = fileBaseName(urllib.parse.urlsplit(url)[2])
        removeFromDir(downloadName, downloadDir)
        saveToPath = joinPath(downloadDir, downloadName)
    localPath, _ = urllib.request.urlretrieve(url, saveToPath,
                                              __ondownLoadProgress)
    print("Saved to: %s" % (localPath, ))
    return localPath
Exemplo n.º 8
0
def rootFileName(path):
    if path is None: return None
    return splitExt(fileBaseName(path))[0]