forked from Botanical/BotanJS
Better caching mechanics
This commit is contained in:
@@ -30,7 +30,11 @@ class Resolver:
|
||||
|
||||
def resource( self, elem ):
|
||||
if "src" in elem.attrib:
|
||||
return elem.attrib[ "src" ]
|
||||
return {
|
||||
"src": elem.attrib[ "src" ]
|
||||
, "js": elem.attrib[ "js" ]
|
||||
, "css": elem.attrib[ "css" ]
|
||||
}
|
||||
|
||||
parent = self.parentMap[ elem ]
|
||||
|
||||
@@ -153,9 +157,10 @@ class BotanClassResolver:
|
||||
if src not in classFiles:
|
||||
classFiles.append( src )
|
||||
|
||||
def cssLookup( self, jsList, cssList ):
|
||||
def cssLookup( self, classList, cssList ):
|
||||
|
||||
for f in jsList:
|
||||
for cdef in classList:
|
||||
f = cdef[ "src" ]
|
||||
possibleList = []
|
||||
|
||||
cssFile = os.path.splitext( f )[0] + ".css"
|
||||
@@ -183,7 +188,7 @@ class BotanClassResolver:
|
||||
if self.CR == None:
|
||||
return None
|
||||
|
||||
md5 = hashlib.md5( bytearray( "".join( fileList ), "utf-8" ) ).hexdigest()
|
||||
md5 = hashlib.md5( bytearray( "|".join( x[mode] for x in fileList ), "utf-8" ) ).hexdigest()
|
||||
|
||||
cName[0] = oFHash = md5 + "." + mode
|
||||
cFHash = md5 + ".c." + mode
|
||||
@@ -193,19 +198,10 @@ class BotanClassResolver:
|
||||
# Compressed file
|
||||
cFile = os.path.join( self.CR, cFHash )
|
||||
|
||||
dates = list(
|
||||
os.path.getmtime( os.path.join( self.R, x ) )
|
||||
if os.path.exists( os.path.join( self.R, x ) ) else -1
|
||||
for x in fileList
|
||||
)
|
||||
|
||||
# Root file date
|
||||
dates.append( os.path.getmtime( os.path.join( self.R, "_this.js" ) ) );
|
||||
|
||||
if self.flagCompress and self.useCache( cFile, dates ):
|
||||
if self.flagCompress and self.useCache( cFile ):
|
||||
return self.BotanCache( cFile, cFHash, self.returnDynamic )
|
||||
|
||||
elif self.useCache( oFile, dates ):
|
||||
elif self.useCache( oFile ):
|
||||
self.JWork.saveCache(
|
||||
oFile
|
||||
# Content is None to initiate a compression
|
||||
@@ -216,17 +212,8 @@ class BotanClassResolver:
|
||||
|
||||
return self.BotanCache( oFile, oFHash, False )
|
||||
|
||||
def useCache( self, f, dList ):
|
||||
if not os.path.exists( f ):
|
||||
return False
|
||||
|
||||
t = os.path.getmtime( f )
|
||||
|
||||
for i in dList:
|
||||
if t < i:
|
||||
return False
|
||||
|
||||
return True
|
||||
def useCache( self, f ):
|
||||
return os.path.exists( f )
|
||||
|
||||
def compileJs( self, cList, xList ):
|
||||
md5 = [ None ]
|
||||
@@ -244,6 +231,7 @@ class BotanClassResolver:
|
||||
|
||||
|
||||
for f in cList:
|
||||
f = f[ "src" ]
|
||||
path = (
|
||||
os.path.splitext( f )[0]
|
||||
.replace( PY_SEP, "." )
|
||||
@@ -285,8 +273,8 @@ class BotanClassResolver:
|
||||
if cacheFile != None:
|
||||
return cacheFile;
|
||||
|
||||
# The root file
|
||||
outputCss = self.BotanFile( "_this.css" )
|
||||
struct = "/* @ */"
|
||||
outputCss = struct + self.BotanFile( "_this.css" )
|
||||
|
||||
for f in self.cleanList( cList ):
|
||||
outputCss += self.BotanFile( f )
|
||||
|
@@ -1,7 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
from botanjs.compressor.closure import Wrapper as ClosureWrapper
|
||||
from botanjs.compressor.yui import Wrapper as YUIWrapper
|
||||
from botanjs.classmap import ClassMap
|
||||
|
||||
CeleryExists = True
|
||||
@@ -38,6 +36,7 @@ class JWork:
|
||||
|
||||
@app.task()
|
||||
def compressJs( md5, externs ):
|
||||
from botanjs.compressor.closure import Wrapper as ClosureWrapper
|
||||
log.info( "Compress js: " + md5 )
|
||||
w = ClosureWrapper()
|
||||
w.scanExterns( externs )
|
||||
@@ -45,6 +44,7 @@ class JWork:
|
||||
|
||||
@app.task()
|
||||
def compressCss( md5 ):
|
||||
from botanjs.compressor.yui import Wrapper as YUIWrapper
|
||||
log.info( "Compress css: " + md5 )
|
||||
w = YUIWrapper()
|
||||
w.compress( md5 )
|
||||
|
Reference in New Issue
Block a user