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
9 class HashVersioningBase(VersioningBase):
10 def __init__(self, hash_method):
11 self.hash_method = hash_method
13 def needs_update(self, output_file, source_files, version):
14 output_file_name = get_output_filename(output_file, version)
15 ph = settings.COMPRESS_VERSION_PLACEHOLDER
19 old_version = output_file_name[phi:phi+len(ph)-len(of)]
20 return (version != old_version), version
22 # no placeholder found, do not update, manual update if needed
25 def get_version(self, source_files):
26 buf = concat(source_files)
27 s = cStringIO.StringIO(buf)
28 version = self.get_hash(s)
32 def get_hash(self, f, CHUNK=2**16):
33 m = self.hash_method()
41 class MD5Versioning(HashVersioningBase):
43 super(MD5Versioning, self).__init__(md5)
45 class SHA1Versioning(HashVersioningBase):
47 super(SHA1Versioning, self).__init__(sha1)