|
|
|
|
@ -14,6 +14,10 @@ extends_documentation_fragment:
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from ansible.plugins.shell import ShellBase
|
|
|
|
|
from ansible.utils.display import Display
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
display = Display()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ShellModule(ShellBase):
|
|
|
|
|
@ -43,6 +47,10 @@ class ShellModule(ShellBase):
|
|
|
|
|
_SHELL_GROUP_RIGHT = ')'
|
|
|
|
|
|
|
|
|
|
def checksum(self, path, python_interp):
|
|
|
|
|
display.deprecated(
|
|
|
|
|
"The 'ShellModule.checksum' method is deprecated. Use 'ActionBase._execute_remote_stat()' instead.",
|
|
|
|
|
version="2.23"
|
|
|
|
|
)
|
|
|
|
|
# In the following test, each condition is a check and logical
|
|
|
|
|
# comparison (|| or &&) that sets the rc value. Every check is run so
|
|
|
|
|
# the last check in the series to fail will be the rc that is returned.
|
|
|
|
|
@ -67,11 +75,7 @@ class ShellModule(ShellBase):
|
|
|
|
|
# "one-liner".
|
|
|
|
|
shell_escaped_path = self.quote(path)
|
|
|
|
|
test = "rc=flag; [ -r %(p)s ] %(shell_or)s rc=2; [ -f %(p)s ] %(shell_or)s rc=1; [ -d %(p)s ] %(shell_and)s rc=3; %(i)s -V 2>/dev/null %(shell_or)s rc=4; [ x\"$rc\" != \"xflag\" ] %(shell_and)s echo \"${rc} \"%(p)s %(shell_and)s exit 0" % dict(p=shell_escaped_path, i=python_interp, shell_and=self._SHELL_AND, shell_or=self._SHELL_OR) # NOQA
|
|
|
|
|
csums = [
|
|
|
|
|
u"({0} -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL), # NOQA Python > 2.4 (including python3)
|
|
|
|
|
u"({0} -c 'import sha; BLOCKSIZE = 65536; hasher = sha.sha();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL), # NOQA Python == 2.4
|
|
|
|
|
]
|
|
|
|
|
cmd = "({0} -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL) # NOQA
|
|
|
|
|
|
|
|
|
|
cmd = (" %s " % self._SHELL_OR).join(csums)
|
|
|
|
|
cmd = "%s; %s %s (echo \'0 \'%s)" % (test, cmd, self._SHELL_OR, shell_escaped_path)
|
|
|
|
|
return cmd
|
|
|
|
|
|