PageRenderTime 377ms CodeModel.GetById 203ms app.highlight 63ms RepoModel.GetById 108ms app.codeStats 0ms

/Mac/Demo/resources/listres.py

http://unladen-swallow.googlecode.com/
Python | 60 lines | 51 code | 8 blank | 1 comment | 13 complexity | b294fbdfcefa061a3ff5eafe922354f4 MD5 | raw file
 1# List all resources
 2
 3from Carbon import Res
 4from Carbon.Resources import *
 5
 6def list1resources():
 7    ntypes = Res.Count1Types()
 8    for itype in range(1, 1+ntypes):
 9        type = Res.Get1IndType(itype)
10        print "Type:", repr(type)
11        nresources = Res.Count1Resources(type)
12        for i in range(1, 1 + nresources):
13            Res.SetResLoad(0)
14            res = Res.Get1IndResource(type, i)
15            Res.SetResLoad(1)
16            info(res)
17
18def listresources():
19    ntypes = Res.CountTypes()
20    for itype in range(1, 1+ntypes):
21        type = Res.GetIndType(itype)
22        print "Type:", repr(type)
23        nresources = Res.CountResources(type)
24        for i in range(1, 1 + nresources):
25            Res.SetResLoad(0)
26            res = Res.GetIndResource(type, i)
27            Res.SetResLoad(1)
28            info(res)
29
30def info(res):
31    print res.GetResInfo(), res.SizeResource(), decodeattrs(res.GetResAttrs())
32
33attrnames = {
34        resChanged:     'Changed',
35        resPreload:     'Preload',
36        resProtected:   'Protected',
37        resLocked:      'Locked',
38        resPurgeable:   'Purgeable',
39        resSysHeap:     'SysHeap',
40}
41
42def decodeattrs(attrs):
43    names = []
44    for bit in range(16):
45        mask = 1<<bit
46        if attrs & mask:
47            if attrnames.has_key(mask):
48                names.append(attrnames[mask])
49            else:
50                names.append(hex(mask))
51    return names
52
53def test():
54    print "=== Local resourcess ==="
55    list1resources()
56    print "=== All resources ==="
57    listresources()
58
59if __name__ == '__main__':
60    test()