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
def _runImpl(self): if not os.path.exists(self.targetWebRootPath): os.makedirs(self.targetWebRootPath) for staticPath in self.get('STATIC_PATHS', []): self._staticPaths.append(FileUtils.createPath( self.sourceWebRootPath, *staticPath.strip(u'/').split(u'/'))) #------------------------------------------------------------------------------------------- # COPY FILES # Copies files from the source folders to the target root folder, maintaining folder # structure in the process FileUtils.walkPath(self.sourceWebRootPath, self._copyWalker) #--- COMMON FILES ---# copies = [ (u'StaticFlow Javascript', 'web/js', 'js/sflow'), (u'StaticFlow CSS', 'web/css', 'css/sflow') ] for item in copies: source = FileUtils.createPath( StaticFlowEnvironment.rootResourcePath, *item[1].split('/'), isDir=True) target = FileUtils.createPath( self.targetWebRootPath, *item[2].split('/'), isDir=True) if os.path.exists(target): SystemUtils.remove(target) targetFolder = FileUtils.createPath(target, '..', isDir=True) if not os.path.exists(targetFolder): os.makedirs(targetFolder) fileList = FileUtils.mergeCopy(source, target) for path, data in fileList.files.iteritems(): SiteProcessUtils.copyToCdnFolder( path, self, FileUtils.getUTCModifiedDatetime(source)) self.writeLogSuccess(u'COPIED', u'%s | %s -> %s' % ( item[0], source.rstrip(os.sep), target.rstrip(os.sep) )) #------------------------------------------------------------------------------------------- # COMPILE # Compiles source files to the target root folder currentPath = os.curdir os.path.walk(self.sourceWebRootPath, self._compileWalker, None) os.chdir(currentPath) #------------------------------------------------------------------------------------------- # CREATE PAGE DEFS # Creates the page data files that define the pages to be generated os.path.walk(self.sourceWebRootPath, self._htmlDefinitionWalker, None) self._pages.process() self._sitemap.write() self._robots.write() for rssGenerator in self._rssGenerators: rssGenerator.write() self._writeGoogleFiles() #------------------------------------------------------------------------------------------- # CLEANUP # Removes temporary and excluded file types from the target root folder os.path.walk(self.targetWebRootPath, self._cleanupWalker, dict()) return True