Added docker windows container for dev
This commit is contained in:
@@ -99,7 +99,9 @@ class BotanClassResolver:
|
||||
|
||||
classMap = ""
|
||||
flagCompress = True
|
||||
oModeIfSizelt = 50 * 1024
|
||||
returnHash = False
|
||||
returnDynamic = False
|
||||
resv = None
|
||||
|
||||
def __init__( self, jwork, BotanRoot, classMap, cacheRoot ):
|
||||
@@ -122,12 +124,17 @@ class BotanClassResolver:
|
||||
|
||||
return content
|
||||
|
||||
def BotanCache( self, t ):
|
||||
content = ""
|
||||
with open( t, "r" ) as f:
|
||||
content = f.read()
|
||||
def BotanCache( self, srcFile, fileHash, hashContentDynamic ):
|
||||
|
||||
return content
|
||||
for _ in [0]:
|
||||
if hashContentDynamic and os.path.getsize( srcFile ) < self.oModeIfSizelt:
|
||||
break
|
||||
|
||||
if self.returnHash:
|
||||
return fileHash
|
||||
|
||||
with open( srcFile, "r" ) as f:
|
||||
return f.read()
|
||||
|
||||
def cleanList( self, lista ):
|
||||
olist = []
|
||||
@@ -196,7 +203,7 @@ class BotanClassResolver:
|
||||
dates.append( os.path.getmtime( os.path.join( self.R, "_this.js" ) ) );
|
||||
|
||||
if self.flagCompress and self.useCache( cFile, dates ):
|
||||
return cFHash if self.returnHash else self.BotanCache( cFile )
|
||||
return self.BotanCache( cFile, cFHash, self.returnDynamic )
|
||||
|
||||
elif self.useCache( oFile, dates ):
|
||||
self.JWork.saveCache(
|
||||
@@ -207,7 +214,7 @@ class BotanClassResolver:
|
||||
, os.path.join( self.R, "externs" )
|
||||
)
|
||||
|
||||
return oFHash if self.returnHash else self.BotanCache( oFile )
|
||||
return self.BotanCache( oFile, oFHash, False )
|
||||
|
||||
def useCache( self, f, dList ):
|
||||
if not os.path.exists( f ):
|
||||
@@ -248,7 +255,7 @@ class BotanClassResolver:
|
||||
|
||||
outputJs = wrapScope( outputJs )
|
||||
|
||||
[ self.JWork.saveCache if self.returnHash else self.JWork.saveCache ][0] (
|
||||
self.JWork.saveCache(
|
||||
os.path.join( self.CR, md5[0] )
|
||||
, outputJs
|
||||
, "js"
|
||||
@@ -283,9 +290,7 @@ class BotanClassResolver:
|
||||
for f in self.cleanList( cList ):
|
||||
outputCss += self.BotanFile( f )
|
||||
|
||||
[ self.JWork.saveCache if self.returnHash else self.JWork.saveCache ][0] (
|
||||
os.path.join( self.CR, md5[0] ), outputCss, "css"
|
||||
)
|
||||
self.JWork.saveCache( os.path.join( self.CR, md5[0] ), outputCss, "css" )
|
||||
|
||||
if self.returnHash:
|
||||
return md5[0]
|
||||
@@ -299,13 +304,26 @@ class BotanClassResolver:
|
||||
flag = mode[0]
|
||||
requestAPIs = code
|
||||
|
||||
# Return compressed contents if possible
|
||||
# otherwise return raw contents
|
||||
if flag == "o":
|
||||
mode = mode[1:]
|
||||
|
||||
# Return raw contents only
|
||||
elif flag == "r":
|
||||
mode = mode[1:]
|
||||
self.flagCompress = False
|
||||
|
||||
# Return hashed filenames only
|
||||
elif flag == "h":
|
||||
mode = mode[1:]
|
||||
self.returnHash = True
|
||||
|
||||
# Return hashed filenames if content is larger than self.oModeIfSizelt bytes
|
||||
# otherwise act as "o" mode
|
||||
else:
|
||||
self.returnHash = True
|
||||
self.returnDynamic = True
|
||||
|
||||
try:
|
||||
requestAPIs = (
|
||||
@@ -329,7 +347,8 @@ class BotanClassResolver:
|
||||
|
||||
for apis in requestAPIs:
|
||||
|
||||
if apis == None: continue
|
||||
if not apis:
|
||||
continue
|
||||
|
||||
classList = []
|
||||
lookupList = imports
|
||||
|
@@ -17,7 +17,7 @@ if CeleryExists:
|
||||
|
||||
if os.path.exists( "settings.ini" ):
|
||||
from botanjs.config import Config
|
||||
app.conf.update( BROKER_URL = Config["BotanJS"]["CeleryBroker"] )
|
||||
app.conf.update( broker_url = Config["BotanJS"]["CeleryBroker"] )
|
||||
|
||||
else:
|
||||
from botanjs.dummy import app
|
||||
@@ -34,7 +34,7 @@ class JWork:
|
||||
if mode == "js":
|
||||
JWork.compressJs.delay( location, externs )
|
||||
elif mode == "css":
|
||||
JWork.compressCss.delay( location )
|
||||
JWork.compressCss( location )
|
||||
|
||||
@app.task()
|
||||
def compressJs( md5, externs ):
|
||||
@@ -54,5 +54,6 @@ class JWork:
|
||||
log.info( "Building Class Map" )
|
||||
c = ClassMap( src )
|
||||
|
||||
os.makedirs( os.path.dirname( location ), exist_ok = True )
|
||||
with open( location, "w" ) as f:
|
||||
f.write( c.build() )
|
||||
|
@@ -23,9 +23,9 @@ class WebAPI:
|
||||
self.BMap = os.path.join( self.BCache, "bmap.xml" )
|
||||
|
||||
if brokerURL != None:
|
||||
CeleryApp.conf.update( BROKER_URL = brokerURL )
|
||||
CeleryApp.conf.update( broker_url = brokerURL )
|
||||
|
||||
self.app = Flask( __name__, static_url_path = self.BCache, static_folder = self.BCache )
|
||||
self.app = Flask( __name__, static_url_path = "/cache/botanjs", static_folder = self.BCache )
|
||||
self.app.jinja_env.add_extension( "compressinja.html.HtmlCompressor" )
|
||||
|
||||
self.app.add_url_rule( "/" , view_func = self.index )
|
||||
@@ -33,6 +33,7 @@ class WebAPI:
|
||||
self.app.add_url_rule( "/<mode>/<path:code>" , view_func = self.api_request )
|
||||
|
||||
def run( self, *args, **kwargs ):
|
||||
JWork.buildClassMap( self.BRoot, self.BMap )
|
||||
return self.app.run( *args, **kwargs )
|
||||
|
||||
def index( self ):
|
||||
@@ -40,6 +41,10 @@ class WebAPI:
|
||||
|
||||
def api_request( self, mode, code ):
|
||||
|
||||
if mode == "rebuild":
|
||||
JWork.buildClassMap.delay( self.BRoot, self.BMap )
|
||||
return "OK", 200
|
||||
|
||||
if code == "zpayload":
|
||||
code = request.args.get( "p" )
|
||||
|
||||
@@ -53,6 +58,8 @@ class WebAPI:
|
||||
srvHandler = JCResv( JWork, self.BRoot, self.BMap, self.BCache )
|
||||
return Response( srvHandler.getAPI( code, mode = mode ), mimetype = t )
|
||||
except Exception as e:
|
||||
if self.app.config[ "DEBUG" ]:
|
||||
raise
|
||||
return str(e), 404
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user