Skip to content

Commit ad6ae24

Browse files
committed
made print() call Py3 compliant, added checks for Py execs
1 parent 64d8715 commit ad6ae24

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

Diff for: tasks/read_file.json

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
}
88
},
99
"implementations": [
10-
{"name": "read_file.rb", "requirements": ["puppet-agent"], "input_method": "stdin"},
1110
{"name": "read_file.sh", "requirements": ["shell"], "input_method": "environment"}
1211
]
1312
}

Diff for: tasks/read_file.sh

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#!/bin/bash
22

33
main() {
4+
local python_exec=""
5+
6+
# check if any python exec is available on the remote system. error out if not
7+
while :; do
8+
python_exec=$(command -v python) && break
9+
python_exec=$(command -v python3) && break
10+
python_exec=$(command -v python2) && break
11+
echo "Error: No Python version 2 or 3 interpreter found."
12+
exit 1
13+
done
14+
415
if [ -r "$PT_path" ]; then
516
cat <<-EOS
617
{
7-
"content": $(python_cmd -c "import json; print json.dumps(open('$PT_path','r').read())")
18+
"content": $(${python_exec} -c "import json; print(json.dumps(open('$PT_path','r').read()))")
819
}
920
EOS
1021
else
@@ -14,17 +25,8 @@ main() {
1425
"error": "File does not exist or is not readable"
1526
}
1627
EOS
17-
fi
18-
}
19-
20-
python_cmd() {
21-
if command -v python >/dev/null 2>&1; then
22-
python "$@"
23-
else
24-
python3 "$@"
28+
exit 1
2529
fi
2630
}
2731

2832
main "$@"
29-
exit_code=$?
30-
exit $exit_code

0 commit comments

Comments
 (0)