Completed
Push — master ( fe49eb...265317 )
by W
06:11
created

main()   A

Complexity

Conditions 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.4286
cc 2
1
#!/usr/bin/env python
2
3
import shlex
4
import sys
5
import subprocess
6
import lib.datatransformer as transformer
7
8
9
def main(args):
10
    command_list = shlex.split('apt-cache policy ' + ' '.join(args[1:]))
11
    process = subprocess.Popen(command_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
12
    command_stdout, command_stderr = process.communicate()
13
    command_exitcode = process.returncode
14
    try:
15
        payload = transformer.to_json(command_stdout, command_stderr, command_exitcode)
16
    except Exception as e:
17
        sys.stderr.write('JSON conversion failed. %s' % str(e))
18
        sys.exit(1)
19
20
    sys.stdout.write(payload)
21
22
if __name__ == '__main__':
23
    main(sys.argv)
24