|
| 1 | +import argparse |
| 2 | +import inspect |
| 3 | +import os |
| 4 | +import pathlib |
| 5 | +import re |
| 6 | +import shlex |
| 7 | +import subprocess |
| 8 | +import sys |
| 9 | +from typing import Optional |
| 10 | +from typing import Sequence |
| 11 | +from typing import Set |
| 12 | +from importlib import import_module |
| 13 | +from itertools import count |
1 | 14 |
|
| 15 | + |
| 16 | +def run_command(command: str) -> int: |
| 17 | + process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE) |
| 18 | + |
| 19 | + try: |
| 20 | + outs, errs = process.communicate(timeout=30) |
| 21 | + if outs: |
| 22 | + print(outs.decode('utf8').strip(), file=sys.stdout) |
| 23 | + if errs: |
| 24 | + print(errs, file=sys.stdout) |
| 25 | + except subprocess.TimeoutExpired: |
| 26 | + process.kill() |
| 27 | + outs, errs = process.communicate() |
| 28 | + if outs: |
| 29 | + print(outs.decode('utf8').strip(), file=sys.stdout) |
| 30 | + if errs: |
| 31 | + print(errs, file=sys.stdout) |
| 32 | + rc = process.poll() |
| 33 | + return rc |
| 34 | + |
| 35 | + |
| 36 | +def main(argv: Optional[Sequence[str]] = None): |
| 37 | + parser = argparse.ArgumentParser() |
| 38 | + parser.add_argument('--python-version', default='3.6') |
| 39 | + parser.add_argument('--settings', default='') |
| 40 | + args = parser.parse_args(argv) |
| 41 | + |
| 42 | + command = 'python{} manage.py graphql_schema'.format(args.python_version) |
| 43 | + |
| 44 | + if args.settings: |
| 45 | + command += ' --settings={}'.format(args.settings) |
| 46 | + |
| 47 | + return run_command(command) |
| 48 | + |
| 49 | + |
| 50 | +if __name__ == '__main__': |
| 51 | + exit(main()) |
0 commit comments