Revert "switch to using hashlib.md5 or md5 (if python 2.4) instead of a os call"

This reverts commit 865796c368.

(Superseeded by next commit)
reviewable/pr18780/r1
Michael DeHaan 13 years ago
parent c39259ded7
commit 2449381da9

@ -28,7 +28,6 @@ import shlex
import shutil
import syslog
import tempfile
try:
import hashlib
HAVE_HASHLIB=True
@ -65,18 +64,12 @@ def write_temp_file(data):
os.close(fd)
return path
def local_md5(filename):
''' compute local md5sum, return None if file is not present '''
if os.path.exists(filename):
md5val=None
if os.path.exists(filename):
if HAVE_HASHLIB:
md5val=hashlib.md5(file(filename).read()).hexdigest()
else:
md5val=md5.new(file(filename).read()).hexdigest()
return md5val
else:
return None
def file_digest(path):
if HAVE_HASHLIB:
digest = hashlib.md5(file(path).read()).hexdigest()
else:
digest = md5.new(file(path).read()).hexdigest()
return digest
# ===========================================
@ -118,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 = local_md5(path)
pathmd5 = file_digest(path)
if os.path.exists(dest):
destmd5 = local_md5(dest)
destmd5 = file_digest(dest)
if pathmd5 != destmd5:
shutil.copy(path, dest)

28
copy

@ -24,13 +24,6 @@ import shlex
import shutil
import syslog
try:
import hashlib
HAVE_HASHLIB=True
except ImportError:
import md5
HAVE_HASHLIB=False
# ===========================================
# convert arguments of form a=b c=d
# to a dictionary
@ -45,20 +38,9 @@ def exit_kv(rc=0, **kwargs):
print dump_kv(kwargs)
sys.exit(rc)
def local_md5(filename):
''' compute local md5sum, return None if file is not present '''
if os.path.exists(filename):
md5val=None
if os.path.exists(filename):
if HAVE_HASHLIB:
md5val=hashlib.md5(file(filename).read()).hexdigest()
else:
md5val=md5.new(file(filename).read()).hexdigest()
return md5val
else:
return None
# ===========================================
def md5_sum(f):
md5sum = os.popen("/usr/bin/md5sum %(file)s 2>/dev/null || /sbin/md5 -q %(file)s 2>/dev/null || /usr/bin/digest -a md5 -v %(file)s 2>/dev/null" % {"file": f}).read().split()[0]
return md5sum
if len(sys.argv) == 1:
exit_kv(rc=1, failed=1, msg="incorrect number of arguments given")
@ -91,7 +73,7 @@ if not os.path.exists(src):
exit_kv(rc=1, failed=1, msg="Source %s failed to transfer" % (src))
if not os.access(src, os.R_OK):
exit_kv(rc=1, failed=1, msg="Source %s not readable" % (src))
md5sum_src = local_md5(src)
md5sum_src = md5_sum(src)
md5sum_dest = None
# check if there is no dest file
@ -101,7 +83,7 @@ if os.path.exists(dest):
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (dest))
if not os.access(dest, os.R_OK):
exit_kv(rc=1, failed=1, msg="Destination %s not readable" % (dest))
md5sum_dest = local_md5(dest)
md5sum_dest = md5_sum(dest)
else:
if not os.access(os.path.dirname(dest), os.W_OK):
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (os.path.dirname(dest)))

28
setup

@ -33,13 +33,6 @@ import subprocess
import traceback
import syslog
try:
import hashlib
HAVE_HASHLIB=True
except ImportError:
import md5
HAVE_HASHLIB=False
try:
import selinux
HAVE_SELINUX=True
@ -318,20 +311,9 @@ def ansible_facts():
get_service_facts(facts)
return facts
def local_md5(filename):
''' compute local md5sum, return None if file is not present '''
if os.path.exists(filename):
md5val=None
if os.path.exists(filename):
if HAVE_HASHLIB:
md5val=hashlib.md5(file(filename).read()).hexdigest()
else:
md5val=md5.new(file(filename).read()).hexdigest()
return md5val
else:
return None
# ===========================================
def md5_sum(f):
md5sum = os.popen("/usr/bin/md5sum %(file)s 2>/dev/null || /sbin/md5 -q %(file)s 2>/dev/null || /usr/bin/digest -a md5 -v %(file)s 2>/dev/null" % {"file": f}).read().split()[0]
return md5sum
# load config & template variables
@ -369,7 +351,7 @@ md5sum = None
if not os.path.exists(ansible_file):
changed = True
else:
md5sum = local_md5(ansible_file)
md5sum = md5_sum(ansible_file)
# Get some basic facts in case facter or ohai are not installed
for (k, v) in ansible_facts().items():
@ -418,7 +400,7 @@ reformat = json.dumps(setup_options, sort_keys=True, indent=4)
f.write(reformat)
f.close()
md5sum2 = local_md5(ansible_file)
md5sum2 = md5_sum(ansible_file)
if md5sum != md5sum2:
changed = True

Loading…
Cancel
Save