Port the copy module over to the new "common module" logic.

This commit is contained in:
Michael DeHaan 2012-07-21 17:07:42 -04:00
parent d76c8c9c85
commit d0f4358730
3 changed files with 60 additions and 93 deletions

View file

@ -39,6 +39,11 @@ import subprocess
import sys
import syslog
try:
from hashlib import md5 as _md5
except ImportError:
from md5 import md5 as _md5
class AnsibleModule(object):
def __init__(self, argument_spec, bypass_checks=False, no_log=False):
@ -135,6 +140,21 @@ class AnsibleModule(object):
print json.dumps(kwargs)
sys.exit(1)
def md5(self, filename):
''' Return MD5 hex digest of local file, or None if file is not present. '''
if not os.path.exists(filename):
return None
digest = _md5()
blocksize = 64 * 1024
infile = open(filename, 'rb')
block = infile.read(blocksize)
while block:
digest.update(block)
block = infile.read(blocksize)
infile.close()
return digest.hexdigest()
# == END DYNAMICALLY INSERTED CODE ===
"""