コード例 #1
0
ファイル: __init__.py プロジェクト: PSyton/django-compress
 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 ''
コード例 #2
0
ファイル: __init__.py プロジェクト: PSyton/django-compress
 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 ''
コード例 #3
0
 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))
コード例 #4
0
ファイル: __init__.py プロジェクト: mgan59/django-compress
 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))
コード例 #5
0
ファイル: __init__.py プロジェクト: mgan59/django-compress
 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
コード例 #6
0
 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
コード例 #7
0
 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)
コード例 #8
0
ファイル: __init__.py プロジェクト: mgan59/django-compress
 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)