示例#1
0
文件: Site.py 项目: sernst/StaticFlow
    def _copyWalker(self, walkData):
        staticFolder = False
        for folder in self._staticPaths:
            path = FileUtils.cleanupPath(walkData.folder, isDir=True)
            folder = FileUtils.cleanupPath(folder, isDir=True)
            if path == folder or FileUtils.isInFolder(path, folder):
                staticFolder = True
                break

        copiedNames = []
        for item in walkData.names:
            if not staticFolder and not StringUtils.ends(item, self._FILE_COPY_TYPES):
                continue

            sourcePath = FileUtils.createPath(walkData.folder, item)
            if os.path.isdir(sourcePath):
                continue

            destPath = FileUtils.changePathRoot(
                sourcePath, self.sourceWebRootPath, self.targetWebRootPath)

            try:
                FileUtils.getDirectoryOf(destPath, createIfMissing=True)
                shutil.copy(sourcePath, destPath)

                lastModified = FileUtils.getUTCModifiedDatetime(sourcePath)
                SiteProcessUtils.createHeaderFile(destPath, lastModified)
                SiteProcessUtils.copyToCdnFolder(destPath, self, lastModified)
                copiedNames.append(item)
            except Exception, err:
                self.writeLogError(u'Unable to copy file', error=err, extras={
                    'SOURCE':sourcePath,
                    'TARGET':destPath })
                return