-
Notifications
You must be signed in to change notification settings - Fork 2
/
regenerate-model-svg.py
executable file
·60 lines (41 loc) · 1.2 KB
/
regenerate-model-svg.py
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
50
51
52
53
54
55
56
57
58
59
60
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import django
from django.apps import apps
import subprocess
os.environ['DJANGO_SETTINGS_MODULE'] = 'pdc.settings_graph_models'
file_contents = '''.. _model_graphs:
PDC Model Graphs
================
Current PDC Model Graphs:
'''
SECTION = '''
{0}
{1}
.. image:: models_svg/{0}.svg
'''
def run_cmd(args):
print(' '.join(args))
res = subprocess.call(args)
if res != 0:
print('Failed')
sys.exit(1)
django.setup()
run_cmd(['python', 'manage.py', 'graph_models', '-aE',
'-o', 'docs/source/models_svg/overview.svg'])
file_contents += SECTION.format('overview', '-' * len('overview'))
for app in sorted(apps.get_apps(), key=lambda x: x.__name__):
if not app.__name__.startswith('pdc.'):
continue
try:
_, _, name, _ = app.__name__.split('.')
except ValueError:
sys.exit(1)
run_cmd(['python', 'manage.py', 'graph_models', '-gE', name,
'-o', 'docs/source/models_svg/{}.svg'.format(name)])
file_contents += SECTION.format(name, '-' * len(name))
with open('docs/source/model_graphs.rst', 'w') as f:
f.write(file_contents)