Synopsis - Synopsis/Formatters/HTML/Fragments/ClassHierarchyGraph.py

File: Synopsis/Formatters/HTML/Fragments/ClassHierarchyGraph.py

     1#
     2# Copyright (C) 2000 Stephen Davies
     3# Copyright (C) 2000 Stefan Seefeld
     4# All rights reserved.
     5# Licensed to the public under the terms of the GNU LGPL (>= 2),
     6# see the file COPYING for details.
     7#
     8
     9from Synopsis import IR
    10from Synopsis import ASG
    11from Synopsis.Processor import InvalidCommand
    12from ClassHierarchySimple import ClassHierarchySimple
    13import os
    14
    15class ClassHierarchyGraph(ClassHierarchySimple):
    16    """Prints a graphical hierarchy for classes, using the Dot formatter.
    17
    18    @see Formatters.Dot
    19    """
    20    def format_class(self, class_):
    21
    22        from Synopsis.Formatters import Dot
    23        super = self.processor.class_tree.superclasses(class_.name)
    24        sub = self.processor.class_tree.subclasses(class_.name)
    25        if len(super) == 0 and len(sub) == 0:
    26            # Skip classes with a boring graph
    27            return ''
    28        #label = self.processor.files.scoped_special('inheritance', clas.name)
    29        label = self.formatter.filename()[:-5] + '-inheritance.html'
    30        tmp = os.path.join(self.processor.output, label)
    31        ir = IR.IR(files={}, asg=ASG.ASG([class_], self.processor.ir.asg.types))
    32        dot = Dot.Formatter(bgcolor=self.processor.graph_color)
    33        dot.toc = self.processor.toc
    34        try:
    35            dot.process(ir,
    36                        output=tmp,
    37                        format='html',
    38                        base_url=self.formatter.filename(),
    39                        type='single',
    40                        title=label)
    41            text = ''
    42            input = open(tmp, "r+")
    43            line = input.readline()
    44            while line:
    45                text = text + line
    46                line = input.readline()
    47            input.close()
    48            os.unlink(tmp)
    49            return text
    50        except InvalidCommand, e:
    51            print 'Warning : %s'%str(e)
    52            return ''
    53
    54    format_class_template = format_class
    55

Generated on Thu Apr 16 16:27:14 2009 by
synopsis (version devel)