Improved functionality for the web based GUI interface

parent 267e6232
...@@ -145,24 +145,11 @@ def _get_parser(): ...@@ -145,24 +145,11 @@ def _get_parser():
action="store_true", action="store_true",
dest="withfiles") dest="withfiles")
tree.add_argument( tree.add_argument(
"--graphviz", "--mode",
dest="graphviz", dest="mode",
default=None, default="mods",
help="qctivate graphviz and specify the program to be used to plot " help="set the working mode for the tree generator: "
"the graph (twopi, gvcolor, wc, ccomps, tred, sccmap, fdp, " "(mods, dfs, bfs)")
"circo, neato, acyclic, nop, gvpr, dot, sfdp)")
tree.add_argument(
"--web",
help="export the tree hierarchy in a web friendly JSON format",
default=False,
action="store_true",
dest="web")
tree.add_argument(
"--solved",
help="enable the parser",
default=False,
action="store_true",
dest="solved")
subparsers.add_parser( subparsers.add_parser(
"manifest-help", "manifest-help",
help="print manifest file variables description") help="print manifest file variables description")
......
...@@ -27,6 +27,7 @@ from hdlmake.util import path ...@@ -27,6 +27,7 @@ from hdlmake.util import path
import logging import logging
from .action import Action from .action import Action
from hdlmake.dep_file import DepFile
class ActionTree(Action): class ActionTree(Action):
...@@ -38,41 +39,22 @@ class ActionTree(Action): ...@@ -38,41 +39,22 @@ class ActionTree(Action):
def _generate_tree_web(self, hierarchy, top_id): def _generate_tree_web(self, hierarchy, top_id):
"""Create a JSON file containing the graph hierarchy from pool""" """Create a JSON file containing the graph hierarchy from pool"""
if self.options.web: try:
try: import json
import json import networkx as nx
from networkx.readwrite import json_graph from networkx.readwrite import json_graph
except ImportError as error_import: except ImportError as error_import:
logging.error(error_import) logging.error(error_import)
quit() quit()
data = json_graph.tree_data(hierarchy, root=top_id) if self.options.mode == 'dfs':
json_string = json.dumps(data) hierarchy = nx.dfs_tree(hierarchy, top_id)
json_file = open("hierarchy.json", "w") elif self.options.mode == 'bfs':
json_file.write(json_string) hierarchy = nx.bfs_tree(hierarchy, top_id, reverse=False)
json_file.close() data = json_graph.tree_data(hierarchy, root=top_id)
json_string = json.dumps(data)
def _generate_tree_graphviz(self, hierarchy, top_id): json_file = open("hierarchy.json", "w")
"""Define the program used to write the graphviz: json_file.write(json_string)
Program should be one of: json_file.close()
twopi, gvcolor, wc, ccomps, tred, sccmap, fdp,
circo, neato, acyclic, nop, gvpr, dot, sfdp
"""
if self.options.graphviz:
try:
import matplotlib.pyplot as plt
import networkx as nx
except ImportError as error_import:
logging.error(error_import)
quit()
pos = nx.graphviz_layout(hierarchy,
prog=self.options.graphviz,
root=top_id)
nx.draw(hierarchy, pos,
with_labels=True,
alpha=0.5,
node_size=100)
plt.savefig("hierarchy.png")
plt.show()
def generate_tree(self): def generate_tree(self):
"""Generate the graph from pool and create the requested outcomes""" """Generate the graph from pool and create the requested outcomes"""
...@@ -84,9 +66,7 @@ class ActionTree(Action): ...@@ -84,9 +66,7 @@ class ActionTree(Action):
unfetched_modules = False unfetched_modules = False
hierarchy = nx.DiGraph() hierarchy = nx.DiGraph()
if self.options.solved: if self.options.mode == "mods":
logging.warning("This is the solved tree")
else:
for mod_aux in self: for mod_aux in self:
if not mod_aux.isfetched: if not mod_aux.isfetched:
unfetched_modules = True unfetched_modules = True
...@@ -97,14 +77,49 @@ class ActionTree(Action): ...@@ -97,14 +77,49 @@ class ActionTree(Action):
else: else:
hierarchy.add_node(mod_aux.path) hierarchy.add_node(mod_aux.path)
top_id = mod_aux.path top_id = mod_aux.path
if self.options.withfiles: if len(mod_aux.files):
if len(mod_aux.files): for file_aux in mod_aux.files:
for file_aux in mod_aux.files: hierarchy.add_edge(mod_aux.path,
hierarchy.add_edge(mod_aux.path, path.relpath(file_aux.path))
path.relpath(file_aux.path)) elif (self.options.mode == 'dfs' or
self.options.mode == 'bfs'):
logging.warning("This is the solved tree")
#self.top_entity = self.options.top
self.build_file_set()
self.solve_file_set()
from hdlmake.srcfile import SourceFileSet
from hdlmake.dep_file import DepRelation
assert isinstance(self.parseable_fileset, SourceFileSet)
fset = self.parseable_fileset.filter(DepFile)
# Find the file that provides the named top level entity
top_rel_vhdl = DepRelation(
"%s.%s" %
("work", self.top_entity), DepRelation.PROVIDE, DepRelation.ENTITY)
top_rel_vlog = DepRelation(
"%s.%s" %
("work", self.top_entity), DepRelation.PROVIDE, DepRelation.MODULE)
top_file = None
for chk_file in fset:
hierarchy.add_node(path.relpath(chk_file.path))
for file_required in chk_file.depends_on:
hierarchy.add_edge(path.relpath(chk_file.path), path.relpath(file_required.path))
for rel in chk_file.rels:
if (rel == top_rel_vhdl) or (rel == top_rel_vlog):
top_file = chk_file
top_id = path.relpath(chk_file.path)
if top_file is None:
logging.critical('Could not find a top level file that provides the '
'top_module="%s". Continuing with the full file set.',
top_level_entity)
else:
logging.error('Unknown tree mode: %s', self.options.mode)
quit()
if unfetched_modules: if unfetched_modules:
logging.warning("Some of the modules have not been fetched!") logging.warning("Some of the modules have not been fetched!")
self._generate_tree_web(hierarchy, top_id) self._generate_tree_web(hierarchy, top_id)
self._generate_tree_graphviz(hierarchy, top_id)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment