-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAresWrapper.py
124 lines (95 loc) · 3.78 KB
/
AresWrapper.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
""" Local wrapper to be able to produce static reports locally without server
From this mode the framework will generate a static html page.
This will allow to produce statics reports and to share the page even without any access to the network
Some external Javascript and CSS libraries are required to be able to run the tool fully locally
Do not use True in both python and Javascript as the Json conversion is not really optimal. Please use boolean instead
"""
import os
import sys
import Ares
# CSS imports
CSS = ['jquery-ui.css',
'bootstrap.css',
'bootstrap.min.css',
'bootstrap-theme.min.css',
'nv.d3.css',
'bootstrap-select.min.css'
]
# Javascript imports
JS = ['jquery-3.2.1.min.js',
'jquery-ui.min.js',
'bootstrap.min.js',
'bootstrap-select.min.js',
'd3.v3.js',
'nv.d3.js', # The mimifyed version does not contain indentedTree objects. https://stackoverflow.com/questions/35452946/not-running-minimal-example-of-indentedtree
'd3.layout.cloud.js' # world cloud chart
]
def components(directory):
""" Return the list of all the available components """
import inspect
import Ares
import AresHtml
import AresGraph
htmlObject = []
for name, obj in inspect.getmembers(AresHtml):
if inspect.isclass(obj) and obj.alias is not None:
htmlObject.append((name, obj.__doc__))
htmlFile = open(r"%s\ArES_components.html" % directory, "w")
aresObj = Ares.Report()
aresObj.title(2, "Html Components")
aresObj.table(['Class Name', 'Description'], htmlObject)
graphObject = []
for name, obj in inspect.getmembers(AresGraph):
if inspect.isclass(obj):
graphObject.append((name, obj.__doc__))
aresObj.title(2, "Graph Components")
aresObj.table(['Class Name', 'Description'], graphObject)
htmlPage(htmlFile, aresObj.html(directory, title='ArES Components'))
htmlFile.close()
sys.exit()
def test(className, directory):
""" Test a component based on Mock Json data
"""
import Ares
import AresGraph
import AresHtml
import inspect
import json
aresComponents = {}
for name, obj in inspect.getmembers(AresHtml):
if inspect.isclass(obj):
aresComponents[name] = obj
for name, obj in inspect.getmembers(AresGraph):
if inspect.isclass(obj):
aresComponents[name] = obj
htmlFile = open(r"%s\ArES_%s.html" % (directory, className), "w")
aresObj = Ares.Report()
aresObj.title(2, "%s Components" % className)
object = aresComponents[className]
aresObj.text(object.__doc__)
with open(r"%s\%s" % (directory, object.mockData)) as data_file:
data = json.load(data_file)
aresObj.comboLineBar(data)
aresObj.title(2, 'Source Code')
aId = aresObj.anchor('Data Source', object.mockData)
aresObj.paragraph('You can download the input data here: {0}', [aresObj.item(aId)])
compObj = aresComponents[className](0, data)
aresObj.code(compObj.js())
htmlPage(htmlFile, aresObj.html(directory, title='ArES Components'))
htmlFile.close()
sys.exit()
if __name__ == '__main__':
# Run the script locally
statisPath = r'' # the path with the CSS and JS folders (if current path please keep this empty
directory = os.getcwd() # The path of this script by default
report = "MyRepotTest" # The name of the main script with the report
# -----------------------------------------------------------------------------------------------
# Test functions
# -----------------------------------------------------------------------------------------------
# Get a description of the different available items
#components(directory)
#test('ComboLineBar', directory)
# Write the report
htmlPage = Ares.htmlLocalHeader(directory, report, statisPath, CSS, JS)
htmlPage.write(__import__(report).report(Ares.Report(), localPath=directory))
Ares.htmlLocalFooter(htmlPage)