def therapy(self): css = [] for fn in self.absolute_paths: with open(fn, 'r') as fp: css.append(fp.read()) css = css_slimmer(''.join(css)) storage.save(self.node.destination, ContentFile(css))
def therapy(self): a_handle, a = mkstemp() b_handle, b = mkstemp() with open(a, 'wb') as a_fp: for fn in self.absolute_paths: with open(fn, 'r') as fp: a_fp.write(fp.read()) a_fp.write(';') p = Popen(['uglifyjs', '-o', b, a], stdout=PIPE) p.wait() with open(b, 'r') as b_fp: storage.save(self.node.destination, ContentFile(b_fp.read())) os.close(a_handle) os.close(b_handle) os.remove(a) os.remove(b)
def therapy(self): args = ['java', '-jar', settings.SHRINK_CLOSURE_COMPILER, '--compilation_level', settings.SHRINK_CLOSURE_COMPILER_COMPILATION_LEVEL] for absolute_path in self.absolute_paths: args.append('--js=%s' % absolute_path) handle, out = mkstemp() args.append('--js_output_file=%s' % out) # for some reason stdout stalls args = map(smart_str, args) print ('Compiling scripts in `%s` to `%s`' % (self.template, self.node.destination)) p = Popen(args, stdout=PIPE) p.wait() with open(out, 'r') as fp: storage.save(self.node.destination, ContentFile(fp.read())) os.close(handle) os.remove(out)
def therapy(self): css = [] parser = Scss() for absolute_path in self.absolute_paths: with open(absolute_path, 'r') as fp: if absolute_path.endswith('.scss'): css.append(parser.compile(fp.read())) else: css.append(fp.read()) handle, tmp = tempfile.mkstemp() with open(tmp, 'w') as fp: fp.write('\n'.join(css)) args = ['java', '-jar', settings.SHRINK_YUI_COMPRESSOR, '--type', 'css', tmp] args = map(smart_str, args) print ('Compressing (s)css in `%s` to `%s`' % (self.template, self.node.destination)) p = Popen(args, stdout=PIPE) p.wait() storage.save(self.node.destination, ContentFile(p.stdout.read())) os.close(handle) os.remove(tmp)