mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-09 09:54:02 -07:00
switch to hashlib.md5 or md5 instead of OS md5 commands
This commit is contained in:
parent
921bf3da9d
commit
55694db7c3
5 changed files with 68 additions and 28 deletions
|
@ -26,11 +26,19 @@ import jinja2
|
|||
import yaml
|
||||
import optparse
|
||||
from operator import methodcaller
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
try:
|
||||
import hashlib
|
||||
HAVE_HASHLIB=True
|
||||
except ImportError:
|
||||
import md5
|
||||
HAVE_HASHLIB=False
|
||||
|
||||
from ansible import errors
|
||||
import ansible.constants as C
|
||||
|
||||
|
@ -312,14 +320,14 @@ def parse_kv(args):
|
|||
options[k]=v
|
||||
return options
|
||||
|
||||
def local_md5(file):
|
||||
''' compute local md5sum, return None if file is not present '''
|
||||
cmd = "/usr/bin/md5sum %s 2> /dev/null || /sbin/md5 -q %s" % (file,file)
|
||||
if not os.path.exists(file):
|
||||
def md5(filename):
|
||||
''' compute md5sum, return None if file is not present '''
|
||||
if not os.path.exists(filename):
|
||||
return None
|
||||
if HAVE_HASHLIB:
|
||||
return hashlib.md5(file(filename).read()).hexdigest()
|
||||
else:
|
||||
c = os.popen(cmd)
|
||||
return c.read().split()[0]
|
||||
return md5.new(file(filename).read()).hexdigest()
|
||||
|
||||
|
||||
####################################################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue