def test_registerJSFiles__both_slimmed(self): """ test the registerJSFiles() with slim_if_possible=True """ if js_slimmer is None: return class MyProduct: pass # test setting a bunch of files files = ["large.js", "test.js"] files.append(tuple(files)) registerJSFiles( MyProduct, files, rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=False ) instance = MyProduct() for filename in files: if isinstance(filename, tuple): filename = ",".join(filename) static = getattr(instance, filename) self.assertTrue(isinstance(static, BetterImageFile)) rendered = str(static) # expect this to be slimmed if len(filename.split(",")) > 1: content_parts = [open(right_here(x)).read() for x in filename.split(",")] expected_content = js_slimmer("\n".join(content_parts)) else: expected_content = js_slimmer(open(right_here(filename)).read()) self.assertEqual(rendered.strip(), expected_content.strip())
def slimmer(self, hard=False): content = self.readFiles() fileRead = list( filter( lambda el: el.strip() != "" and el.strip() != "'use strict';", content.splitlines())) fileRead = js_slimmer("\n".join(fileRead)) fileRead = fileRead.splitlines() fileRead = list(map(lambda el: el.strip(), fileRead)) return js_slimmer("".join(fileRead), hard)
def test_registerJSFiles__one_slimmed(self): """ test the registerJSFiles() with slim_if_possible=True but one of the files shouldn't be slimmed because its filename indicates that it's already been slimmed/packed/minified. In this test, the big challange is when two js files are combined and one of them should be slimmed, the other one not slimmed. """ class MyProduct: pass files = ["test.min.js", "test.js"] files.append(tuple(files)) registerJSFiles( MyProduct, files, rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=False ) instance = MyProduct() for filename in files: if isinstance(filename, tuple): filename = ",".join(filename) static = getattr(instance, filename) self.assertTrue(isinstance(static, BetterImageFile)) rendered = str(static).strip() # expect this to be slimmed if len(filename.split(",")) > 1: content_parts = [] for filename in filename.split(","): content = open(right_here(filename)).read() if filename.find("min") > -1 or js_slimmer is None: content_parts.append(content) else: content_parts.append(js_slimmer(content)) expected_content = "\n".join(content_parts) expected_content = expected_content.strip() else: content = open(right_here(filename)).read() if filename.find("min") > -1 or js_slimmer is None: expected_content = content else: expected_content = js_slimmer(content) expected_content = expected_content.strip() self.assertEqual(rendered, expected_content)
def test_registerJSFiles__both_slimmed_and_gzipped(self): """ test the registerJSFiles() with slim_if_possible=True """ if js_slimmer is None: return class MyProduct: pass # test setting a bunch of files files = ["large.js", "test.js"] files.append(tuple(files)) registerJSFiles( MyProduct, files, rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=True ) instance = MyProduct() REQUEST = self.app.REQUEST RESPONSE = REQUEST.RESPONSE for filename in files: if isinstance(filename, tuple): filename = ",".join(filename) static = getattr(instance, filename) self.assertTrue(isinstance(static, BetterImageFile)) # if you just call static.__str__() you're not calling it # with a REQUEST that accepts gzip encoding REQUEST.set("HTTP_ACCEPT_ENCODING", "gzip") bin_rendered = static.index_html(REQUEST, RESPONSE) # expect this to be slimmed if len(filename.split(",")) > 1: content_parts = [open(right_here(x)).read() for x in filename.split(",")] expected_content = js_slimmer("\n".join(content_parts)) else: content = open(right_here(filename)).read() expected_content = js_slimmer(content) rendered = _gzip2ascii(bin_rendered) self.assertEqual(rendered.strip(), expected_content.strip())
def registerJS(filename, path='js', slim_if_possible=True): product = OFS.misc_.misc_.IssueTrackerMassContainer objectid = filename setattr(product, objectid, BetterImageFile(os.path.join(path, filename), globals())) obj = getattr(product, objectid) if js_slimmer is not None and OPTIMIZE: if slim_if_possible: slimmed = js_slimmer(open(obj.path, 'rb').read()) new_path = obj.path + '-slimmed' open(new_path, 'wb').write(slimmed) setattr(obj, 'path', new_path)
def get_code(self): import slimmer f = codecs.open(self.path, 'r', 'utf-8') code = f.read() f.close() if self.filetype == '.css': return slimmer.css_slimmer(code) if self.filetype == '.js': return slimmer.js_slimmer(code) if self.filetype == '.html': return slimmer.xhtml_slimmer(code) return code
def _registerJS(product, filename, path='js', slim_if_possible=True): objectid = filename setattr(product, objectid, BetterImageFile(os.path.join(path, filename), globals())) obj = getattr(product, objectid) if js_slimmer is not None and OPTIMIZE: if slim_if_possible: slimmed = js_slimmer(open(obj.path, 'rb').read()) new_path = obj.path + '-slimmed.js' new_path = _get_autogenerated_file_path(new_path) open(new_path, 'wb').write(slimmed) setattr(obj, 'path', new_path)
def _get_code(self): import slimmer f = open(self.path) code = f.read() f.close() if self.filetype == '.css': return slimmer.css_slimmer(code) if self.filetype == '.js': return slimmer.js_slimmer(code) if self.filetype == '.html': return slimmer.xhtml_slimmer(code) return code
def get_code(self): import slimmer f = open(self.path) code = f.read() f.close() if self.filetype == '.css': return slimmer.css_slimmer(code) if self.filetype == '.js': return slimmer.js_slimmer(code) if self.filetype == '.html': return slimmer.xhtml_slimmer(code) return code
def optimize(content, type_): if type_ == CSS: if getattr(settings, 'DJANGO_STATIC_YUI_COMPRESSOR', None): return _run_yui_compressor(content, type_) return css_slimmer(content) elif type_ == JS: if getattr(settings, 'DJANGO_STATIC_CLOSURE_COMPILER', None): return _run_closure_compiler(content) if getattr(settings, 'DJANGO_STATIC_YUI_COMPRESSOR', None): return _run_yui_compressor(content, type_) return js_slimmer(content) else: raise ValueError("Invalid type %r" % type_)
def geniAnki(self): if (web.ctx.environ['HTTP_USER_AGENT'].lower().find('iphone') < 0) and (web.ctx.environ['HTTP_USER_AGENT'].lower().find('ipod') < 0): iPhone = False else: iPhone = True # css f = open(iankiPath+'/static/base.css') css = f.read() f.close() if True: #iPhone f = open(iankiPath+'/static/iphone.css') css += f.read() f.close() if iPhone: f = open(iankiPath+'/static/anki-logo.png', 'rb') touchicon = '<link rel="apple-touch-icon" href="data:image/png;base64,%s"/>' % base64.b64encode(f.read()) f.close() favicon = "" joose = "" orm = "" else: touchicon = "" # favicon f = open(iankiPath+'/static/favicon.ico', 'rb') favicon = '<link rel="shorcut icon" href="data:image/ico;base64,%s"/>' % base64.b64encode(f.read()) f.close() f = open(iankiPath+'/static/joose.mini.js') joose = f.read() f.close() f = open(iankiPath+'/static/orm_async.js') orm = f.read() f.close() f = open(iankiPath+'/static/mootools-1.2.1-core.js') s1 = f.read() f.close() f = open(iankiPath+'/static/ianki.js') s2 = f.read() f.close() f = open(iankiPath+'/templates/ianki.html') iankiHTML = f.read() f.close() if makeSlim: s2 = slimmer.js_slimmer(s2) iankiHTML = iankiHTML % {'version':ui.__version__, 'favicon':favicon, 'touchicon':touchicon, 'css':css, 'joose':joose, 'orm':orm, 'mootools':s1, 'ianki':s2, 'location':web.input(loc='').loc} return iankiHTML
def registerJS(filename, path='js', slim_if_possible=True): product = OFS.misc_.misc_.IssueTrackerMassContainer objectid = filename setattr(product, objectid, BetterImageFile(os.path.join(path, filename), globals()) ) obj = getattr(product, objectid) if js_slimmer is not None and OPTIMIZE: if slim_if_possible: slimmed = js_slimmer(open(obj.path,'rb').read()) new_path = obj.path + '-slimmed' open(new_path, 'wb').write(slimmed) setattr(obj, 'path', new_path)
def _registerJS(product, filename, path='js', slim_if_possible=True): objectid = filename setattr(product, objectid, BetterImageFile(os.path.join(path, filename), globals()) ) obj = getattr(product, objectid) if js_slimmer is not None and OPTIMIZE: if slim_if_possible: slimmed = js_slimmer(open(obj.path,'rb').read()) new_path = obj.path + '-slimmed.js' new_path = _get_autogenerated_file_path(new_path) open(new_path, 'wb').write(slimmed) setattr(obj, 'path', new_path)
def render(self, context): code = self.nodelist.render(context) if self.format == 'css': return css_slimmer(code) elif self.format in ('js', 'javascript'): return js_slimmer(code) elif self.format == 'html': return html_slimmer(code) else: format = guessSyntax(code) if format: self.format = format return self.render(context) return code
def optimize(content, type_): if type_ == CSS: if cssmin is not None: return _run_cssmin(content) elif getattr(settings, "DJANGO_STATIC_YUI_COMPRESSOR", None): return _run_yui_compressor(content, type_) return slimmer.css_slimmer(content) elif type_ == JS: if getattr(settings, "DJANGO_STATIC_CLOSURE_COMPILER", None): return _run_closure_compiler(content) if getattr(settings, "DJANGO_STATIC_YUI_COMPRESSOR", None): return _run_yui_compressor(content, type_) if getattr(settings, "DJANGO_STATIC_JSMIN", None): return _run_jsmin(content) return slimmer.js_slimmer(content) else: raise ValueError("Invalid type %r" % type_)
def test_registering_with_slimming_basic(self): try: from slimmer import js_slimmer, css_slimmer except ImportError: # not possible to test this return class MyProduct: pass instance = MyProduct() registerJSFile(MyProduct, "test.js", rel_path="tests", set_expiry_header=True, slim_if_possible=True) static = getattr(instance, "test.js") self.assertEqual(str(static), js_slimmer(open(right_here("test.js")).read())) # this will have created a file called 'test.js-slimmed.js' whose content # is the same as str(static) copy_test_js = os.path.join(_get_autogenerated_dir(), "test.js-slimmed.js") self.assertTrue(os.path.isfile(copy_test_js)) self.assertEqual(open(copy_test_js).read(), str(static)) # and it that directory there should not be any other files for f in os.listdir(os.path.dirname(copy_test_js)): self.assertEqual(f, os.path.basename(copy_test_js)) registerCSSFile(MyProduct, "test.css", rel_path="tests", set_expiry_header=True, slim_if_possible=True) static = getattr(instance, "test.css") self.assertEqual(str(static), css_slimmer(open(right_here("test.css")).read())) # this will have created a file called 'test.css-slimmed.css' whose content # is the same as str(static) copy_test_css = os.path.join(_get_autogenerated_dir(), "test.css-slimmed.css") self.assertTrue(os.path.isfile(copy_test_css)) self.assertEqual(open(copy_test_css).read(), str(static)) # and it that directory there should not be any other files other # than the one we made before called test.js-slimmed.js for f in os.listdir(os.path.dirname(copy_test_css)): self.assertTrue(f == os.path.basename(copy_test_js) or f == os.path.basename(copy_test_css)) # if you don it again it should just overwrite the old one registerCSSFile(MyProduct, "test.css", rel_path="tests", set_expiry_header=True, slim_if_possible=True) static = getattr(instance, "test.css") # there should still only be two files in the autogenerated directory self.assertEqual(len(os.listdir(_get_autogenerated_dir())), 2)
def optimize(content, type_): if type_ == CSS: if cssmin is not None: return _run_cssmin(content) elif getattr(settings, 'DJANGO_STATIC_YUI_COMPRESSOR', None): return _run_yui_compressor(content, type_) return slimmer.css_slimmer(content) elif type_ == JS: if getattr(settings, 'DJANGO_STATIC_CLOSURE_COMPILER', None): return _run_closure_compiler(content) if getattr(settings, 'DJANGO_STATIC_YUI_COMPRESSOR', None): return _run_yui_compressor(content, type_) if getattr(settings, 'DJANGO_STATIC_JSMIN', None): return _run_jsmin(content) return slimmer.js_slimmer(content) else: raise ValueError("Invalid type %r" % type_)
def render(self, context): code = self.nodelist.render(context) if slimmer is None: return code if self.format not in ('css','js','html','xhtml'): self.format = guessSyntax(code) if self.format == 'css': return css_slimmer(code) elif self.format in ('js', 'javascript'): return js_slimmer(code) elif self.format == 'xhtml': return xhtml_slimmer(code) elif self.format == 'html': return html_slimmer(code) return code
def render(self, context): code = self.nodelist.render(context) if slimmer is None: return code if self.format not in ("css", "js", "html", "xhtml"): self.format = slimmer.guessSyntax(code) if self.format == "css": return slimmer.css_slimmer(code) elif self.format in ("js", "javascript"): return slimmer.js_slimmer(code) elif self.format == "xhtml": return slimmer.xhtml_slimmer(code) elif self.format == "html": return slimmer.html_slimmer(code) else: raise TemplateSyntaxError("Unrecognized format for slimming content") return code
def render(self, context): code = self.nodelist.render(context) if slimmer is None: return code if self.format not in ('css','js','html','xhtml'): self.format = slimmer.guessSyntax(code) if self.format == 'css': return slimmer.css_slimmer(code) elif self.format in ('js', 'javascript'): return slimmer.js_slimmer(code) elif self.format == 'xhtml': return slimmer.xhtml_slimmer(code) elif self.format == 'html': return slimmer.html_slimmer(code) else: raise TemplateSyntaxError("Unrecognized format for slimming content") return code
def test_registering_with_slimming_and_gzip_and_images_in_css(self): try: from slimmer import js_slimmer, css_slimmer except ImportError: # not possible to test this return class MyProduct: pass instance = MyProduct() registerJSFile(MyProduct, "test.js", rel_path="tests", set_expiry_header=True, slim_if_possible=True) static = getattr(instance, "test.js") self.assertEqual(str(static), js_slimmer(open(right_here("test.js")).read())) registerCSSFile( MyProduct, "test.css", rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=True, ) static = getattr(instance, "test.css") self.assertEqual(str(static), css_slimmer(open(right_here("test.css")).read())) # if you don it again it should just overwrite the old one registerCSSFile( MyProduct, "test.css", rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=True, ) static = getattr(instance, "test.css") self.assertEqual(str(static), css_slimmer(open(right_here("test.css")).read()))
def test_registerJSFiles__one_slimmed_and_gzipped(self): """ test the registerJSFiles() with slim_if_possible=True but one of the files shouldn't be slimmed because its filename indicates that it's already been slimmed/packed/minified. In this test, the big challange is when two js files are combined and one of them should be slimmed, the other one not slimmed. """ if js_slimmer is None: return class MyProduct: pass files = ["test.min.js", "test.js"] files.append(tuple(files)) registerJSFiles( MyProduct, files, rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=True ) REQUEST = self.app.REQUEST RESPONSE = REQUEST.RESPONSE instance = MyProduct() for filename in files: if isinstance(filename, tuple): filename = ",".join(filename) static = getattr(instance, filename) self.assertTrue(isinstance(static, BetterImageFile)) # if you just call static.__str__() you're not calling it # with a REQUEST that accepts gzip encoding REQUEST.set("HTTP_ACCEPT_ENCODING", "gzip") bin_rendered = static.index_html(REQUEST, RESPONSE) # expect this to be slimmed if len(filename.split(",")) > 1: content_parts = [] for filename in filename.split(","): content = open(right_here(filename)).read() if filename.find("min") > -1: content_parts.append(content) else: if js_slimmer is None: content_parts.append(content) else: content_parts.append(js_slimmer(content)) expected_content = "\n".join(content_parts) expected_content = expected_content.strip() else: if filename.find("min") > -1: expected_content = open(right_here(filename)).read() else: content = open(right_here(filename)).read() if js_slimmer is None: expected_content = content else: expected_content = js_slimmer(content) expected_content = expected_content.strip() rendered = _gzip2ascii(bin_rendered) self.assertEqual(rendered.strip(), expected_content)
def test_registering_with_slimming_and_gzip(self): try: from slimmer import js_slimmer, css_slimmer except ImportError: # not possible to test this return class MyProduct: pass instance = MyProduct() registerJSFile( MyProduct, "test.js", rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=True ) static = getattr(instance, "test.js") # Note, using str(static) means it does not send the Accept-Encoding: gzip # header. self.assertEqual(str(static), js_slimmer(open(right_here("test.js")).read())) # this will have created a file called 'test.js-slimmed.js' whose content # is the same as str(static) copy_test_js = os.path.join(_get_autogenerated_dir(), "test.js-slimmed.js") self.assertTrue(os.path.isfile(copy_test_js)) self.assertEqual(open(copy_test_js).read(), str(static)) # it would also have generated another copy called # test.js-slimmed.js.gz copy_test_js_gz = os.path.join(_get_autogenerated_dir(), "test.js-slimmed.js.gz") self.assertTrue(os.path.isfile(copy_test_js_gz)) self.assertEqual(gzip.open(copy_test_js_gz).read(), str(static)) registerCSSFile( MyProduct, "test.css", rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=True, ) static = getattr(instance, "test.css") self.assertEqual(str(static), css_slimmer(open(right_here("test.css")).read())) # this will have created a file called 'test.css-slimmed.css' whose content # is the same as str(static) copy_test_css = os.path.join(_get_autogenerated_dir(), "test.css-slimmed.css") self.assertTrue(os.path.isfile(copy_test_css)) self.assertEqual(open(copy_test_css).read(), str(static)) # it would also have generated another copy called # test.css-slimmed.css.gz copy_test_css_gz = os.path.join(_get_autogenerated_dir(), "test.css-slimmed.css.gz") self.assertTrue(os.path.isfile(copy_test_css_gz)) self.assertEqual(gzip.open(copy_test_css_gz).read(), str(static)) # if you don it AGAIN it should just overwrite the old one registerCSSFile( MyProduct, "test.css", rel_path="tests", set_expiry_header=True, slim_if_possible=True, gzip_if_possible=True, ) static = getattr(instance, "test.css") self.assertEqual(str(static), css_slimmer(open(right_here("test.css")).read()))
def evaluate(self,scope, locals, block=None): if not hasattr(self,'output') or not self.output: from slimmer import js_slimmer self.output = js_slimmer(self.data) return self.output
def evaluate(self, scope, locals, block=None): if not hasattr(self, 'output') or not self.output: from slimmer import js_slimmer self.output = js_slimmer(self.data) return self.output
def output(self, _in, out, **kwargs): out.write(js_slimmer(_in.read()))
import slimmer import sys if __name__ == '__main__': for fpath in sys.argv[1:]: with open(fpath, 'r') as fh: txt = fh.read() if fpath.endswith('.html'): txt = slimmer.html_slimmer(txt) elif fpath.endswith('.css'): txt = slimmer.css_slimmer(txt) elif fpath.endswith('.js'): txt = slimmer.js_slimmer(txt) else: print('unknown format of', fpath) with open(fpath, 'w') as fh: fh.write(txt)
def registerJSFile(product, filename, epath=None, Globals=globals(), rel_path='js', slim_if_possible=True, gzip_if_possible=False, set_expiry_header=False, max_age_development=60, max_age_production=3600): p_home = package_home(Globals) # product home if filename.count('-slimmed.js'): raise SystemError, "Again!??!" objectid = filename path = "%s/" % rel_path if epath: path = "%s/%s/" % (rel_path, epath) filepath = '%s%s' % (path, filename) if len(filename.split(',')) > 1: # it's a combo name!! real_filepath = _getAutogeneratedFilepath(os.path.join(p_home, filepath)) out = open(real_filepath, 'w') mtimes = [] for filepath_ in [os.path.join(p_home, '%s%s' % (path, x)) for x in filename.split(',')]: content = open(filepath_).read() if slim_if_possible and js_slimmer and not dont_slim_file(filepath_): content = js_slimmer(content) out.write(content + '\n') mtimes.append(os.stat(filepath_)[stat.ST_MTIME]) out.close() filepath = real_filepath mtime = max(mtimes) # since we've taken the slimming thought into account already # here in the loop there is no need to consider slimming the # content further down. slim_if_possible = False else: mtime = os.stat(os.path.join(p_home, filepath))[stat.ST_MTIME] setattr(product, objectid, BetterImageFile(filepath, Globals, max_age_development=max_age_development, max_age_production=max_age_production, set_expiry_header=set_expiry_header) ) obj = getattr(product, objectid) if slim_if_possible and dont_slim_file(os.path.join(p_home, filepath)): slim_if_possible = False if slim_if_possible and \ os.path.isfile(os.path.join(p_home, filepath)): if os.path.isfile(os.path.join(p_home, filepath+'.nogzip')): gzip_if_possible = False if js_slimmer is not None and slim_if_possible: obj = getattr(product, objectid) slimmed = js_slimmer(open(obj.path,'rb').read(), hardcore=False) filepath = _getAutogeneratedFilepath(obj.path + '-slimmed.js') open(filepath, 'wb').write(slimmed) setattr(obj, 'path', filepath) # set up an alias too with near infinite max_age a, b = os.path.splitext(filename) objectid_alias = a + '.%s' % mtime + b setattr(product, objectid_alias, BetterImageFile(obj.path, Globals, set_expiry_header=set_expiry_header, max_age_development=EXPIRY_INFINITY, # 5 years max_age_production=EXPIRY_INFINITY # 5 years ) ) # make a note of the alias if hasattr(product, 'misc_infinite_aliases'): aliases = product.misc_infinite_aliases else: aliases = {} aliases[objectid] = objectid_alias setattr(product, 'misc_infinite_aliases', aliases) if gzip_if_possible: setattr(product, objectid, GzippedFile(filepath, Globals, max_age_development=max_age_development, max_age_production=max_age_production, set_expiry_header=set_expiry_header) ) # then set up an alias (overwrite the previous alias) # for the gzipped version too. setattr(product, objectid_alias, GzippedFile(filepath, Globals, max_age_development=EXPIRY_INFINITY, max_age_production=EXPIRY_INFINITY, set_expiry_header=set_expiry_header) )
mimetype = "application/octet-stream" # get raw file data with open(filepath, "rb") as fr: filedata = fr.read() oldfilesize = len(filedata) # can I remove CR, LF, Tabs? if do_slimmer: if fileext in [".tpl", ".html", ".htm"]: filedata = slimmer.html_slimmer(filedata) elif fileext in [".css"]: filedata = slimmer.css_slimmer(filedata) elif fileext in [".js"]: filedata = slimmer.js_slimmer(filedata) print "Adding {} mimetype = ({}) size = {} reduced size = {}".format(filename, mimetype, oldfilesize, len(filedata)) # filename length, mime tpye length, file content length fw.write(struct.pack("<BBH", len(filename) + 1, len(mimetype) + 1, len(filedata))) # filename data fw.write(struct.pack(str(len(filename)) + "sB", filename, 0x00)) # mime type data fw.write(struct.pack(str(len(mimetype)) + "sB", mimetype, 0x00)) # file data fw.write(filedata)
mimetype = "application/octet-stream" # get raw file data with open(filepath, "rb") as fr: filedata = fr.read() oldfilesize = len(filedata) # can I remove CR, LF, Tabs? if do_slimmer: if fileext in [".tpl", ".html", ".htm"]: filedata = slimmer.html_slimmer(filedata) elif fileext in [".css"]: filedata = slimmer.css_slimmer(filedata) elif fileext in [".js"]: filedata = slimmer.js_slimmer(filedata) print "Adding {} mimetype = ({}) size = {} reduced size = {}".format( filename, mimetype, oldfilesize, len(filedata)) # flags fw.write(struct.pack("B", 0)) # filename length, mime tpye length, file content length fw.write( struct.pack("<BBH", len(filename) + 1, len(mimetype) + 1, len(filedata))) # filename data fw.write(struct.pack(str(len(filename)) + "sB", filename, 0x00))
import os,sys import json import datetime import time import calendar import arrow import os #Y-m-d H:i:s ms tz #print datetime.timedelta(3600*8) #print result html="" for line in open("test.html"): html+=line #print html import slimmer html=slimmer.js_slimmer(html) html=slimmer.html_slimmer(html) print html
# comment out all the other js files in the template found = False for no, line in enumerate(all_lines): if found: if line.strip() == "{# end opus.js #}": all_lines[no] = "--> \n" + all_lines[no] break if line.strip() == "{# opus.js #}": all_lines[no] = all_lines[no] + "<!--\n" found = True # strip any console log calls from all js files stripConsoleLogs(my_files) # min and concat all js files in js_files.py/base_opus.html min_file = "" for infile in my_files: min_file = min_file + js_slimmer(open(infile).read()) # write out the new template and the js file new_file = open(template_pth, "w") new_file.write("".join(all_lines)) new_file.close() new_file = open(outfile, "w") new_file.write(min_file) new_file.close() print "Bye!"