From 0bd973c335dd56a198c05cc2fe2f37c99ac1d961 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Thu, 1 Nov 2012 16:26:09 +0100 Subject: Added -s and -A parameters --- tools/class2dot.py | 48 +++++++++++++++++++++++++++++++++++++++++------- tools/class2html.py | 6 +++++- 2 files changed, 46 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/class2dot.py b/tools/class2dot.py index 43f8db3..b37d048 100755 --- a/tools/class2dot.py +++ b/tools/class2dot.py @@ -95,7 +95,19 @@ class DotExporter(object): if q.name == "ValueMap": print >>self.file, "ValueMap
%s
" % ("".join(q.value)) - def print_class(self, c, display_local = True): + def compare_properties(self, p1, p2): + """ + Compare two properties. Only Name and Description are checked. + """ + if p1.name != p2.name: + return False + d1 = p1.qualifiers.get("Description", None) + d2 = p2.qualifiers.get("Description", None) + if d1.value != d2.value: + return False + return True + + def print_class(self, c, display_local = True, box_only = False): """ Print one class, inc. header. """ @@ -107,17 +119,24 @@ class DotExporter(object): # draw arrow to parent print >>self.file, "\"%s\"->\"%s\"" % (c.classname, c.superclass) + if box_only: + return + local_props = [] for name in sorted(c.properties.keys()): if parent and parent.properties.has_key(name): - pass + if not self.compare_properties(c.properties[name], parent.properties[name]): + # the property was overridden + local_props.append(c.properties[name]) else: local_props.append(c.properties[name]) local_methods = [] for name in sorted(c.methods.keys()): if parent and parent.methods.has_key(name): - pass + if not self.compare_properties(c.methods[name], parent.methods[name]): + # the property was overridden + local_methods.append(c.methods[name]) else: local_methods.append(c.methods[name]) @@ -140,9 +159,9 @@ class DotExporter(object): def add_class(self, classname): self.classes.add(classname) - def export(self): + def export(self, shrink, noassoc = False): """ - Print all classes and their parent. + Print all classes and their parents. """ print >>self.file, """ digraph "classes_No_Name" { @@ -153,7 +172,16 @@ edge [arrowhead="empty" fontsize=10 fontname="sans-serif"] """ while self.classes: c = self.classes.pop() - self.print_class(self.load_class(c)) + + cl = self.load_class(c) + if noassoc and cl.qualifiers.get("Association", False): + continue + + if shrink and shrink.match(c): + + self.print_class(cl, box_only = True) + else: + self.print_class(cl) print >>self.file, "}" @@ -168,14 +196,20 @@ subclass. parser = optparse.OptionParser(usage="usage: %prog [options] classname [classname ...]", description=description) parser.add_option('-u', '--url', action='store', dest='addr', default='https://localhost:5989', help='URL of CIM server, default: https://localhost:5989') parser.add_option('-U', '--user', action='store', dest='user', default=None, help='CIM user name') +parser.add_option('-s', '--shrink', action='store', dest='shrink', default=None, help='Regular expression pattern of CIM classes, which will be drawn only as boxes, without properties.') +parser.add_option('-A', '--no-associations', action='store_true', dest='noassoc', default=False, help='Skip association classes.') parser.add_option('-P', '--password', action='store', dest='password', default=None, help='CIM password') (options, args) = parser.parse_args() sys.stdout.softspace=0 +shrink = None +if options.shrink: + shrink = re.compile(options.shrink) + cliconn = pywbem.WBEMConnection(options.addr, (options.user, options.password)) exporter = DotExporter(cliconn) for c in args: exporter.add_class(c) -exporter.export() +exporter.export(shrink = shrink, noassoc = options.noassoc) diff --git a/tools/class2html.py b/tools/class2html.py index 2b1f547..24a0366 100755 --- a/tools/class2html.py +++ b/tools/class2html.py @@ -122,7 +122,8 @@ class HtmlExporter(object): if p.qualifiers.has_key("Out"): direction.add("OUT") if p.qualifiers.has_key("In"): - direction.add("IN") + if p.qualifiers["In"].value: + direction.add("IN") if not direction: direction.add("IN") direction = "/".join(sorted(direction)) @@ -205,6 +206,9 @@ class HtmlExporter(object): for name in sorted(c.methods.keys()): if parent and parent.methods.has_key(name): inherited_methods.append(c.methods[name]) + if not self.compare_properties(c.methods[name], parent.methods[name]): + # the property was overridden + local_methods.append(c.methods[name]) else: local_methods.append(c.methods[name]) -- cgit