[Zope3-checkins] CVS: Packages/ZConfig - info.py:1.1.2.20
Fred L. Drake, Jr.
fred@zope.com
Tue, 24 Dec 2002 13:36:43 -0500
Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv25877
Modified Files:
Tag: zconfig-schema-devel-branch
info.py
Log Message:
Add some utility functions to make examining a schema a little easier.
=== Packages/ZConfig/info.py 1.1.2.19 => 1.1.2.20 ===
--- Packages/ZConfig/info.py:1.1.2.19 Mon Dec 23 10:56:40 2002
+++ Packages/ZConfig/info.py Tue Dec 24 13:36:12 2002
@@ -222,7 +222,7 @@
self.datatype = datatype
self.keytype = keytype
self.valuetype = valuetype
- self._children = [] # [info, ...]
+ self._children = [] # [(key, info), ...]
self._attrmap = {} # {attribute: index, ...}
self._keymap = {} # {key: index, ...}
@@ -268,6 +268,21 @@
def getchildnames(self):
return [key for (key, info) in self._children]
+ def getrequiredtypes(self):
+ d = {}
+ if self.name:
+ d[self.name] = 1
+ stack = [self]
+ while stack:
+ info = stack.pop()
+ for key, ci in info._children:
+ if ci.issection():
+ t = ci.sectiontype
+ if not d.has_key(t.name):
+ d[t.name] = 1
+ stack.append(t)
+ return d.keys()
+
def getsectionindex(self, type, name):
index = -1
for key, info in self._children:
@@ -336,3 +351,12 @@
def issection(self):
return True
+
+ def getunusedtypes(self):
+ alltypes = self.gettypenames()
+ reqtypes = self.getrequiredtypes()
+ for n in reqtypes:
+ alltypes.remove(n)
+ if self.name and self.name in alltypes:
+ alltypes.remove(self.name)
+ return alltypes