Do not include attributes which are inherited.
authorTim Ansell <mithro@gmail.com>
Sat, 25 Oct 2008 22:28:31 +0000
changeset 417 a88affc13f98
parent 416 99771d263391
child 418 e035f31d131e
Do not include attributes which are inherited. Also some extra comments. Review URL: http://codereviews.googleopensourceprograms.com/1603
scripts/graph.py
--- a/scripts/graph.py	Sat Oct 25 22:26:34 2008 +0000
+++ b/scripts/graph.py	Sat Oct 25 22:28:31 2008 +0000
@@ -62,6 +62,7 @@
         if not isinstance(klass, TypeType):
           continue
 
+        # Create arrows to the parent classes
         for parent in klass.__bases__:
           G.add_edge(klassname, parent.__name__)
           edge = G.get_edge(klassname, parent.__name__)
@@ -71,7 +72,10 @@
         attrs = ""
         for attrname in dir(klass):
           attr = getattr(klass, attrname)
+
+          # Is it an appengine datastore type?
           if type(attr) in google.appengine.ext.db.__dict__.values():
+            # References get arrows to the other class
             if isinstance(attr, google.appengine.ext.db.ReferenceProperty):
               hasa = attr.reference_class.__name__
               G.add_edge(hasa, klassname)
@@ -79,14 +83,21 @@
               edge.attr['arrowhead'] = 'inv'
 
               refs += "+ %s: %s\l" % (attrname, type(attr).__name__[:-8])
+            
+            # Ignore back references
             elif isinstance(attr, google.appengine.ext.db._ReverseReferenceProperty):
               pass
             else:
-              attrs += "+ %s: %s\l" % (attrname, type(attr).__name__[:-8])
+              # Check that the property is not inherited for a parent class
+              local = True
+              for parent in klass.__bases__:
+                if hasattr(parent, attrname):
+                  local = False
+
+              if local:
+                attrs += "+ %s: %s\l" % (attrname, type(attr).__name__[:-8])
         label = "{%s|%s|%s}" % (klassname, attrs, refs)
 
-        print label
-
         G.add_node(klassname)
         node = G.get_node(klassname)
         node.attr['label'] = label