blob: efc5c47eddca1ec5bd039b492d1916ce436b138f [file] [log] [blame]
Jack Jansen813c9971998-07-31 09:42:35 +00001"""tools for BuildApplet and BuildApplication"""
2
3import sys
4import os
5import string
6import imp
7import marshal
8import macfs
Jack Jansen5a6fdcd2001-08-25 12:15:04 +00009from Carbon import Res
Jack Jansen813c9971998-07-31 09:42:35 +000010import MACFS
11import MacOS
12import macostools
Jack Jansenb2e33fe2002-03-29 21:21:28 +000013import macresource
Jack Jansen813c9971998-07-31 09:42:35 +000014import EasyDialogs
Jack Jansenb2e33fe2002-03-29 21:21:28 +000015import shutil
Jack Jansen813c9971998-07-31 09:42:35 +000016
17
18BuildError = "BuildError"
19
Jack Jansen813c9971998-07-31 09:42:35 +000020# .pyc file (and 'PYC ' resource magic number)
21MAGIC = imp.get_magic()
22
23# Template file (searched on sys.path)
Jack Jansen3b805261999-02-14 23:12:06 +000024TEMPLATE = "PythonInterpreter"
Jack Jansen813c9971998-07-31 09:42:35 +000025
26# Specification of our resource
27RESTYPE = 'PYC '
28RESNAME = '__main__'
29
30# A resource with this name sets the "owner" (creator) of the destination
Jack Jansen81da9f11999-03-17 22:57:55 +000031# It should also have ID=0. Either of these alone is not enough.
Jack Jansen813c9971998-07-31 09:42:35 +000032OWNERNAME = "owner resource"
33
Jack Jansen81da9f11999-03-17 22:57:55 +000034# Default applet creator code
35DEFAULT_APPLET_CREATOR="Pyta"
36
Jack Jansen813c9971998-07-31 09:42:35 +000037# OpenResFile mode parameters
38READ = 1
39WRITE = 2
40
41
Jack Jansena4f8e582001-02-17 23:30:19 +000042def findtemplate(template=None):
Jack Jansen813c9971998-07-31 09:42:35 +000043 """Locate the applet template along sys.path"""
Jack Jansenb2e33fe2002-03-29 21:21:28 +000044 if MacOS.runtimemodel == 'macho':
45 if template:
46 return template
47 return findtemplate_macho()
Jack Jansena4f8e582001-02-17 23:30:19 +000048 if not template:
49 template=TEMPLATE
Jack Jansen813c9971998-07-31 09:42:35 +000050 for p in sys.path:
Jack Jansena4f8e582001-02-17 23:30:19 +000051 file = os.path.join(p, template)
Jack Jansen813c9971998-07-31 09:42:35 +000052 try:
Jack Jansena4f8e582001-02-17 23:30:19 +000053 file, d1, d2 = macfs.ResolveAliasFile(file)
Jack Jansen813c9971998-07-31 09:42:35 +000054 break
55 except (macfs.error, ValueError):
56 continue
57 else:
Jack Jansena4f8e582001-02-17 23:30:19 +000058 raise BuildError, "Template %s not found on sys.path" % `template`
59 file = file.as_pathname()
60 return file
Jack Jansenb2e33fe2002-03-29 21:21:28 +000061
62def findtemplate_macho():
63 execpath = sys.executable.split('/')
64 if not 'Contents' in execpath:
65 raise BuildError, "Not running from a .app bundle: %s" % sys.executable
66 i = execpath.index('Contents')
67 return '/'.join(execpath[:i])
Jack Jansen813c9971998-07-31 09:42:35 +000068
69
Jack Jansen388fbf32002-06-09 22:08:52 +000070def process(template, filename, destname, copy_codefragment,
71 rsrcname=None, others=[], raw=0, progress="default"):
Jack Jansen813c9971998-07-31 09:42:35 +000072
Jack Jansen388fbf32002-06-09 22:08:52 +000073 if progress == "default":
Jack Jansen813c9971998-07-31 09:42:35 +000074 progress = EasyDialogs.ProgressBar("Processing %s..."%os.path.split(filename)[1], 120)
75 progress.label("Compiling...")
Jack Jansen388fbf32002-06-09 22:08:52 +000076 progress.inc(0)
Jack Jansen813c9971998-07-31 09:42:35 +000077
78 # Read the source and compile it
79 # (there's no point overwriting the destination if it has a syntax error)
80
Jack Jansen5d099042002-06-20 20:42:07 +000081 fp = open(filename, 'rU')
Jack Jansen813c9971998-07-31 09:42:35 +000082 text = fp.read()
83 fp.close()
84 try:
85 code = compile(text, filename, "exec")
86 except (SyntaxError, EOFError):
87 raise BuildError, "Syntax error in script %s" % `filename`
88
Jack Jansen388fbf32002-06-09 22:08:52 +000089 # Set the destination file name. Note that basename
90 # does contain the whole filepath, only a .py is stripped.
Jack Jansen813c9971998-07-31 09:42:35 +000091
92 if string.lower(filename[-3:]) == ".py":
Jack Jansen388fbf32002-06-09 22:08:52 +000093 basename = filename[:-3]
94 if MacOS.runtimemodel != 'macho' and not destname:
95 destname = basename
Jack Jansen813c9971998-07-31 09:42:35 +000096 else:
Jack Jansen388fbf32002-06-09 22:08:52 +000097 basename = filename
98
99 if not destname:
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000100 if MacOS.runtimemodel == 'macho':
Jack Jansen388fbf32002-06-09 22:08:52 +0000101 destname = basename + '.app'
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000102 else:
Jack Jansen388fbf32002-06-09 22:08:52 +0000103 destname = basename + '.applet'
104 if not rsrcname:
105 rsrcname = basename + '.rsrc'
106
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000107 # Try removing the output file. This fails in MachO, but it should
108 # do any harm.
Jack Jansen813c9971998-07-31 09:42:35 +0000109 try:
110 os.remove(destname)
111 except os.error:
112 pass
Jack Jansen388fbf32002-06-09 22:08:52 +0000113 process_common(template, progress, code, rsrcname, destname, 0,
114 copy_codefragment, raw, others)
Jack Jansen813c9971998-07-31 09:42:35 +0000115
116
117def update(template, filename, output):
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000118 if MacOS.runtimemodel == 'macho':
119 raise BuildError, "No updating yet for MachO applets"
Jack Jansen388fbf32002-06-09 22:08:52 +0000120 if progress:
Jack Jansen813c9971998-07-31 09:42:35 +0000121 progress = EasyDialogs.ProgressBar("Updating %s..."%os.path.split(filename)[1], 120)
122 else:
123 progress = None
124 if not output:
125 output = filename + ' (updated)'
126
127 # Try removing the output file
128 try:
129 os.remove(output)
130 except os.error:
131 pass
132 process_common(template, progress, None, filename, output, 1, 1)
133
134
Jack Jansen388fbf32002-06-09 22:08:52 +0000135def process_common(template, progress, code, rsrcname, destname, is_update,
136 copy_codefragment, raw=0, others=[]):
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000137 if MacOS.runtimemodel == 'macho':
Jack Jansen388fbf32002-06-09 22:08:52 +0000138 return process_common_macho(template, progress, code, rsrcname, destname,
139 is_update, raw, others)
140 if others:
141 raise BuildError, "Extra files only allowed for MachoPython applets"
Jack Jansen813c9971998-07-31 09:42:35 +0000142 # Create FSSpecs for the various files
143 template_fss = macfs.FSSpec(template)
144 template_fss, d1, d2 = macfs.ResolveAliasFile(template_fss)
145 dest_fss = macfs.FSSpec(destname)
146
147 # Copy data (not resources, yet) from the template
Jack Jansen388fbf32002-06-09 22:08:52 +0000148 if progress:
Jack Jansen813c9971998-07-31 09:42:35 +0000149 progress.label("Copy data fork...")
150 progress.set(10)
151
152 if copy_codefragment:
153 tmpl = open(template, "rb")
154 dest = open(destname, "wb")
155 data = tmpl.read()
156 if data:
157 dest.write(data)
158 dest.close()
159 tmpl.close()
160 del dest
161 del tmpl
162
163 # Open the output resource fork
164
Jack Jansen388fbf32002-06-09 22:08:52 +0000165 if progress:
Jack Jansen813c9971998-07-31 09:42:35 +0000166 progress.label("Copy resources...")
167 progress.set(20)
168 try:
169 output = Res.FSpOpenResFile(dest_fss, WRITE)
170 except MacOS.Error:
Jack Jansen01a2d9e2001-01-29 15:32:00 +0000171 Res.FSpCreateResFile(destname, '????', 'APPL', MACFS.smAllScripts)
Jack Jansen813c9971998-07-31 09:42:35 +0000172 output = Res.FSpOpenResFile(dest_fss, WRITE)
173
174 # Copy the resources from the target specific resource template, if any
175 typesfound, ownertype = [], None
176 try:
177 input = Res.FSpOpenResFile(rsrcname, READ)
178 except (MacOS.Error, ValueError):
179 pass
Jack Jansen388fbf32002-06-09 22:08:52 +0000180 if progress:
Jack Jansen813c9971998-07-31 09:42:35 +0000181 progress.inc(50)
182 else:
183 if is_update:
184 skip_oldfile = ['cfrg']
185 else:
186 skip_oldfile = []
187 typesfound, ownertype = copyres(input, output, skip_oldfile, 0, progress)
188 Res.CloseResFile(input)
189
190 # Check which resource-types we should not copy from the template
Jack Jansen81da9f11999-03-17 22:57:55 +0000191 skiptypes = []
192 if 'vers' in typesfound: skiptypes.append('vers')
Jack Jansen813c9971998-07-31 09:42:35 +0000193 if 'SIZE' in typesfound: skiptypes.append('SIZE')
194 if 'BNDL' in typesfound: skiptypes = skiptypes + ['BNDL', 'FREF', 'icl4',
195 'icl8', 'ics4', 'ics8', 'ICN#', 'ics#']
196 if not copy_codefragment:
197 skiptypes.append('cfrg')
Jack Jansen81da9f11999-03-17 22:57:55 +0000198## skipowner = (ownertype <> None)
Jack Jansen813c9971998-07-31 09:42:35 +0000199
200 # Copy the resources from the template
201
202 input = Res.FSpOpenResFile(template_fss, READ)
Jack Jansen81da9f11999-03-17 22:57:55 +0000203 dummy, tmplowner = copyres(input, output, skiptypes, 1, progress)
204
Jack Jansen813c9971998-07-31 09:42:35 +0000205 Res.CloseResFile(input)
Jack Jansen81da9f11999-03-17 22:57:55 +0000206## if ownertype == None:
207## raise BuildError, "No owner resource found in either resource file or template"
Jack Jansen813c9971998-07-31 09:42:35 +0000208 # Make sure we're manipulating the output resource file now
209
210 Res.UseResFile(output)
Jack Jansen81da9f11999-03-17 22:57:55 +0000211
212 if ownertype == None:
213 # No owner resource in the template. We have skipped the
214 # Python owner resource, so we have to add our own. The relevant
215 # bundle stuff is already included in the interpret/applet template.
216 newres = Res.Resource('\0')
217 newres.AddResource(DEFAULT_APPLET_CREATOR, 0, "Owner resource")
218 ownertype = DEFAULT_APPLET_CREATOR
Jack Jansen813c9971998-07-31 09:42:35 +0000219
220 if code:
221 # Delete any existing 'PYC ' resource named __main__
222
223 try:
224 res = Res.Get1NamedResource(RESTYPE, RESNAME)
225 res.RemoveResource()
226 except Res.Error:
227 pass
228
229 # Create the raw data for the resource from the code object
Jack Jansen388fbf32002-06-09 22:08:52 +0000230 if progress:
Jack Jansen813c9971998-07-31 09:42:35 +0000231 progress.label("Write PYC resource...")
232 progress.set(120)
233
234 data = marshal.dumps(code)
235 del code
236 data = (MAGIC + '\0\0\0\0') + data
237
238 # Create the resource and write it
239
240 id = 0
241 while id < 128:
242 id = Res.Unique1ID(RESTYPE)
243 res = Res.Resource(data)
244 res.AddResource(RESTYPE, id, RESNAME)
Just van Rossum874f87b1999-01-30 22:31:26 +0000245 attrs = res.GetResAttrs()
246 attrs = attrs | 0x04 # set preload
247 res.SetResAttrs(attrs)
Jack Jansen813c9971998-07-31 09:42:35 +0000248 res.WriteResource()
249 res.ReleaseResource()
250
251 # Close the output file
252
253 Res.CloseResFile(output)
254
255 # Now set the creator, type and bundle bit of the destination
256 dest_finfo = dest_fss.GetFInfo()
257 dest_finfo.Creator = ownertype
258 dest_finfo.Type = 'APPL'
Jack Jansenb70699b1999-12-03 23:38:05 +0000259 dest_finfo.Flags = dest_finfo.Flags | MACFS.kHasBundle | MACFS.kIsShared
Jack Jansen813c9971998-07-31 09:42:35 +0000260 dest_finfo.Flags = dest_finfo.Flags & ~MACFS.kHasBeenInited
261 dest_fss.SetFInfo(dest_finfo)
262
263 macostools.touched(dest_fss)
Jack Jansen388fbf32002-06-09 22:08:52 +0000264 if progress:
Jack Jansen813c9971998-07-31 09:42:35 +0000265 progress.label("Done.")
Jack Jansen388fbf32002-06-09 22:08:52 +0000266 progress.inc(0)
Jack Jansen813c9971998-07-31 09:42:35 +0000267
Jack Jansen388fbf32002-06-09 22:08:52 +0000268def process_common_macho(template, progress, code, rsrcname, destname, is_update, raw=0, others=[]):
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000269 # First make sure the name ends in ".app"
270 if destname[-4:] != '.app':
271 destname = destname + '.app'
272 # Now deduce the short name
273 shortname = os.path.split(destname)[1]
274 if shortname[-4:] == '.app':
275 # Strip the .app suffix
276 shortname = shortname[:-4]
Jack Jansen9aa8fd02002-03-29 23:44:37 +0000277 # And deduce the .plist and .icns names
278 plistname = None
279 icnsname = None
280 if rsrcname and rsrcname[-5:] == '.rsrc':
281 tmp = rsrcname[:-5]
282 plistname = tmp + '.plist'
283 if os.path.exists(plistname):
284 icnsname = tmp + '.icns'
285 if not os.path.exists(icnsname):
286 icnsname = None
287 else:
288 plistname = None
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000289 # Start with copying the .app framework
290 if not is_update:
291 exceptlist = ["Contents/Info.plist",
292 "Contents/Resources/English.lproj/InfoPlist.strings",
293 "Contents/Resources/python.rsrc",
294 ]
Jack Jansen388fbf32002-06-09 22:08:52 +0000295 copyapptree(template, destname, exceptlist, progress)
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000296 # Now either use the .plist file or the default
Jack Jansen388fbf32002-06-09 22:08:52 +0000297 if progress:
298 progress.label('Create info.plist')
299 progress.inc(0)
Jack Jansen9aa8fd02002-03-29 23:44:37 +0000300 if plistname:
Jack Jansen388fbf32002-06-09 22:08:52 +0000301 shutil.copy2(plistname, os.path.join(destname, 'Contents', 'Info.plist'))
Jack Jansen9aa8fd02002-03-29 23:44:37 +0000302 if icnsname:
303 icnsdest = os.path.split(icnsname)[1]
304 icnsdest = os.path.join(destname,
Jack Jansen388fbf32002-06-09 22:08:52 +0000305 os.path.join('Contents', 'Resources', icnsdest))
Jack Jansen9aa8fd02002-03-29 23:44:37 +0000306 shutil.copy2(icnsname, icnsdest)
307 # XXXX Wrong. This should be parsed from plist file. Also a big hack:-)
308 if shortname == 'PythonIDE':
309 ownertype = 'Pide'
310 else:
311 ownertype = 'PytA'
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000312 # XXXX Should copy .icns file
313 else:
Jack Jansen388fbf32002-06-09 22:08:52 +0000314 cocoainfo = ''
315 for o in others:
316 if o[-4:] == '.nib':
317 nibname = os.path.split(o)[1][:-4]
318 cocoainfo = """
319 <key>NSMainNibFile</key>
320 <string>%s</string>
321 <key>NSPrincipalClass</key>
322 <string>NSApplication</string>""" % nibname
323
324
325 plistname = os.path.join(template, 'Contents', 'Resources', 'Applet-Info.plist')
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000326 plistdata = open(plistname).read()
Jack Jansen388fbf32002-06-09 22:08:52 +0000327 plistdata = plistdata % {'appletname':shortname, 'cocoainfo':cocoainfo}
328 ofp = open(os.path.join(destname, 'Contents', 'Info.plist'), 'w')
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000329 ofp.write(plistdata)
330 ofp.close()
331 ownertype = 'PytA'
332 # Create the PkgInfo file
Jack Jansen388fbf32002-06-09 22:08:52 +0000333 if progress:
334 progress.label('Create PkgInfo')
335 progress.inc(0)
336 ofp = open(os.path.join(destname, 'Contents', 'PkgInfo'), 'wb')
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000337 ofp.write('APPL' + ownertype)
338 ofp.close()
339
340
Jack Jansen388fbf32002-06-09 22:08:52 +0000341 if progress:
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000342 progress.label("Copy resources...")
343 progress.set(20)
344 resfilename = '%s.rsrc' % shortname
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000345 try:
346 output = Res.FSOpenResourceFile(
Jack Jansen388fbf32002-06-09 22:08:52 +0000347 os.path.join(destname, 'Contents', 'Resources', resfilename),
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000348 u'', WRITE)
349 except MacOS.Error:
350 fsr, dummy = Res.FSCreateResourceFile(
Jack Jansen388fbf32002-06-09 22:08:52 +0000351 os.path.join(destname, 'Contents', 'Resources'),
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000352 unicode(resfilename), '')
353 output = Res.FSOpenResourceFile(fsr, u'', WRITE)
354
355 # Copy the resources from the target specific resource template, if any
356 typesfound, ownertype = [], None
357 try:
358 input = macresource.open_pathname(rsrcname)
359 except (MacOS.Error, ValueError):
360 pass
Jack Jansen388fbf32002-06-09 22:08:52 +0000361 if progress:
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000362 progress.inc(50)
363 else:
364 typesfound, ownertype = copyres(input, output, [], 0, progress)
365 Res.CloseResFile(input)
366
367 # Check which resource-types we should not copy from the template
368 skiptypes = []
369## if 'vers' in typesfound: skiptypes.append('vers')
370## if 'SIZE' in typesfound: skiptypes.append('SIZE')
371## if 'BNDL' in typesfound: skiptypes = skiptypes + ['BNDL', 'FREF', 'icl4',
372## 'icl8', 'ics4', 'ics8', 'ICN#', 'ics#']
373## if not copy_codefragment:
374## skiptypes.append('cfrg')
375## skipowner = (ownertype <> None)
376
377 # Copy the resources from the template
378
379 input = Res.FSOpenResourceFile(
Jack Jansen388fbf32002-06-09 22:08:52 +0000380 os.path.join(template, 'Contents', 'Resources', 'python.rsrc'), u'', READ)
381 if progress:
382 progress.label("Copy standard resources...")
383 progress.inc(0)
384## dummy, tmplowner = copyres(input, output, skiptypes, 1, progress)
385 dummy, tmplowner = copyres(input, output, skiptypes, 1, None)
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000386
387 Res.CloseResFile(input)
388## if ownertype == None:
389## raise BuildError, "No owner resource found in either resource file or template"
390 # Make sure we're manipulating the output resource file now
391
392 Res.CloseResFile(output)
393
394 if code:
Jack Jansen388fbf32002-06-09 22:08:52 +0000395 if raw:
396 pycname = '__rawmain__.pyc'
397 else:
398 pycname = '__main__.pyc'
399 outputfilename = os.path.join(destname, 'Contents', 'Resources', pycname)
400 if progress:
401 progress.label('Creating '+pycname)
402 progress.inc(0)
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000403 writepycfile(code, outputfilename)
Jack Jansen388fbf32002-06-09 22:08:52 +0000404 # Copy other files the user asked for
405 for osrc in others:
406 oname = os.path.split(osrc)[1]
407 odst = os.path.join(destname, 'Contents', 'Resources', oname)
408 if progress:
409 progress.label('Copy ' + oname)
410 progress.inc(0)
411 if os.path.isdir(osrc):
412 copyapptree(osrc, odst)
413 else:
414 shutil.copy2(osrc, odst)
415 if progress:
416 progress.label('Done.')
417 progress.inc(0)
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000418
419## macostools.touched(dest_fss)
Jack Jansen813c9971998-07-31 09:42:35 +0000420
421# Copy resources between two resource file descriptors.
Jack Jansen81da9f11999-03-17 22:57:55 +0000422# skip a resource named '__main__' or (if skipowner is set) with ID zero.
Jack Jansen813c9971998-07-31 09:42:35 +0000423# Also skip resources with a type listed in skiptypes.
424#
425def copyres(input, output, skiptypes, skipowner, progress=None):
426 ctor = None
427 alltypes = []
428 Res.UseResFile(input)
429 ntypes = Res.Count1Types()
430 progress_type_inc = 50/ntypes
431 for itype in range(1, 1+ntypes):
432 type = Res.Get1IndType(itype)
433 if type in skiptypes:
434 continue
435 alltypes.append(type)
436 nresources = Res.Count1Resources(type)
437 progress_cur_inc = progress_type_inc/nresources
438 for ires in range(1, 1+nresources):
439 res = Res.Get1IndResource(type, ires)
440 id, type, name = res.GetResInfo()
441 lcname = string.lower(name)
Jack Jansen81da9f11999-03-17 22:57:55 +0000442
443 if lcname == OWNERNAME and id == 0:
Jack Jansen813c9971998-07-31 09:42:35 +0000444 if skipowner:
445 continue # Skip this one
446 else:
447 ctor = type
448 size = res.size
449 attrs = res.GetResAttrs()
Jack Jansen388fbf32002-06-09 22:08:52 +0000450 if progress:
Jack Jansen813c9971998-07-31 09:42:35 +0000451 progress.label("Copy %s %d %s"%(type, id, name))
452 progress.inc(progress_cur_inc)
453 res.LoadResource()
454 res.DetachResource()
455 Res.UseResFile(output)
456 try:
457 res2 = Res.Get1Resource(type, id)
458 except MacOS.Error:
459 res2 = None
460 if res2:
Jack Jansen388fbf32002-06-09 22:08:52 +0000461 if progress:
Jack Jansen813c9971998-07-31 09:42:35 +0000462 progress.label("Overwrite %s %d %s"%(type, id, name))
Jack Jansen388fbf32002-06-09 22:08:52 +0000463 progress.inc(0)
Jack Jansen813c9971998-07-31 09:42:35 +0000464 res2.RemoveResource()
465 res.AddResource(type, id, name)
466 res.WriteResource()
467 attrs = attrs | res.GetResAttrs()
468 res.SetResAttrs(attrs)
469 Res.UseResFile(input)
470 return alltypes, ctor
471
Jack Jansen388fbf32002-06-09 22:08:52 +0000472def copyapptree(srctree, dsttree, exceptlist=[], progress=None):
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000473 names = []
474 if os.path.exists(dsttree):
475 shutil.rmtree(dsttree)
476 os.mkdir(dsttree)
477 todo = os.listdir(srctree)
478 while todo:
479 this, todo = todo[0], todo[1:]
480 if this in exceptlist:
481 continue
482 thispath = os.path.join(srctree, this)
483 if os.path.isdir(thispath):
484 thiscontent = os.listdir(thispath)
485 for t in thiscontent:
486 todo.append(os.path.join(this, t))
487 names.append(this)
488 for this in names:
489 srcpath = os.path.join(srctree, this)
490 dstpath = os.path.join(dsttree, this)
491 if os.path.isdir(srcpath):
492 os.mkdir(dstpath)
493 else:
Jack Jansen388fbf32002-06-09 22:08:52 +0000494 if progress:
495 progress.label('Copy '+this)
496 progress.inc(0)
Jack Jansenb2e33fe2002-03-29 21:21:28 +0000497 shutil.copy2(srcpath, dstpath)
498
499def writepycfile(codeobject, cfile):
500 import marshal
501 fc = open(cfile, 'wb')
502 fc.write('\0\0\0\0') # MAGIC placeholder, written later
503 fc.write('\0\0\0\0') # Timestap placeholder, not needed
504 marshal.dump(codeobject, fc)
505 fc.flush()
506 fc.seek(0, 0)
507 fc.write(MAGIC)
508 fc.close()
Jack Jansen813c9971998-07-31 09:42:35 +0000509