append(): Fixing the test for convertability after consultation with
[python/dscho.git] / Mac / Lib / test / cmtest.py
blobbdbca23d307266ffea13895724d4aa5b51fa8aab
1 """cmtest - List all components in the system"""
3 from Carbon import Cm
4 from Carbon import Res
5 from Carbon import sys
7 def getstr255(r):
8 """Get string from str255 resource"""
9 if not r.data: return ''
10 len = ord(r.data[0])
11 return r.data[1:1+len]
13 def getinfo(c):
14 """Return (type, subtype, creator, fl1, fl2, name, description) for component"""
15 h1 = Res.Resource('')
16 h2 = Res.Resource('')
17 h3 = Res.Resource('')
18 type, subtype, creator, fl1, fl2 = c.GetComponentInfo(h1, h2, h3)
19 name = getstr255(h1)
20 description = getstr255(h2)
21 return type, subtype, creator, fl1, fl2, name, description
23 def getallcomponents():
24 """Return list with info for all components, sorted"""
25 any = ('\0\0\0\0', '\0\0\0\0', '\0\0\0\0', 0, 0)
26 c = None
27 rv = []
28 while 1:
29 try:
30 c = Cm.FindNextComponent(c, any)
31 except Cm.Error:
32 break
33 rv.append(getinfo(c))
34 rv.sort()
35 return rv
37 def main():
38 """Print info for all components"""
39 info = getallcomponents()
40 for type, subtype, creator, f1, f2, name, description in info:
41 print '%4.4s %4.4s %4.4s %s 0x%x 0x%x'%(type, subtype, creator, name, f1, f2)
42 print ' ', description
43 sys.exit(1)
45 main()