def concat(self, filelist, outfile=None): """ Concat css and js files into a bundle """ from cStringIO import StringIO out_type = outfile and outfile.split('.')[-1] or 'js' outtxt = '' for f in filelist: suffix = None if ':' in f: f, suffix = f.split(':') if not os.path.exists(f) or os.path.isdir(f): continue self.timestamps[f] = os.path.getmtime(f) # get datas with open(f, 'r') as infile: # get file type ftype = f.split('.')[-1] data = unicode(infile.read(), 'utf-8') outtxt += ('\n/*\n *\t%s\n */' % f) # append if suffix == 'concat' or out_type != 'js' or self.no_compress or ( '.min.' in f): outtxt += '\n' + data + '\n' else: jsm = JavascriptMinify() tmpin = StringIO(data.encode('utf-8')) tmpout = StringIO() jsm.minify(tmpin, tmpout) tmpmin = unicode(tmpout.getvalue() or '', 'utf-8') tmpmin.strip('\n') outtxt += tmpmin with open(outfile, 'w') as f: f.write(outtxt.encode("utf-8")) print "Wrote %s - %sk" % (outfile, str(int(os.path.getsize(outfile) / 1024)))
def concat(self, filelist, outfile=None): """ Concat css and js files into a bundle """ from cStringIO import StringIO out_type = outfile and outfile.split('.')[-1] or 'js' outtxt = '' for f in filelist: suffix = None if ':' in f: f, suffix = f.split(':') if not os.path.exists(f) or os.path.isdir(f): continue self.timestamps[f] = os.path.getmtime(f) # get datas try: with open(f, 'r') as infile: # get file type ftype = f.split('.')[-1] data = unicode(infile.read(), 'utf-8', errors='ignore') outtxt += ('\n/*\n *\t%s\n */' % f) # append if suffix == 'concat' or out_type != 'js' or self.no_compress or ( '.min.' in f): outtxt += '\n' + data + '\n' else: jsm = JavascriptMinify() tmpin = StringIO(data.encode('utf-8')) tmpout = StringIO() jsm.minify(tmpin, tmpout) tmpmin = unicode(tmpout.getvalue() or '', 'utf-8') tmpmin.strip('\n') outtxt += tmpmin except Exception, e: print "--Error in:" + f + "--" print webnotes.getTraceback()