1 """Creation of PYC resources"""
11 """Return a pascal-style string from a python-style string"""
13 raise ValueError, 'String too large'
14 return chr(len(str))+str
16 def create(dst
, creator
='Pyth'):
17 """Create output file. Return handle and first id to use."""
23 Res
.FSpCreateResFile(dst
, creator
, 'rsrc', smAllScripts
)
27 output
= Res
.FSpOpenResFile(dst
, WRITE
)
28 Res
.UseResFile(output
)
31 def writemodule(name
, id, data
, type='PYC '):
32 """Write pyc code to a PYC resource with given name and id."""
33 # XXXX Check that it doesn't exist
34 res
= Res
.Resource(data
)
35 res
.AddResource(type, id, name
)
39 def frompycfile(file, name
=None):
40 """Copy one pyc file to the open resource file"""
42 d
, name
= os
.path
.split(file)
45 writemodule(name
, id, __builtin__
.open(file, 'rb').read())
48 def frompyfile(file, name
=None):
49 """Compile python source file to pyc file and add to resource file"""
52 py_compile
.compile(file)
54 return frompycfile(file, name
)
56 # XXXX Note this is incorrect, it only handles one type and one file....
60 def findfreeid(type='PYC '):
61 """Find next free id-number for given resource type"""
64 if _firstfreeid
== None:
67 num
= Res
.Count1Resources(type)
68 for i
in range(1, num
+1):
69 r
= Res
.Get1IndResource(type, i
)
70 id, d1
, d2
= r
.GetResInfo()
71 highest
= max(highest
, id)
73 _firstfreeid
= highest
+1
75 _firstfreeid
= _firstfreeid
+1