|
1 | 1 | import importlib
|
2 | 2 | import json
|
3 | 3 | from optparse import make_option
|
| 4 | +from distutils.version import StrictVersion |
4 | 5 |
|
| 6 | +from django import get_version as get_django_version |
5 | 7 | from django.core.management.base import BaseCommand, CommandError
|
6 | 8 |
|
| 9 | +LT_DJANGO_1_8 = StrictVersion(get_django_version()) < StrictVersion('1.8') |
7 | 10 |
|
8 |
| -class Command(BaseCommand): |
9 |
| - help = 'Dump Graphene schema JSON to file' |
10 |
| - can_import_settings = True |
| 11 | +if LT_DJANGO_1_8: |
| 12 | + class CommandArguments(BaseCommand): |
| 13 | + option_list = BaseCommand.option_list + ( |
| 14 | + make_option( |
| 15 | + '--schema', |
| 16 | + type=str, |
| 17 | + dest='schema', |
| 18 | + default='', |
| 19 | + help='Django app containing schema to dump, e.g. myproject.core.schema', |
| 20 | + ), |
| 21 | + make_option( |
| 22 | + '--out', |
| 23 | + type=str, |
| 24 | + dest='out', |
| 25 | + default='', |
| 26 | + help='Output file (default: schema.json)' |
| 27 | + ), |
| 28 | + ) |
| 29 | +else: |
| 30 | + class CommandArguments(BaseCommand): |
| 31 | + def add_arguments(self, parser): |
| 32 | + from django.conf import settings |
| 33 | + parser.add_argument( |
| 34 | + '--schema', |
| 35 | + type=str, |
| 36 | + dest='schema', |
| 37 | + default=getattr(settings, 'GRAPHENE_SCHEMA', ''), |
| 38 | + help='Django app containing schema to dump, e.g. myproject.core.schema') |
11 | 39 |
|
12 |
| - option_list = BaseCommand.option_list + ( |
13 |
| - make_option( |
14 |
| - '--schema', |
15 |
| - type=str, |
16 |
| - dest='schema', |
17 |
| - default='', |
18 |
| - help='Django app containing schema to dump, e.g. myproject.core.schema', |
19 |
| - ), |
20 |
| - make_option( |
21 |
| - '--out', |
22 |
| - type=str, |
23 |
| - dest='out', |
24 |
| - default='', |
25 |
| - help='Output file (default: schema.json)' |
26 |
| - ), |
27 |
| - ) |
| 40 | + parser.add_argument( |
| 41 | + '--out', |
| 42 | + type=str, |
| 43 | + dest='out', |
| 44 | + default=getattr(settings, 'GRAPHENE_SCHEMA_OUTPUT', 'schema.json'), |
| 45 | + help='Output file (default: schema.json)') |
28 | 46 |
|
29 |
| - def add_arguments(self, parser): |
30 |
| - from django.conf import settings |
31 |
| - parser.add_argument( |
32 |
| - '--schema', |
33 |
| - type=str, |
34 |
| - dest='schema', |
35 |
| - default=getattr(settings, 'GRAPHENE_SCHEMA', ''), |
36 |
| - help='Django app containing schema to dump, e.g. myproject.core.schema') |
37 | 47 |
|
38 |
| - parser.add_argument( |
39 |
| - '--out', |
40 |
| - type=str, |
41 |
| - dest='out', |
42 |
| - default=getattr(settings, 'GRAPHENE_SCHEMA_OUTPUT', 'schema.json'), |
43 |
| - help='Output file (default: schema.json)') |
| 48 | +class Command(CommandArguments): |
| 49 | + help = 'Dump Graphene schema JSON to file' |
| 50 | + can_import_settings = True |
44 | 51 |
|
45 | 52 | def save_file(self, out, schema_dict):
|
46 | 53 | with open(out, 'w') as outfile:
|
|
0 commit comments