From e8144b3b9012c1768f9249e9eda19847313485ef Mon Sep 17 00:00:00 2001 From: Akos Vandra Date: Sun, 25 Jan 2015 14:51:01 +0100 Subject: [PATCH 1/2] fixes #10086 --- lib/ansible/runner/shell_plugins/sh.py | 2 +- v2/ansible/plugins/shell/sh.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/runner/shell_plugins/sh.py b/lib/ansible/runner/shell_plugins/sh.py index c43a8e725cd..816b4c301c0 100644 --- a/lib/ansible/runner/shell_plugins/sh.py +++ b/lib/ansible/runner/shell_plugins/sh.py @@ -98,7 +98,7 @@ class ShellModule(object): test = "rc=flag; [ -r \'%(p)s\' ] || rc=2; [ -f \'%(p)s\' ] || rc=1; [ -d \'%(p)s\' ] && rc=3; %(i)s -V 2>/dev/null || rc=4; [ x\"$rc\" != \"xflag\" ] && echo \"${rc}\"\' %(p)s\' && exit 0" % dict(p=path, i=python_interp) csums = [ - "(%s -c 'import hashlib; print(hashlib.sha1(open(\"%s\", \"rb\").read()).hexdigest())' 2>/dev/null)" % (python_interp, path), # Python > 2.4 (including python3) + "(%s -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();\nwith open(\"%s\", \"rb\") as afile:\n\tbuf = afile.read(BLOCKSIZE)\n\twhile len(buf) > 0:\n\t\thasher.update(buf)\n\t\tbuf = afile.read(BLOCKSIZE)\n\n\nprint(hasher.hexdigest())' 2>/dev/null)" % (python_interp, path), # Python > 2.4 (including python3) "(%s -c 'import sha; print(sha.sha(open(\"%s\", \"rb\").read()).hexdigest())' 2>/dev/null)" % (python_interp, path), # Python == 2.4 ] diff --git a/v2/ansible/plugins/shell/sh.py b/v2/ansible/plugins/shell/sh.py index c43a8e725cd..816b4c301c0 100644 --- a/v2/ansible/plugins/shell/sh.py +++ b/v2/ansible/plugins/shell/sh.py @@ -98,7 +98,7 @@ class ShellModule(object): test = "rc=flag; [ -r \'%(p)s\' ] || rc=2; [ -f \'%(p)s\' ] || rc=1; [ -d \'%(p)s\' ] && rc=3; %(i)s -V 2>/dev/null || rc=4; [ x\"$rc\" != \"xflag\" ] && echo \"${rc}\"\' %(p)s\' && exit 0" % dict(p=path, i=python_interp) csums = [ - "(%s -c 'import hashlib; print(hashlib.sha1(open(\"%s\", \"rb\").read()).hexdigest())' 2>/dev/null)" % (python_interp, path), # Python > 2.4 (including python3) + "(%s -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();\nwith open(\"%s\", \"rb\") as afile:\n\tbuf = afile.read(BLOCKSIZE)\n\twhile len(buf) > 0:\n\t\thasher.update(buf)\n\t\tbuf = afile.read(BLOCKSIZE)\n\n\nprint(hasher.hexdigest())' 2>/dev/null)" % (python_interp, path), # Python > 2.4 (including python3) "(%s -c 'import sha; print(sha.sha(open(\"%s\", \"rb\").read()).hexdigest())' 2>/dev/null)" % (python_interp, path), # Python == 2.4 ] From 03fa421f3f67efbdb7ba2932c2f54b1cc906388e Mon Sep 17 00:00:00 2001 From: Akos Vandra Date: Sun, 25 Jan 2015 18:42:59 +0100 Subject: [PATCH 2/2] do not use with, it is not supported all the way down to 2.4 --- lib/ansible/runner/shell_plugins/sh.py | 2 +- v2/ansible/plugins/shell/sh.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/runner/shell_plugins/sh.py b/lib/ansible/runner/shell_plugins/sh.py index 816b4c301c0..ce214588520 100644 --- a/lib/ansible/runner/shell_plugins/sh.py +++ b/lib/ansible/runner/shell_plugins/sh.py @@ -98,7 +98,7 @@ class ShellModule(object): test = "rc=flag; [ -r \'%(p)s\' ] || rc=2; [ -f \'%(p)s\' ] || rc=1; [ -d \'%(p)s\' ] && rc=3; %(i)s -V 2>/dev/null || rc=4; [ x\"$rc\" != \"xflag\" ] && echo \"${rc}\"\' %(p)s\' && exit 0" % dict(p=path, i=python_interp) csums = [ - "(%s -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();\nwith open(\"%s\", \"rb\") as afile:\n\tbuf = afile.read(BLOCKSIZE)\n\twhile len(buf) > 0:\n\t\thasher.update(buf)\n\t\tbuf = afile.read(BLOCKSIZE)\n\n\nprint(hasher.hexdigest())' 2>/dev/null)" % (python_interp, path), # Python > 2.4 (including python3) + "(%s -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();\nafile = open(\"%s\", \"rb\")\nbuf = afile.read(BLOCKSIZE)\nwhile len(buf) > 0:\n\thasher.update(buf)\n\tbuf = afile.read(BLOCKSIZE)\nafile.close()\nprint(hasher.hexdigest())' 2>/dev/null)" % (python_interp, path), # Python > 2.4 (including python3) "(%s -c 'import sha; print(sha.sha(open(\"%s\", \"rb\").read()).hexdigest())' 2>/dev/null)" % (python_interp, path), # Python == 2.4 ] diff --git a/v2/ansible/plugins/shell/sh.py b/v2/ansible/plugins/shell/sh.py index 816b4c301c0..ce214588520 100644 --- a/v2/ansible/plugins/shell/sh.py +++ b/v2/ansible/plugins/shell/sh.py @@ -98,7 +98,7 @@ class ShellModule(object): test = "rc=flag; [ -r \'%(p)s\' ] || rc=2; [ -f \'%(p)s\' ] || rc=1; [ -d \'%(p)s\' ] && rc=3; %(i)s -V 2>/dev/null || rc=4; [ x\"$rc\" != \"xflag\" ] && echo \"${rc}\"\' %(p)s\' && exit 0" % dict(p=path, i=python_interp) csums = [ - "(%s -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();\nwith open(\"%s\", \"rb\") as afile:\n\tbuf = afile.read(BLOCKSIZE)\n\twhile len(buf) > 0:\n\t\thasher.update(buf)\n\t\tbuf = afile.read(BLOCKSIZE)\n\n\nprint(hasher.hexdigest())' 2>/dev/null)" % (python_interp, path), # Python > 2.4 (including python3) + "(%s -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();\nafile = open(\"%s\", \"rb\")\nbuf = afile.read(BLOCKSIZE)\nwhile len(buf) > 0:\n\thasher.update(buf)\n\tbuf = afile.read(BLOCKSIZE)\nafile.close()\nprint(hasher.hexdigest())' 2>/dev/null)" % (python_interp, path), # Python > 2.4 (including python3) "(%s -c 'import sha; print(sha.sha(open(\"%s\", \"rb\").read()).hexdigest())' 2>/dev/null)" % (python_interp, path), # Python == 2.4 ]