def read_file(self, path): """Read file content in binary mode""" if storage.exists(path): file = storage.open(path, mode='rb') content = file.read().decode('utf8') file.close() return content return ''
def cleanup(self, filename): if not settings.COMPRESS_VERSION_REMOVE_OLD: return # Nothing to delete here path = os.path.dirname(filename) regex = self.file_regex(os.path.basename(filename)) if storage.exists(path): for f in storage.listdir(path)[1]: if regex.match(f): if self.verbose: print "Removing outdated file %s" % f storage.delete(os.path.join(path, f))
def cleanup(self, filename): if not settings.COMPRESS_VERSION and not settings.COMPRESS_VERSION_REMOVE_OLD: return # Nothing to delete here path = os.path.dirname(filename) filename = settings.COMPRESS_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.COMPRESS_VERSION_PLACEHOLDER)]) regex = re.compile(r'^%s$' % os.path.basename(self.output_filename(filename, r'([A-Za-z0-9]+)'))) if storage.exists(path): for f in storage.listdir(path)[1]: if regex.match(f): if self.verbose: print "Removing outdated file %s" % f storage.delete(os.path.join(path, f))
def compile(self, paths): for index, path in enumerate(paths): for compiler in self.compilers: compiler = compiler(self.verbose) if compiler.match_file(path): new_path = self.output_path(path, compiler.output_extension) content = self.read_file(path) try: compiled_content = compiler.compile_file(content) self.save_file(new_path, compiled_content) except CompilerError: if not storage.exists(new_path): raise paths[index] = new_path return paths
def need_update(self, output_file, paths): version = self.version(paths) output_file = self.output_filename(output_file, version) if not storage.exists(root_path(output_file)): return True, version return self.version_impl.need_update(output_file, paths, version)
def need_update(self, output_file, paths): version = self.version(paths) output_file = self.output_filename(output_file, version) if not storage.exists(self.relative_path(output_file)): return True, version return getattr(self.versionner, 'need_update')(output_file, paths, version)