|
@@ -1,6 +1,7 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
2
|
2
|
|
3
|
3
|
from loader import *
|
|
4
|
+import warnings
|
4
|
5
|
|
5
|
6
|
def refreshdyn():
|
6
|
7
|
import sys
|
|
@@ -24,4 +25,41 @@ def db_init():
|
24
|
25
|
em = Model(EmBackendJson(Settings.em_file))
|
25
|
26
|
em.migrate_handler(mh)
|
26
|
27
|
|
|
28
|
+def em_graph(output_file = None, image_format = None):
|
|
29
|
+ from EditorialModel.model import Model
|
|
30
|
+ from EditorialModel.backend.json_backend import EmBackendJson
|
|
31
|
+ from EditorialModel.backend.graphviz import EmBackendGraphviz
|
|
32
|
+ import subprocess
|
|
33
|
+
|
|
34
|
+ if image_format is None:
|
|
35
|
+ if hasattr(Settings, 'em_graph_format'):
|
|
36
|
+ image_format = Settings.em_graph_format
|
|
37
|
+ else:
|
|
38
|
+ image_format = 'png'
|
|
39
|
+ if output_file is None:
|
|
40
|
+ if hasattr(Settings, 'em_graph_output'):
|
|
41
|
+ output_file = Settings.em_graph_output
|
|
42
|
+ else:
|
|
43
|
+ output_file = '/tmp/em_%s_graph.dot'
|
|
44
|
+ image_format = image_format.lower()
|
|
45
|
+ try:
|
|
46
|
+ output_file = output_file%Settings.sitename
|
|
47
|
+ except TypeError:
|
|
48
|
+ warnings.warn("Bad filename for em_graph output. The filename should be in the form '/foo/bar/file_%s_name.png")
|
|
49
|
+ pass
|
|
50
|
+
|
|
51
|
+ dot_file = output_file+".dot"
|
|
52
|
+
|
|
53
|
+ graphviz_bckend = EmBackendGraphviz(dot_file)
|
|
54
|
+ edmod = Model(EmBackendJson(Settings.em_file))
|
|
55
|
+ graphviz_bckend.save(edmod)
|
|
56
|
+ dot_cmd = [
|
|
57
|
+ "dot",
|
|
58
|
+ "-T%s"%image_format,
|
|
59
|
+ dot_file
|
|
60
|
+ ]
|
|
61
|
+ with open(output_file, "w+") as outfp:
|
|
62
|
+ subprocess.check_call(dot_cmd, stdout=outfp)
|
|
63
|
+ os.unlink(dot_file)
|
|
64
|
+ print("Output image written in file : '%s'" % output_file)
|
27
|
65
|
|