2 from hashlib import md5, sha1
5 from compress.conf import settings
6 from compress.utils import concat, get_output_filename
7 from compress.versioning.base import VersioningBase
10 class HashVersioningBase(VersioningBase):
12 def __init__(self, hash_method):
13 self.hash_method = hash_method
15 def needs_update(self, output_file, source_files, version):
16 output_file_name = get_output_filename(output_file, version)
17 ph = settings.COMPRESS_VERSION_PLACEHOLDER
21 old_version = output_file_name[phi:phi + len(ph) - len(of)]
22 return (version != old_version), version
24 # no placeholder found, do not update, manual update if needed
27 def get_version(self, source_files):
28 buf = concat(source_files)
29 s = cStringIO.StringIO(buf)
30 version = self.get_hash(s)
34 def get_hash(self, f, CHUNK=2 ** 16):
35 m = self.hash_method()
44 class MD5Versioning(HashVersioningBase):
47 super(MD5Versioning, self).__init__(md5)
50 class SHA1Versioning(HashVersioningBase):
53 super(SHA1Versioning, self).__init__(sha1)