Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
07a7353a
Commit
07a7353a
authored
Mar 02, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port changes from #10372 fixing checksumming on csh and backslashes in filenames to v2
parent
85bb01aa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
+15
-4
v2/ansible/plugins/shell/csh.py
+3
-0
v2/ansible/plugins/shell/sh.py
+12
-4
No files found.
v2/ansible/plugins/shell/csh.py
View file @
07a7353a
...
...
@@ -19,5 +19,8 @@ from ansible.runner.shell_plugins.sh import ShellModule as ShModule
class
ShellModule
(
ShModule
):
# How to end lines in a python script one-liner
_SHELL_EMBEDDED_PY_EOL
=
'
\\\n
'
def
env_prefix
(
self
,
**
kwargs
):
return
'env
%
s'
%
super
(
ShellModule
,
self
)
.
env_prefix
(
**
kwargs
)
v2/ansible/plugins/shell/sh.py
View file @
07a7353a
...
...
@@ -24,6 +24,9 @@ _USER_HOME_PATH_RE = re.compile(r'^~[_.A-Za-z0-9][-_.A-Za-z0-9]*$')
class
ShellModule
(
object
):
# How to end lines in a python script one-liner
_SHELL_EMBEDDED_PY_EOL
=
'
\n
'
def
env_prefix
(
self
,
**
kwargs
):
'''Build command prefix with environment variables.'''
env
=
dict
(
...
...
@@ -103,14 +106,19 @@ class ShellModule(object):
# 2: No read permissions on the file
# 3: File is a directory
# 4: No python interpreter
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
)
# Quoting gets complex here. We're writing a python string that's
# used by a variety of shells on the remote host to invoke a python
# "one-liner".
shell_escaped_path
=
pipes
.
quote
(
path
)
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
=
shell_escaped_path
,
i
=
python_interp
)
csums
=
[
"(
%
s -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();
\n
afile = open(
\"
%
s
\"
,
\"
rb
\"
)
\n
buf = afile.read(BLOCKSIZE)
\n
while len(buf) > 0:
\n\t
hasher.update(buf)
\n\t
buf = afile.read(BLOCKSIZE)
\n
afile.close()
\n
print(hasher.hexdigest())' 2>/dev/null)"
%
(
python_interp
,
path
),
# Python > 2.4 (including python3)
"(
%
s -c 'import sha; BLOCKSIZE = 65536; hasher = sha.sha();
\n
afile = open(
\"
%
s
\"
,
\"
rb
\"
)
\n
buf = afile.read(BLOCKSIZE)
\n
while len(buf) > 0:
\n\t
hasher.update(buf)
\n\t
buf = afile.read(BLOCKSIZE)
\n
afile.close()
\n
print(hasher.hexdigest())' 2>/dev/null)"
%
(
python_interp
,
path
),
# Python == 2.4
"(
{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}
\t
hasher.update(buf){2}
\t
buf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)"
.
format
(
python_interp
,
shell_escaped_path
,
self
.
_SHELL_EMBEDDED_PY_EOL
),
# Python > 2.4 (including python3)
"(
{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}
\t
hasher.update(buf){2}
\t
buf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)"
.
format
(
python_interp
,
shell_escaped_path
,
self
.
_SHELL_EMBEDDED_PY_EOL
),
# Python == 2.4
]
cmd
=
" || "
.
join
(
csums
)
cmd
=
"
%
s;
%
s || (echo
\'
0
%
s
\'
)"
%
(
test
,
cmd
,
path
)
cmd
=
"
%
s;
%
s || (echo
\'
0
\'
%
s)"
%
(
test
,
cmd
,
shell_escaped_
path
)
return
cmd
def
build_module_command
(
self
,
env_string
,
shebang
,
cmd
,
rm_tmp
=
None
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment