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 _compileWalker(self, args, path, names): for name in names: namePath = FileUtils.createPath(path, name, isFile=True) if name.endswith('.coffee'): SiteProcessUtils.compileCoffeescript(self, namePath) elif name.endswith('.css'): SiteProcessUtils.compileCss(self, namePath)
def _writeGoogleFiles(self): vid = self.get(('GOOGLE', 'SITE_VERIFY_ID')) if not vid: return False if not vid.endswith('.html'): vid += '.html' path = FileUtils.createPath(self.targetWebRootPath, vid, isFile=True) FileUtils.putContents(u'google-site-verification: ' + vid, path) SiteProcessUtils.createHeaderFile(path, None) return True
def _createLoaderJs(self): """Doc...""" result = SiteProcessUtils.compileCoffeescriptFile( FileUtils.createPath( StaticFlowEnvironment.rootResourcePath, '..', 'js', 'loader.coffee', isFile=True), FileUtils.createPath( StaticFlowEnvironment.rootResourcePath, 'web', 'js', isDir=True) ) if result['code']: print 'ERROR: Failed to compile loader.coffee' print result return False print u'COMPILED: loader.js' return True
def _createEngineJs(self): cb = CoffeescriptBuilder( 'sflow.api.SFlowApi-exec', FileUtils.createPath(StaticFlowEnvironment.rootResourcePath, '..', 'js', isDir=True), buildOnly=True) target = cb.construct()[0] targetFolder = FileUtils.createPath( StaticFlowEnvironment.rootResourcePath, 'web', 'js', isDir=True) result = SiteProcessUtils.compileCoffeescriptFile(target.assembledPath, targetFolder) if result['code']: print 'ERROR: Failed compilation of the Static Flow engine' print result return False sourcePath = FileUtils.createPath(targetFolder, target.name + '.js', isFile=True) destPath = FileUtils.createPath(targetFolder, 'engine.js', isFile=True) SystemUtils.move(sourcePath, destPath) return True
def _processFolderDefinitions(self, path): cd = ConfigsDict(JSON.fromFile(path)) directory = FileUtils.getDirectoryOf(path) for item in os.listdir(directory): # Only find content source file types if not StringUtils.ends(item, ('.sfml', '.html')): continue # Skip files that already have a definitions file itemPath = FileUtils.createPath(directory, item, isFile=True) itemDefsPath = itemPath.rsplit('.', 1)[0] + '.def' if os.path.exists(itemDefsPath): continue test = SiteProcessUtils.testFileFilter( itemPath, cd.get(('FOLDER', 'EXTENSION_FILTER')), cd.get(('FOLDER', 'NAME_FILTER'))) if not test: continue JSON.toFile(itemDefsPath, dict(), pretty=True) return True
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
def targetUrl(self): domain = self.site.get('DOMAIN', None) if not domain: return u'' return SiteProcessUtils.getUrlFromPath(self.site, domain, self.targetPath)
def targetUrl(self): """ The URL of the sitemap formatted in accordance with the type of site deployment """ domain = self.site.get('DOMAIN', None) if not domain: return u'' return SiteProcessUtils.getUrlFromPath(self.site, domain, self.targetPath)