Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue471 - import hashlib to sidestep deprecation warnings #474

Merged
merged 1 commit into from
Jun 14, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions library/assemble
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ except ImportError:
import simplejson as json
import os
import os.path
import md5
import sys
import shlex
import shutil
import syslog
import tempfile
try:
import hashlib
HAVE_HASHLIB=True
except ImportError:
import md5
HAVE_HASHLIB=False

# Since hashlib is only available in 2.5 and onwards, this module
# uses md5 which is available in 2.4.
Expand Down Expand Up @@ -59,6 +64,13 @@ def write_temp_file(data):
os.close(fd)
return path

def file_digest(path):
if HAVE_HASHLIB:
digest = hashlib.md5(file(path).read()).hexdigest()
else:
digest = md5.new(file(path).read()).hexdigest()
return digest

# ===========================================

if len(sys.argv) == 1:
Expand Down Expand Up @@ -99,10 +111,10 @@ if not os.path.isdir(src):
fail_json(msg="Source (%s) is not a directory" % src)

path = write_temp_file(assemble_from_fragments(src))
pathmd5 = md5.new(file(path).read()).hexdigest()
pathmd5 = file_digest(path)

if os.path.exists(dest):
destmd5 = md5.new(file(dest).read()).hexdigest()
destmd5 = file_digest(dest)

if pathmd5 != destmd5:
shutil.copy(path, dest)
Expand Down