[Python-checkins] python/dist/src/Mac/Lib buildtools.py,1.11,1.12
jackjansen@users.sourceforge.net
jackjansen@users.sourceforge.net
2002年6月09日 15:08:54 -0700
Update of /cvsroot/python/python/dist/src/Mac/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv31258/Mac/Lib
Modified Files:
buildtools.py
Log Message:
- Better commandline interface to BuildApplet, complete with options,
verbose output to the console, etc.
- Allow Cocoa applets to be built with BuildApplet.
No full testing has been done yet to ensure OS9 operation hasn't suffered.
Index: buildtools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Lib/buildtools.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** buildtools.py 29 Mar 2002 23:44:37 -0000 1.11
--- buildtools.py 9 Jun 2002 22:08:52 -0000 1.12
***************
*** 18,24 ****
BuildError = "BuildError"
- DEBUG=1
-
-
# .pyc file (and 'PYC ' resource magic number)
MAGIC = imp.get_magic()
--- 18,21 ----
***************
*** 71,81 ****
! def process(template, filename, output, copy_codefragment):
! if DEBUG:
progress = EasyDialogs.ProgressBar("Processing %s..."%os.path.split(filename)[1], 120)
progress.label("Compiling...")
! else:
! progress = None
# Read the source and compile it
--- 68,78 ----
! def process(template, filename, destname, copy_codefragment,
! rsrcname=None, others=[], raw=0, progress="default"):
! if progress == "default":
progress = EasyDialogs.ProgressBar("Processing %s..."%os.path.split(filename)[1], 120)
progress.label("Compiling...")
! progress.inc(0)
# Read the source and compile it
***************
*** 90,108 ****
raise BuildError, "Syntax error in script %s" % `filename`
! # Set the destination file name
if string.lower(filename[-3:]) == ".py":
! destname = filename[:-3]
! rsrcname = destname + '.rsrc'
else:
if MacOS.runtimemodel == 'macho':
! destname = filename + '.app'
else:
! destname = filename + ".applet"
! rsrcname = filename + '.rsrc'
!
! if output:
! destname = output
!
# Try removing the output file. This fails in MachO, but it should
# do any harm.
--- 87,108 ----
raise BuildError, "Syntax error in script %s" % `filename`
! # Set the destination file name. Note that basename
! # does contain the whole filepath, only a .py is stripped.
if string.lower(filename[-3:]) == ".py":
! basename = filename[:-3]
! if MacOS.runtimemodel != 'macho' and not destname:
! destname = basename
else:
+ basename = filename
+
+ if not destname:
if MacOS.runtimemodel == 'macho':
! destname = basename + '.app'
else:
! destname = basename + '.applet'
! if not rsrcname:
! rsrcname = basename + '.rsrc'
!
# Try removing the output file. This fails in MachO, but it should
# do any harm.
***************
*** 111,115 ****
except os.error:
pass
! process_common(template, progress, code, rsrcname, destname, 0, copy_codefragment)
--- 111,116 ----
except os.error:
pass
! process_common(template, progress, code, rsrcname, destname, 0,
! copy_codefragment, raw, others)
***************
*** 117,121 ****
if MacOS.runtimemodel == 'macho':
raise BuildError, "No updating yet for MachO applets"
! if DEBUG:
progress = EasyDialogs.ProgressBar("Updating %s..."%os.path.split(filename)[1], 120)
else:
--- 118,122 ----
if MacOS.runtimemodel == 'macho':
raise BuildError, "No updating yet for MachO applets"
! if progress:
progress = EasyDialogs.ProgressBar("Updating %s..."%os.path.split(filename)[1], 120)
else:
***************
*** 132,138 ****
! def process_common(template, progress, code, rsrcname, destname, is_update, copy_codefragment):
if MacOS.runtimemodel == 'macho':
! return process_common_macho(template, progress, code, rsrcname, destname, is_update)
# Create FSSpecs for the various files
template_fss = macfs.FSSpec(template)
--- 133,143 ----
! def process_common(template, progress, code, rsrcname, destname, is_update,
! copy_codefragment, raw=0, others=[]):
if MacOS.runtimemodel == 'macho':
! return process_common_macho(template, progress, code, rsrcname, destname,
! is_update, raw, others)
! if others:
! raise BuildError, "Extra files only allowed for MachoPython applets"
# Create FSSpecs for the various files
template_fss = macfs.FSSpec(template)
***************
*** 141,145 ****
# Copy data (not resources, yet) from the template
! if DEBUG:
progress.label("Copy data fork...")
progress.set(10)
--- 146,150 ----
# Copy data (not resources, yet) from the template
! if progress:
progress.label("Copy data fork...")
progress.set(10)
***************
*** 158,162 ****
# Open the output resource fork
! if DEBUG:
progress.label("Copy resources...")
progress.set(20)
--- 163,167 ----
# Open the output resource fork
! if progress:
progress.label("Copy resources...")
progress.set(20)
***************
*** 173,177 ****
except (MacOS.Error, ValueError):
pass
! if DEBUG:
progress.inc(50)
else:
--- 178,182 ----
except (MacOS.Error, ValueError):
pass
! if progress:
progress.inc(50)
else:
***************
*** 223,227 ****
# Create the raw data for the resource from the code object
! if DEBUG:
progress.label("Write PYC resource...")
progress.set(120)
--- 228,232 ----
# Create the raw data for the resource from the code object
! if progress:
progress.label("Write PYC resource...")
progress.set(120)
***************
*** 257,264 ****
macostools.touched(dest_fss)
! if DEBUG:
progress.label("Done.")
! def process_common_macho(template, progress, code, rsrcname, destname, is_update):
# First make sure the name ends in ".app"
if destname[-4:] != '.app':
--- 262,270 ----
macostools.touched(dest_fss)
! if progress:
progress.label("Done.")
+ progress.inc(0)
! def process_common_macho(template, progress, code, rsrcname, destname, is_update, raw=0, others=[]):
# First make sure the name ends in ".app"
if destname[-4:] != '.app':
***************
*** 287,298 ****
"Contents/Resources/python.rsrc",
]
! copyapptree(template, destname, exceptlist)
# Now either use the .plist file or the default
if plistname:
! shutil.copy2(plistname, os.path.join(destname, 'Contents/Info.plist'))
if icnsname:
icnsdest = os.path.split(icnsname)[1]
icnsdest = os.path.join(destname,
! os.path.join('Contents/Resources', icnsdest))
shutil.copy2(icnsname, icnsdest)
# XXXX Wrong. This should be parsed from plist file. Also a big hack:-)
--- 293,307 ----
"Contents/Resources/python.rsrc",
]
! copyapptree(template, destname, exceptlist, progress)
# Now either use the .plist file or the default
+ if progress:
+ progress.label('Create info.plist')
+ progress.inc(0)
if plistname:
! shutil.copy2(plistname, os.path.join(destname, 'Contents', 'Info.plist'))
if icnsname:
icnsdest = os.path.split(icnsname)[1]
icnsdest = os.path.join(destname,
! os.path.join('Contents', 'Resources', icnsdest))
shutil.copy2(icnsname, icnsdest)
# XXXX Wrong. This should be parsed from plist file. Also a big hack:-)
***************
*** 303,331 ****
# XXXX Should copy .icns file
else:
! plistname = os.path.join(template, 'Contents/Resources/Applet-Info.plist')
plistdata = open(plistname).read()
! plistdata = plistdata % {'appletname':shortname}
! ofp = open(os.path.join(destname, 'Contents/Info.plist'), 'w')
ofp.write(plistdata)
ofp.close()
ownertype = 'PytA'
# Create the PkgInfo file
! ofp = open(os.path.join(destname, 'Contents/PkgInfo'), 'wb')
ofp.write('APPL' + ownertype)
ofp.close()
! if DEBUG:
progress.label("Copy resources...")
progress.set(20)
resfilename = '%s.rsrc' % shortname
- respartialpathname = 'Contents/Resources/%s' % resfilename
try:
output = Res.FSOpenResourceFile(
! os.path.join(destname, respartialpathname),
u'', WRITE)
except MacOS.Error:
fsr, dummy = Res.FSCreateResourceFile(
! os.path.join(destname, 'Contents/Resources'),
unicode(resfilename), '')
output = Res.FSOpenResourceFile(fsr, u'', WRITE)
--- 312,353 ----
# XXXX Should copy .icns file
else:
! cocoainfo = ''
! for o in others:
! if o[-4:] == '.nib':
! nibname = os.path.split(o)[1][:-4]
! cocoainfo = """
! <key>NSMainNibFile</key>
! <string>%s</string>
! <key>NSPrincipalClass</key>
! <string>NSApplication</string>""" % nibname
!
!
! plistname = os.path.join(template, 'Contents', 'Resources', 'Applet-Info.plist')
plistdata = open(plistname).read()
! plistdata = plistdata % {'appletname':shortname, 'cocoainfo':cocoainfo}
! ofp = open(os.path.join(destname, 'Contents', 'Info.plist'), 'w')
ofp.write(plistdata)
ofp.close()
ownertype = 'PytA'
# Create the PkgInfo file
! if progress:
! progress.label('Create PkgInfo')
! progress.inc(0)
! ofp = open(os.path.join(destname, 'Contents', 'PkgInfo'), 'wb')
ofp.write('APPL' + ownertype)
ofp.close()
! if progress:
progress.label("Copy resources...")
progress.set(20)
resfilename = '%s.rsrc' % shortname
try:
output = Res.FSOpenResourceFile(
! os.path.join(destname, 'Contents', 'Resources', resfilename),
u'', WRITE)
except MacOS.Error:
fsr, dummy = Res.FSCreateResourceFile(
! os.path.join(destname, 'Contents', 'Resources'),
unicode(resfilename), '')
output = Res.FSOpenResourceFile(fsr, u'', WRITE)
***************
*** 337,341 ****
except (MacOS.Error, ValueError):
pass
! if DEBUG:
progress.inc(50)
else:
--- 359,363 ----
except (MacOS.Error, ValueError):
pass
! if progress:
progress.inc(50)
else:
***************
*** 356,361 ****
input = Res.FSOpenResourceFile(
! os.path.join(template, 'Contents/Resources/python.rsrc'), u'', READ)
! dummy, tmplowner = copyres(input, output, skiptypes, 1, progress)
Res.CloseResFile(input)
--- 378,387 ----
input = Res.FSOpenResourceFile(
! os.path.join(template, 'Contents', 'Resources', 'python.rsrc'), u'', READ)
! if progress:
! progress.label("Copy standard resources...")
! progress.inc(0)
! ## dummy, tmplowner = copyres(input, output, skiptypes, 1, progress)
! dummy, tmplowner = copyres(input, output, skiptypes, 1, None)
Res.CloseResFile(input)
***************
*** 367,372 ****
if code:
! outputfilename = os.path.join(destname, 'Contents/Resources/__main__.pyc')
writepycfile(code, outputfilename)
## macostools.touched(dest_fss)
--- 393,419 ----
if code:
! if raw:
! pycname = '__rawmain__.pyc'
! else:
! pycname = '__main__.pyc'
! outputfilename = os.path.join(destname, 'Contents', 'Resources', pycname)
! if progress:
! progress.label('Creating '+pycname)
! progress.inc(0)
writepycfile(code, outputfilename)
+ # Copy other files the user asked for
+ for osrc in others:
+ oname = os.path.split(osrc)[1]
+ odst = os.path.join(destname, 'Contents', 'Resources', oname)
+ if progress:
+ progress.label('Copy ' + oname)
+ progress.inc(0)
+ if os.path.isdir(osrc):
+ copyapptree(osrc, odst)
+ else:
+ shutil.copy2(osrc, odst)
+ if progress:
+ progress.label('Done.')
+ progress.inc(0)
## macostools.touched(dest_fss)
***************
*** 401,405 ****
size = res.size
attrs = res.GetResAttrs()
! if DEBUG and progress:
progress.label("Copy %s %d %s"%(type, id, name))
progress.inc(progress_cur_inc)
--- 448,452 ----
size = res.size
attrs = res.GetResAttrs()
! if progress:
progress.label("Copy %s %d %s"%(type, id, name))
progress.inc(progress_cur_inc)
***************
*** 412,417 ****
res2 = None
if res2:
! if DEBUG and progress:
progress.label("Overwrite %s %d %s"%(type, id, name))
res2.RemoveResource()
res.AddResource(type, id, name)
--- 459,465 ----
res2 = None
if res2:
! if progress:
progress.label("Overwrite %s %d %s"%(type, id, name))
+ progress.inc(0)
res2.RemoveResource()
res.AddResource(type, id, name)
***************
*** 422,426 ****
return alltypes, ctor
! def copyapptree(srctree, dsttree, exceptlist=[]):
names = []
if os.path.exists(dsttree):
--- 470,474 ----
return alltypes, ctor
! def copyapptree(srctree, dsttree, exceptlist=[], progress=None):
names = []
if os.path.exists(dsttree):
***************
*** 444,447 ****
--- 492,498 ----
os.mkdir(dstpath)
else:
+ if progress:
+ progress.label('Copy '+this)
+ progress.inc(0)
shutil.copy2(srcpath, dstpath)