Commit 8b570fa2 by Timothée Peignier

move hexdigest out of utils

parent 4efbc491
......@@ -35,18 +35,6 @@ def get_mod_func(callback):
return callback[:dot], callback[dot + 1:]
def get_hexdigest(plaintext):
"""
Create a hexdigest from a plaintext string
"""
try:
import hashlib
return hashlib.sha1(plaintext).hexdigest()
except ImportError:
import sha
return sha.new(plaintext).hexdigest()
def needs_update(output_file, source_files, verbosity=0):
"""
Scan the source files for changes and returns True if the output_file needs to be updated.
......
from compress.conf import settings
from compress.utils import get_output_filename, get_hexdigest, compress_source
from compress.utils import get_output_filename, compress_source
from compress.versioning import VersioningBase, VersioningError
from django.utils.hashcompat import sha_constructor
try:
import git
except ImportError:
......@@ -21,6 +23,9 @@ class GitVersioningBase(VersioningBase):
# no placeholder found, do not update, manual update if needed
return False, version
def hexdigest(self, plaintext):
return sha_constructor(plaintext).hexdigest()
class GitRevVersioning(GitVersioningBase):
"""
......@@ -33,7 +38,7 @@ class GitRevVersioning(GitVersioningBase):
for f in source_files:
commit = [i for i in repo.iter_commits(paths=compress_source(f), **kwargs)][0]
commit_revs.append(commit.name_rev)
return get_hexdigest(', '.join(commit_revs))[0:16]
return self.hexdigest(', '.join(commit_revs))[0:16]
class GitHeadRevVersioning(GitVersioningBase):
......@@ -43,4 +48,4 @@ class GitHeadRevVersioning(GitVersioningBase):
def get_version(self, source_files):
f = source_files[0]
repo = git.Repo(compress_source(f))
return get_hexdigest(repo.head.commit.name_rev)[0:16]
return self.hexdigest(repo.head.commit.name_rev)[0:16]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment