File: sample_process.py

package info (click to toggle)
doit 0.36.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,704 kB
  • sloc: python: 11,863; makefile: 33; ansic: 14; javascript: 3; sh: 1
file content (37 lines) | stat: -rw-r--r-- 1,272 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/env python3

# tests on CmdTask will use this script as an external process.
# - If you call this script with 3 or more arguments, the process returns
#   exit code (166).
# - If you call this script with arguments "please fail", it returns exit
#   code (11).
# - If you call this script with arguments "check env", it verifies the
#   existence of an environment variable called "GELKIPWDUZLOVSXE", with
#   value "1". If the variable is not found, the process returns exit code (99).
# - Otherwise, any first argument gets written to STDOUT. Any second argument
#   gets written to STDERR.

import os
import sys

if __name__ == "__main__":
    # error
    if len(sys.argv) > 3:
        sys.exit(166)
    # fail
    if len(sys.argv) == 3 and sys.argv[1]=='please' and sys.argv[2]=='fail':
        sys.stdout.write("out ouch")
        sys.stderr.write("err output on failure")
        sys.exit(11)
    # check env
    if len(sys.argv) == 3 and sys.argv[1]=='check' and sys.argv[2]=='env':
        if os.environ.get('GELKIPWDUZLOVSXE') == '1':
            sys.exit(0)
        else:
            sys.exit(99)
    # ok
    if len(sys.argv) > 1:
        sys.stdout.write(sys.argv[1])
    if len(sys.argv) > 2:
        sys.stderr.write(sys.argv[2])
    sys.exit(0)