Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit 4bc7c0b

Browse files
authored
Update graphene_django_hook.py
1 parent 2a53629 commit 4bc7c0b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

graphene_django_hook.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,51 @@
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
114

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

Comments
 (0)