File: custom_python_want_json_module.py

package info (click to toggle)
python-mitogen 0.3.26-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,456 kB
  • sloc: python: 22,134; sh: 183; makefile: 74; perl: 19; ansic: 18
file content (40 lines) | stat: -rwxr-xr-x 749 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
# I am an Ansible Python WANT_JSON module. I should receive a JSON-encoded file.

import json
import sys


WANT_JSON = 1


def usage():
    sys.stderr.write('Usage: %s <input.json>\n' % (sys.argv[0],))
    sys.exit(1)

if len(sys.argv) < 2:
    usage()

# Also must slurp in our own source code, to verify the encoding string was
# added.
fp = open(sys.argv[0])
try:
    me = fp.read()
finally:
    fp.close()

try:
    fp = open(sys.argv[1])
    try:
        input_json = fp.read()
    finally:
        fp.close()
except IOError:
    usage()

print("{")
print("  \"changed\": false,")
print("  \"msg\": \"Here is my input\",")
print("  \"source\": [%s]," % (json.dumps(me),))
print("  \"input\": [%s]" % (input_json,))
print("}")