1414import marshal
1515import imp
1616import macfs
17+ import MACFS
1718import MacOS
1819from Res import *
1920
@@ -42,18 +43,16 @@ def main():
4243 for p in sys .path :
4344 template = os .path .join (p , TEMPLATE )
4445 try :
45- tmpl = open (template , "rb" )
46- tmpl .close ()
46+ template , d1 , d2 = macfs .ResolveAliasFile (template )
4747 break
48- except IOError :
48+ except ( macfs . error , ValueError ) :
4949 continue
5050 else :
51- die ("Template %s not found" % `template ` )
51+ die ("Template %s not found on sys.path " % `TEMPLATE ` )
5252 return
53-
54- # Convert to full pathname
55- template = macfs .FSSpec (template ).as_pathname ()
56-
53+ template = template .as_pathname ()
54+ print 'Using template' , template
55+
5756 # Ask for source text if not specified in sys.argv[1:]
5857
5958 if not sys .argv [1 :]:
@@ -106,6 +105,10 @@ def process(template, filename, output):
106105 destname = output
107106 # Copy the data from the template (creating the file as well)
108107
108+ template_fss = macfs .FSSpec (template )
109+ template_fss , d1 , d2 = macfs .ResolveAliasFile (template_fss )
110+ dest_fss = macfs .FSSpec (destname )
111+
109112 tmpl = open (template , "rb" )
110113 dest = open (destname , "wb" )
111114 data = tmpl .read ()
@@ -117,23 +120,23 @@ def process(template, filename, output):
117120 # Copy the creator of the template to the destination
118121 # unless it already got one. Set type to APPL
119122
120- tctor , ttype = MacOS . GetCreatorAndType ( template )
121- ctor , type = MacOS . GetCreatorAndType ( destname )
123+ tctor , ttype = template_fss . GetCreatorType ( )
124+ ctor , type = dest_fss . GetCreatorType ( )
122125 if type in undefs : type = 'APPL'
123126 if ctor in undefs : ctor = tctor
124127
125128 # Open the output resource fork
126129
127130 try :
128- output = FSpOpenResFile (destname , WRITE )
131+ output = FSpOpenResFile (dest_fss , WRITE )
129132 except MacOS .Error :
130133 print "Creating resource fork..."
131134 CreateResFile (destname )
132- output = FSpOpenResFile (destname , WRITE )
135+ output = FSpOpenResFile (dest_fss , WRITE )
133136
134137 # Copy the resources from the template
135138
136- input = FSpOpenResFile (template , READ )
139+ input = FSpOpenResFile (template_fss , READ )
137140 newctor = copyres (input , output )
138141 CloseResFile (input )
139142 if newctor : ctor = newctor
@@ -149,9 +152,13 @@ def process(template, filename, output):
149152 CloseResFile (input )
150153 if newctor : ctor = newctor
151154
152- # Now set the creator and type of the destination
153-
154- MacOS .SetCreatorAndType (destname , ctor , type )
155+ # Now set the creator, type and bundle bit of the destination
156+ dest_finfo = dest_fss .GetFInfo ()
157+ dest_finfo .Creator = ctor
158+ dest_finfo .Type = type
159+ dest_finfo .Flags = dest_finfo .Flags | MACFS .kHasBundle
160+ dest_finfo .Flags = dest_finfo .Flags & ~ MACFS .kHasBeenInited
161+ dest_fss .SetFInfo (dest_finfo )
155162
156163 # Make sure we're manipulating the output resource file now
157164
0 commit comments