File: console.py

package info (click to toggle)
turing 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,340 kB
  • sloc: python: 106,582; xml: 101; makefile: 53; sh: 29
file content (49 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (4)
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
41
42
43
44
45
46
47
48
49
"""
This script wraps the execution of console program so that a prompt appear
after the end of the console program (so that the console does not close as
soon as the user program finished).


Usage:
    pyqode-console program [options]

Example:

    $ pyqode-console python /path/to/a/script.py --spam eggs
    $ ...
    $ The process terminated with exit code 0.
    $ Press a key to close this window...
    $
"""
import os
import sys
import subprocess


def main():
    """
    pyqode-console main function.
    """
    global program, args, ret
    print(os.getcwd())
    ret = 0
    if '--help' in sys.argv or '-h' in sys.argv or len(sys.argv) == 1:
        print(__doc__)
    else:
        program = sys.argv[1]
        args = sys.argv[2:]
        if args:
            ret = subprocess.call([program] + args)
        else:
            ret = subprocess.call([program])
    print('\nProcess terminated with exit code %d' % ret)
    prompt = 'Press ENTER to close this window...'
    if sys.version_info[0] == 3:
        input(prompt)
    else:
        raw_input(prompt)
    sys.exit(ret)


if __name__ == '__main__':
    main()