def compileTemplateToJava(src, package): types, params, content = compileTemplateInner(src); className = src[src.rfind("/")+1:]; className = className[0].upper() + className[1:]; packagePath = javaTmpltDir; packageName = "templates"; if not bash.exists(packagePath): bash.mkdir(packagePath); for pack in package: packagePath += "/"+pack; packageName += "."+pack; if not bash.exists(packagePath): bash.mkdir(packagePath); outfil = bash.writefile(packagePath + "/" + className + ".java"); outfil.write( "package "+packageName+";\n\n"+ "public class "+className+" {\n"+ "\tpublic static String run("); for i in xrange(0, len(types)): if i > 0: outfil.write(", "); outfil.write(("Object" if types[i] == None else types[i]) + " " + params[i]); outfil.write(") {\n\t\treturn\t"+content+";\n\t}\n}"); outfil.close();
def compileTemplate(src, dest, package=[]): print "Compiling template \""+src+"\"..."; #Preprocess content = "\"" + bash.readfile(src+tmpltExt).read().strip( ).replace( "\\", "\\\\" ).replace( "\t", "\\t" ).replace( "\r", "" ).replace( "\f", "\\f" ).replace( "\'", "\\\'" ).replace( "\"", "\\\"" ).replace( "\n", "\"+\n\t\t\t\"" ) + "\""; varName = src[src.rfind("/")+1:]; varName = varName[0].lower() + varName[1:]; #Output outfil = bash.writefile(dest); outfil.write("var templates = templates || {};\n") packageName = "templates"; for pack in package: packageName += "."+pack; outfil.write(packageName + " = " + packageName + " || {};\n"); outfil.write(packageName + "." + varName + " = " + content + ";") outfil.close();
def run(path, consts, funs): if bash.isdir(path): for fil in bash.ls(path): run(path + "/" + fil, consts, funs) else: content = runOnFile(path, consts, funs) outfil = bash.writefile(path) outfil.write(content) outfil.close()
def run(path, consts, funs): if bash.isdir(path): for fil in bash.ls(path): run(path+"/"+fil, consts, funs); else: content = runOnFile(path, consts, funs); outfil = bash.writefile(path); outfil.write(content); outfil.close();
def compileTemplateToJS(src, dest, package=[]): types, params, content = compileTemplateInner(src); funName = src[src.rfind("/")+1:]; funName = funName[0].lower() + funName[1:]; outfil = bash.writefile(dest); outfil.write("var templates = templates || {};\n") packageName = "templates"; for pack in package: packageName += "."+pack; outfil.write(packageName + " = " + packageName + " || {};\n"); outfil.write( packageName+"."+funName+" = function(" + ", ".join(params) + ") {\n" + "\treturn\t"+content+";\n};") outfil.close();
def compileTemplateToJS(src, dest, package=[]): types, params, content = compileTemplateInner(src) funName = src[src.rfind("/") + 1:] funName = funName[0].lower() + funName[1:] outfil = bash.writefile(dest) outfil.write("var templates = templates || {};\n") packageName = "templates" for pack in package: packageName += "." + pack outfil.write(packageName + " = " + packageName + " || {};\n") outfil.write(packageName + "." + funName + " = function(" + ", ".join(params) + ") {\n" + "\treturn\t" + content + ";\n};") outfil.close()
def compileTemplate(src, dest, package=[]): print "Compiling template \"" + src + "\"..." #Preprocess content = "\"" + bash.readfile(src + tmpltExt).read().strip().replace( "\\", "\\\\").replace("\t", "\\t").replace("\r", "").replace( "\f", "\\f").replace("\'", "\\\'").replace("\"", "\\\"").replace( "\n", "\"+\n\t\t\t\"") + "\"" varName = src[src.rfind("/") + 1:] varName = varName[0].lower() + varName[1:] #Output outfil = bash.writefile(dest) outfil.write("var templates = templates || {};\n") packageName = "templates" for pack in package: packageName += "." + pack outfil.write(packageName + " = " + packageName + " || {};\n") outfil.write(packageName + "." + varName + " = " + content + ";") outfil.close()
def compileTemplateToJava(src, package): types, params, content = compileTemplateInner(src) className = src[src.rfind("/") + 1:] className = className[0].upper() + className[1:] packagePath = javaTmpltDir packageName = "templates" if not bash.exists(packagePath): bash.mkdir(packagePath) for pack in package: packagePath += "/" + pack packageName += "." + pack if not bash.exists(packagePath): bash.mkdir(packagePath) outfil = bash.writefile(packagePath + "/" + className + ".java") outfil.write("package " + packageName + ";\n\n" + "public class " + className + " {\n" + "\tpublic static String run(") for i in xrange(0, len(types)): if i > 0: outfil.write(", ") outfil.write(("Object" if types[i] == None else types[i]) + " " + params[i]) outfil.write(") {\n\t\treturn\t" + content + ";\n\t}\n}") outfil.close()
def transferLeaf(src, dest, plat, debug, mVars, mFuns, parents, merge): if merge: assert(len(parents) > 0); isDir = bash.isdir(src) wantsMacros = not (isDir and (os.path.basename(src) in noTemplating)); ext = src[src.rfind("/_")+2:] if isDir else src[src.rfind(".")+1:]; outPath = dest+("/"+ext if isDir else ""); for parent in parents: if not bash.exists(outPath): bash.mkdir(outPath); outPath += "/" + parent; if not merge and not bash.exists(outPath): bash.mkdir(outPath); if isDir: # Get list of files to transfer baseFolders = ["", "/_"+plat] + (["/"+debugFolder, "/_"+plat+"/"+debugFolder] if debug else []); # Actually transfer if merge: ofpath = outPath+"."+ext; outfil = bash.writefile(ofpath); i = 0; while i < len(baseFolders): baseFolder = src+baseFolders[i]; if bash.exists(baseFolder): fils = bash.ls(baseFolder); oFil = baseFolder+"/"+orderFile; if bash.exists(oFil): oFilReader = bash.readfile(oFil); o = oFilReader.read().strip().split(); oFilReader.close(); fils = o+list(set(fils).difference(o)); for fil in fils: fname = baseFolder+"/"+fil; if bash.isdir(fname): if fil[0] != '_': baseFolders.insert(i+1, fname[len(src):]); elif fil.endswith("."+ext): infil = bash.readfile(fname); outfil.write(infil.read()+"\n"); infil.close() i += 1; outfil.close(); if wantsMacros: macros.run(ofpath, mVars, mFuns); if ext == "js" and not debug: print "\tCompressing \""+ofpath+"\"..." bash.compressJS(ofpath, (plat != webPlat)); else: for baseFolder in baseFolders: baseFolder = src+baseFolder; if bash.exists(baseFolder): for fil in bash.ls(baseFolder): fname = baseFolder+"/"+fil; if fil[0] != '_' or not bash.isdir(fname): oPath = outPath+"/"+fil; bash.cp_r(fname, oPath); if wantsMacros: macros.run(oPath, mVars, mFuns); else: oPath = outPath + ("."+ext if merge else ""); bash.cp_r(src, oPath); if wantsMacros: macros.run(oPath, mVars, mFuns);
def makeWebXML(src, dest): print "Building web.xml..." infil = bash.readfile(src); outfl = bash.writefile(dest); outfl.write("<?xml version=\"1.0\" encoding=\"UTF-8\" "+ "standalone=\"no\"?><web-app "+ "xmlns=\"http://java.sun.com/xml/ns/javaee\" "+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+ "version=\"2.5\" "+ "xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee"+ " "+ "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\">\n" + "\n" + "\t<!-- Custom MIME types -->\n" + "\t<mime-mapping>\n" + "\t\t<extension>woff</extension>\n" + "\t\t<mime-type>font/opentype</mime-type>\n" + "\t</mime-mapping>\n" + "\n" + "\t<!-- Google Endpoint API Stuff -->\n" + "\t<servlet>\n" + "\t\t<servlet-name>SystemServiceServlet</servlet-name>\n" + "\t\t<servlet-class>" + "com.google.api.server.spi.SystemServiceServlet" + "</servlet-class>\n" + "\t\t<init-param>\n" + "\t\t\t<param-name>services</param-name>\n" + "\t\t\t<param-value/>\n" + "\t\t</init-param>\n" + "\t</servlet>\n" + "\t<servlet-mapping>\n" + "\t\t<servlet-name>SystemServiceServlet</servlet-name>\n" + "\t\t<url-pattern>/_ah/spi/*</url-pattern>\n" + "\t</servlet-mapping>\n" + "\n" + "\t<!-- - - - - - - - - - - - - - - - - - -->\n" + "\t<!-- Servlets (mostly) -->\n" + "\t<!-- - - - - - - - - - - - - - - - - - -->\n\n"); prefix = "servlets" usedServlets = set([]); for line in infil: if "," in line: elems = line.split(",") assert(len(elems) > 1); fname = elems[0] if fname.startswith("."): fname = prefix + fname url = elems[1].strip().rstrip("/"); isJSP = "JSP" in fname.upper(); tagName = "jsp-file" if isJSP else "servlet-class"; servlet = None; if len(elems) < 3: if isJSP: servlet = re.sub(r'^.*\/(.*)\.jsp$', r'\1Servlet', fname) else: servlet = re.sub(r'^.*\.(.*)$', r'\1', fname); servlet = servlet[0].lower() + servlet[1:]; if servlet in usedServlets: i = 0; while (servlet+"_"+str(i)) in usedServlets: i += 1; servlet += "_"+str(i); usedServlets.add(servlet); else: servlet = elems[2].strip(); outfl.write("\t<servlet>\n" + "\t\t<servlet-name>"+servlet+"</servlet-name>\n" + "\t\t<"+tagName+">"+fname+"</"+tagName+">\n" + "\t</servlet>\n" + "\t<servlet-mapping>\n" + "\t\t<servlet-name>"+servlet+"</servlet-name>\n" + "\t\t<url-pattern>"+url+"</url-pattern>\n" + "\t</servlet-mapping>\n" + "\t<servlet-mapping>\n" + "\t\t<servlet-name>"+servlet+"</servlet-name>\n" + "\t\t<url-pattern>"+url+"/</url-pattern>\n" + "\t</servlet-mapping>\n"); else: line = line.strip() if line.startswith("WELCOME:"): line = line[8:].strip(); outfl.write("\t<!-- Default page to serve -->\n" + "\t<welcome-file-list>\n" + "\t\t<welcome-file>"+line+"</welcome-file>\n" + "\t</welcome-file-list>\n" + "\n") elif len(line) > 0: outfl.write("\n\t<!-- "+line+" -->\n"); prefix = "servlets."+ re.sub(r' ', r'_', re.sub(r'\s*-\s+', r'.', line.lower())) outfl.write("</web-app>") outfl.close(); infil.close();
for i in xrange(0, len(platforms)): if bash.exists(platformPaths[i]): clearFolder(platformPaths[i], "server/protected_war.csv" if i == 0 else None) else: bash.mkdir(platformPaths[i]) plat = platforms[i]; native = plat != webPlat; path = platformPaths[i]; mVars['PLATFORM'] = plat; mVars['NATIVE'] = "true" if native else "false"; mVars['SERVER'] = server if native else ""; mVars['MODERN'] = "true" if (native or mVars['TEST'] == "true") else "false"; transferFls(tmpFolder, path, plat, debug, mVars, mFuns, uSet if i == 0 else projectsForApp); # Download channel API if native: apiPath = "_ah/channel/jsapi"; bash.mkdir(os.path.join(path, "_ah")); bash.mkdir(os.path.join(path, "_ah/channel")); content = urllib2.urlopen( os.path.join(server, apiPath) if local else "https://talkgadget.google.com/talkgadget/channel.js" ).read(); apiFile = bash.writefile(os.path.join(path, apiPath)); apiFile.write(re.sub(r'/_ah', os.path.join(server, "_ah"), content)); apiFile.close(); bash.rm_r(tmpFolder);
def transferLeaf(src, dest, plat, debug, mVars, mFuns, parents, merge): if merge: assert (len(parents) > 0) isDir = bash.isdir(src) wantsMacros = not (isDir and (os.path.basename(src) in noTemplating)) ext = src[src.rfind("/_") + 2:] if isDir else src[src.rfind(".") + 1:] outPath = dest + ("/" + ext if isDir else "") for parent in parents: if not bash.exists(outPath): bash.mkdir(outPath) outPath += "/" + parent if not merge and not bash.exists(outPath): bash.mkdir(outPath) if isDir: # Get list of files to transfer baseFolders = ["", "/_" + plat] + ( ["/" + debugFolder, "/_" + plat + "/" + debugFolder] if debug else []) # Actually transfer if merge: ofpath = outPath + "." + ext outfil = bash.writefile(ofpath) i = 0 while i < len(baseFolders): baseFolder = src + baseFolders[i] if bash.exists(baseFolder): fils = bash.ls(baseFolder) oFil = baseFolder + "/" + orderFile if bash.exists(oFil): oFilReader = bash.readfile(oFil) o = oFilReader.read().strip().split() oFilReader.close() fils = o + list(set(fils).difference(o)) for fil in fils: fname = baseFolder + "/" + fil if bash.isdir(fname): if fil[0] != '_': baseFolders.insert(i + 1, fname[len(src):]) elif fil.endswith("." + ext): infil = bash.readfile(fname) outfil.write(infil.read() + "\n") infil.close() i += 1 outfil.close() if wantsMacros: macros.run(ofpath, mVars, mFuns) if ext == "js" and not debug: print "\tCompressing \"" + ofpath + "\"..." bash.compressJS(ofpath, (plat != webPlat)) else: for baseFolder in baseFolders: baseFolder = src + baseFolder if bash.exists(baseFolder): for fil in bash.ls(baseFolder): fname = baseFolder + "/" + fil if fil[0] != '_' or not bash.isdir(fname): oPath = outPath + "/" + fil bash.cp_r(fname, oPath) if wantsMacros: macros.run(oPath, mVars, mFuns) else: oPath = outPath + ("." + ext if merge else "") bash.cp_r(src, oPath) if wantsMacros: macros.run(oPath, mVars, mFuns)
def makeWebXML(src, dest): print "Building web.xml..." infil = bash.readfile(src) outfl = bash.writefile(dest) outfl.write("<?xml version=\"1.0\" encoding=\"UTF-8\" " + "standalone=\"no\"?><web-app " + "xmlns=\"http://java.sun.com/xml/ns/javaee\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "version=\"2.5\" " + "xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee" + " " + "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\">\n" + "\n" + "\t<!-- Custom MIME types -->\n" + "\t<mime-mapping>\n" + "\t\t<extension>woff</extension>\n" + "\t\t<mime-type>font/opentype</mime-type>\n" + "\t</mime-mapping>\n" + "\n" + "\t<!-- Google Endpoint API Stuff -->\n" + "\t<servlet>\n" + "\t\t<servlet-name>SystemServiceServlet</servlet-name>\n" + "\t\t<servlet-class>" + "com.google.api.server.spi.SystemServiceServlet" + "</servlet-class>\n" + "\t\t<init-param>\n" + "\t\t\t<param-name>services</param-name>\n" + "\t\t\t<param-value/>\n" + "\t\t</init-param>\n" + "\t</servlet>\n" + "\t<servlet-mapping>\n" + "\t\t<servlet-name>SystemServiceServlet</servlet-name>\n" + "\t\t<url-pattern>/_ah/spi/*</url-pattern>\n" + "\t</servlet-mapping>\n" + "\n" + "\t<!-- - - - - - - - - - - - - - - - - - -->\n" + "\t<!-- Servlets (mostly) -->\n" + "\t<!-- - - - - - - - - - - - - - - - - - -->\n\n") prefix = "servlets" usedServlets = set([]) for line in infil: if "," in line: elems = line.split(",") assert (len(elems) > 1) fname = elems[0] if fname.startswith("."): fname = prefix + fname url = elems[1].strip().rstrip("/") isJSP = "JSP" in fname.upper() tagName = "jsp-file" if isJSP else "servlet-class" servlet = None if len(elems) < 3: if isJSP: servlet = re.sub(r'^.*\/(.*)\.jsp$', r'\1Servlet', fname) else: servlet = re.sub(r'^.*\.(.*)$', r'\1', fname) servlet = servlet[0].lower() + servlet[1:] if servlet in usedServlets: i = 0 while (servlet + "_" + str(i)) in usedServlets: i += 1 servlet += "_" + str(i) usedServlets.add(servlet) else: servlet = elems[2].strip() outfl.write("\t<servlet>\n" + "\t\t<servlet-name>" + servlet + "</servlet-name>\n" + "\t\t<" + tagName + ">" + fname + "</" + tagName + ">\n" + "\t</servlet>\n" + "\t<servlet-mapping>\n" + "\t\t<servlet-name>" + servlet + "</servlet-name>\n" + "\t\t<url-pattern>" + url + "</url-pattern>\n" + "\t</servlet-mapping>\n" + "\t<servlet-mapping>\n" + "\t\t<servlet-name>" + servlet + "</servlet-name>\n" + "\t\t<url-pattern>" + url + "/</url-pattern>\n" + "\t</servlet-mapping>\n") else: line = line.strip() if line.startswith("WELCOME:"): line = line[8:].strip() outfl.write("\t<!-- Default page to serve -->\n" + "\t<welcome-file-list>\n" + "\t\t<welcome-file>" + line + "</welcome-file>\n" + "\t</welcome-file-list>\n" + "\n") elif len(line) > 0: outfl.write("\n\t<!-- " + line + " -->\n") prefix = "servlets." + re.sub( r' ', r'_', re.sub(r'\s*-\s+', r'.', line.lower())) outfl.write("</web-app>") outfl.close() infil.close()
compileFolder(tmpFolder) for i in xrange(0, len(platforms)): if bash.exists(platformPaths[i]): clearFolder(platformPaths[i], "server/protected_war.csv" if i == 0 else None) else: bash.mkdir(platformPaths[i]) plat = platforms[i] native = plat != webPlat path = platformPaths[i] mVars['PLATFORM'] = plat mVars['NATIVE'] = "true" if native else "false" mVars['SERVER'] = server if native else "" mVars['MODERN'] = "true" if (native or mVars['TEST'] == "true") else "false" transferFls(tmpFolder, path, plat, debug, mVars, mFuns, uSet if i == 0 else projectsForApp) # Download channel API if native: apiPath = "_ah/channel/jsapi" bash.mkdir(os.path.join(path, "_ah")) bash.mkdir(os.path.join(path, "_ah/channel")) content = urllib2.urlopen( os.path.join(server, apiPath) if local else "https://talkgadget.google.com/talkgadget/channel.js").read() apiFile = bash.writefile(os.path.join(path, apiPath)) apiFile.write(re.sub(r'/_ah', os.path.join(server, "_ah"), content)) apiFile.close() bash.rm_r(tmpFolder)