def process_combine(self, outputdir, verbose=False): #automatically process static combine from uliweb.contrib.template import init_static_combine from rjsmin.rjsmin import jsmin from rcssmin.rcssmin import cssmin d = init_static_combine() for k, v in d.items(): filename = os.path.join(outputdir, k) if verbose: print 'Process ... %s' % filename with open(filename, 'w') as f: ext = os.path.splitext(k)[1] if ext == '.js': processor = jsmin elif ext == '.css': processor = cssmin else: print "Error: Unsupport type %s" % ext sys.exit(1) for x in v: fname = os.path.join(outputdir, x) if verbose: print ' add %s' % fname f.write(processor(open(fname).read())) f.write('\n')
def process_combine(self, outputdir, verbose=False): #automatically process static combine from uliweb.contrib.template import init_static_combine from rjsmin.rjsmin import jsmin from rcssmin.rcssmin import cssmin import glob #delete combined files for f in glob.glob(os.path.join(outputdir, '_cmb_*')): try: os.remove(f) except: print "Error: static file [%s] can't be deleted" d = init_static_combine() for k, v in d.items(): filename = os.path.join(outputdir, k) if verbose: print 'Process ... %s' % filename readme = os.path.splitext(filename)[0] + '.txt' with open(filename, 'w') as f: ext = os.path.splitext(k)[1] if ext == '.js': processor = jsmin elif ext == '.css': processor = cssmin else: print "Error: Unsupport type %s" % ext sys.exit(1) for x in v: fname = os.path.join(outputdir, x) if verbose: print ' add %s' % fname kwargs = {} if ext == '.css': kwargs = {'base_dir':os.path.dirname(x)} f.write(processor(open(fname).read(), **kwargs)) f.write('\n') with open(readme, 'w') as r: for x in v: r.write(x) r.write('\n')