| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | """tools for BuildApplet and BuildApplication""" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import imp | 
					
						
							|  |  |  | import marshal | 
					
						
							| 
									
										
										
										
											2001-08-25 12:15:04 +00:00
										 |  |  | from Carbon import Res | 
					
						
							| 
									
										
										
										
											2003-02-02 23:03:50 +00:00
										 |  |  | import Carbon.Files | 
					
						
							|  |  |  | import Carbon.File | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | import MacOS | 
					
						
							|  |  |  | import macostools | 
					
						
							| 
									
										
										
										
											2002-03-29 21:21:28 +00:00
										 |  |  | import macresource | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | import EasyDialogs | 
					
						
							| 
									
										
										
										
											2002-03-29 21:21:28 +00:00
										 |  |  | import shutil | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 55631-55794 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
  r55636 | neal.norwitz | 2007-05-29 00:06:39 -0700 (Tue, 29 May 2007) | 149 lines
  Merged revisions 55506-55635 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk
  ........
    r55507 | georg.brandl | 2007-05-22 07:28:17 -0700 (Tue, 22 May 2007) | 2 lines
    Remove the "panel" module doc file which has been ignored since 1994.
  ........
    r55522 | mark.hammond | 2007-05-22 19:04:28 -0700 (Tue, 22 May 2007) | 4 lines
    Remove definition of PY_UNICODE_TYPE from pyconfig.h, allowing the
    definition in unicodeobject.h to be used, giving us the desired
    wchar_t in place of 'unsigned short'.  As discussed on python-dev.
  ........
    r55525 | neal.norwitz | 2007-05-22 23:35:32 -0700 (Tue, 22 May 2007) | 6 lines
    Add -3 option to the interpreter to warn about features that are
    deprecated and will be changed/removed in Python 3.0.
    This patch is mostly from Anthony.  I tweaked some format and added
    a little doc.
  ........
    r55527 | neal.norwitz | 2007-05-22 23:57:35 -0700 (Tue, 22 May 2007) | 1 line
    Whitespace cleanup
  ........
    r55528 | neal.norwitz | 2007-05-22 23:58:36 -0700 (Tue, 22 May 2007) | 1 line
    Add a bunch more deprecation warnings for builtins that are going away in 3.0
  ........
    r55549 | georg.brandl | 2007-05-24 09:49:29 -0700 (Thu, 24 May 2007) | 2 lines
    shlex.split() now has an optional "posix" parameter.
  ........
    r55550 | georg.brandl | 2007-05-24 10:33:33 -0700 (Thu, 24 May 2007) | 2 lines
    Fix parameter passing.
  ........
    r55555 | facundo.batista | 2007-05-24 10:50:54 -0700 (Thu, 24 May 2007) | 6 lines
    Added an optional timeout parameter to urllib.ftpwrapper, with tests
    (for this and a basic one, because there weren't any). Changed also
    NEWS, but didn't find documentation for this function, assumed it
    wasn't public...
  ........
    r55563 | facundo.batista | 2007-05-24 13:01:59 -0700 (Thu, 24 May 2007) | 4 lines
    Removed the .recv() in the test, is not necessary, and was
    causing problems that didn't have anything to do with was
    actually being tested...
  ........
    r55564 | facundo.batista | 2007-05-24 13:51:19 -0700 (Thu, 24 May 2007) | 5 lines
    Let's see if reading exactly what is written allow this live
    test to pass (now I know why there were so few tests in ftp,
    http, etc, :( ).
  ........
    r55567 | facundo.batista | 2007-05-24 20:10:28 -0700 (Thu, 24 May 2007) | 4 lines
    Trying to make the tests work in Windows and Solaris, everywhere
    else just works
  ........
    r55568 | facundo.batista | 2007-05-24 20:47:19 -0700 (Thu, 24 May 2007) | 4 lines
    Fixing stupid error, and introducing a sleep, to see if the
    other thread is awakened and finish sending data.
  ........
    r55569 | facundo.batista | 2007-05-24 21:20:22 -0700 (Thu, 24 May 2007) | 4 lines
    Commenting out the tests until find out who can test them in
    one of the problematic enviroments.
  ........
    r55570 | neal.norwitz | 2007-05-24 22:13:40 -0700 (Thu, 24 May 2007) | 2 lines
    Get test passing again by commenting out the reference to the test class.
  ........
    r55575 | vinay.sajip | 2007-05-25 00:05:59 -0700 (Fri, 25 May 2007) | 1 line
    Updated docstring for SysLogHandler (#1720726).
  ........
    r55576 | vinay.sajip | 2007-05-25 00:06:55 -0700 (Fri, 25 May 2007) | 1 line
    Updated documentation for SysLogHandler (#1720726).
  ........
    r55592 | brett.cannon | 2007-05-25 13:17:15 -0700 (Fri, 25 May 2007) | 3 lines
    Remove direct call's to file's constructor and replace them with calls to
    open() as ths is considered best practice.
  ........
    r55601 | kristjan.jonsson | 2007-05-26 12:19:50 -0700 (Sat, 26 May 2007) | 1 line
    Remove the rgbimgmodule from PCBuild8
  ........
    r55602 | kristjan.jonsson | 2007-05-26 12:31:39 -0700 (Sat, 26 May 2007) | 1 line
    Include <windows.h> after python.h, so that WINNT is properly set before windows.h is included.  Fixes warnings in PC builds.
  ........
    r55603 | walter.doerwald | 2007-05-26 14:04:13 -0700 (Sat, 26 May 2007) | 2 lines
    Fix typo.
  ........
    r55604 | peter.astrand | 2007-05-26 15:18:20 -0700 (Sat, 26 May 2007) | 1 line
    Applied patch 1669481, slightly modified: Support close_fds on Win32
  ........
    r55606 | neal.norwitz | 2007-05-26 21:08:54 -0700 (Sat, 26 May 2007) | 2 lines
    Add the new function object attribute names from py3k.
  ........
    r55617 | lars.gustaebel | 2007-05-27 12:49:30 -0700 (Sun, 27 May 2007) | 20 lines
    Added errors argument to TarFile class that allows the user to
    specify an error handling scheme for character conversion. Additional
    scheme "utf-8" in read mode. Unicode input filenames are now
    supported by design. The values of the pax_headers dictionary are now
    limited to unicode objects.
    Fixed: The prefix field is no longer used in PAX_FORMAT (in
    conformance with POSIX).
    Fixed: In read mode use a possible pax header size field.
    Fixed: Strip trailing slashes from pax header name values.
    Fixed: Give values in user-specified pax_headers precedence when
    writing.
    Added unicode tests. Added pax/regtype4 member to testtar.tar all
    possible number fields in a pax header.
    Added two chapters to the documentation about the different formats
    tarfile.py supports and how unicode issues are handled.
  ........
    r55618 | raymond.hettinger | 2007-05-27 22:23:22 -0700 (Sun, 27 May 2007) | 1 line
    Explain when groupby() issues a new group.
  ........
    r55634 | martin.v.loewis | 2007-05-28 21:01:29 -0700 (Mon, 28 May 2007) | 2 lines
    Test pre-commit hook for a link to a .py file.
  ........
    r55635 | martin.v.loewis | 2007-05-28 21:02:03 -0700 (Mon, 28 May 2007) | 2 lines
    Revert 55634.
  ........
................
  r55639 | neal.norwitz | 2007-05-29 00:58:11 -0700 (Tue, 29 May 2007) | 1 line
  Remove sys.exc_{type,exc_value,exc_traceback}
................
  r55641 | neal.norwitz | 2007-05-29 01:03:50 -0700 (Tue, 29 May 2007) | 1 line
  Missed one sys.exc_type.  I wonder why exc_{value,traceback} were already gone
................
  r55642 | neal.norwitz | 2007-05-29 01:08:33 -0700 (Tue, 29 May 2007) | 1 line
  Missed more doc for sys.exc_* attrs.
................
  r55643 | neal.norwitz | 2007-05-29 01:18:19 -0700 (Tue, 29 May 2007) | 1 line
  Remove sys.exc_clear()
................
  r55665 | guido.van.rossum | 2007-05-29 19:45:43 -0700 (Tue, 29 May 2007) | 4 lines
  Make None, True, False keywords.
  We can now also delete all the other places that explicitly forbid
  assignment to None, but I'm not going to bother right now.
................
  r55666 | guido.van.rossum | 2007-05-29 20:01:51 -0700 (Tue, 29 May 2007) | 3 lines
  Found another place that needs check for forbidden names.
  Fixed test_syntax.py accordingly (it helped me find that one).
................
  r55668 | guido.van.rossum | 2007-05-29 20:41:48 -0700 (Tue, 29 May 2007) | 2 lines
  Mark None, True, False as keywords.
................
  r55673 | neal.norwitz | 2007-05-29 23:28:25 -0700 (Tue, 29 May 2007) | 3 lines
  Get the dis module working on modules again after changing dicts
  to not return lists and also new-style classes.  Add a test.
................
  r55674 | neal.norwitz | 2007-05-29 23:35:45 -0700 (Tue, 29 May 2007) | 1 line
  Umm, it helps to add the module that the test uses
................
  r55675 | neal.norwitz | 2007-05-29 23:53:05 -0700 (Tue, 29 May 2007) | 4 lines
  Try to fix up all the other places that were assigning to True/False.
  There's at least one more problem in test.test_xmlrpc.  I have other
  changes in that file and that should be fixed soon (I hope).
................
  r55679 | neal.norwitz | 2007-05-30 00:31:55 -0700 (Wed, 30 May 2007) | 1 line
  Fix up another place that was assigning to True/False.
................
  r55688 | brett.cannon | 2007-05-30 14:19:47 -0700 (Wed, 30 May 2007) | 2 lines
  Ditch MimeWriter.
................
  r55692 | brett.cannon | 2007-05-30 14:52:00 -0700 (Wed, 30 May 2007) | 2 lines
  Remove the mimify module.
................
  r55707 | guido.van.rossum | 2007-05-31 05:08:45 -0700 (Thu, 31 May 2007) | 2 lines
  Backport the addition of show_code() to dis.py -- it's too handy.
................
  r55708 | guido.van.rossum | 2007-05-31 06:22:57 -0700 (Thu, 31 May 2007) | 7 lines
  Fix a fairly long-standing bug in the check for assignment to None (and other
  keywords, these days).  In 2.5, you could write foo(None=1) without getting
  a SyntaxError (although foo()'s definition would have to use **kwds to avoid
  getting a runtime error complaining about an unknown keyword of course).
  This ought to be backported to 2.5.2 or at least 2.6.
................
  r55724 | brett.cannon | 2007-05-31 19:32:41 -0700 (Thu, 31 May 2007) | 2 lines
  Remove the cfmfile.
................
  r55727 | neal.norwitz | 2007-05-31 22:19:44 -0700 (Thu, 31 May 2007) | 1 line
  Remove reload() builtin.
................
  r55729 | neal.norwitz | 2007-05-31 22:51:30 -0700 (Thu, 31 May 2007) | 59 lines
  Merged revisions 55636-55728 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk
  ........
    r55637 | georg.brandl | 2007-05-29 00:16:47 -0700 (Tue, 29 May 2007) | 2 lines
    Fix rst markup.
  ........
    r55638 | neal.norwitz | 2007-05-29 00:51:39 -0700 (Tue, 29 May 2007) | 1 line
    Fix typo in doc
  ........
    r55671 | neal.norwitz | 2007-05-29 21:53:41 -0700 (Tue, 29 May 2007) | 1 line
    Fix indentation (whitespace only).
  ........
    r55676 | thomas.heller | 2007-05-29 23:58:30 -0700 (Tue, 29 May 2007) | 1 line
    Fix compiler warnings.
  ........
    r55677 | thomas.heller | 2007-05-30 00:01:25 -0700 (Wed, 30 May 2007) | 2 lines
    Correct the name of a field in the WIN32_FIND_DATAA and WIN32_FIND_DATAW structures.
    Closes bug #1726026.
  ........
    r55686 | brett.cannon | 2007-05-30 13:46:26 -0700 (Wed, 30 May 2007) | 2 lines
    Have MimeWriter raise a DeprecationWarning as per PEP 4 and its documentation.
  ........
    r55690 | brett.cannon | 2007-05-30 14:48:58 -0700 (Wed, 30 May 2007) | 3 lines
    Have mimify raise a DeprecationWarning.  The docs and PEP 4 have listed the
    module as deprecated for a while.
  ........
    r55696 | brett.cannon | 2007-05-30 15:24:28 -0700 (Wed, 30 May 2007) | 2 lines
    Have md5 raise a DeprecationWarning as per PEP 4.
  ........
    r55705 | neal.norwitz | 2007-05-30 21:14:22 -0700 (Wed, 30 May 2007) | 1 line
    Add some spaces in the example code.
  ........
    r55716 | brett.cannon | 2007-05-31 12:20:00 -0700 (Thu, 31 May 2007) | 2 lines
    Have the sha module raise a DeprecationWarning as specified in PEP 4.
  ........
    r55719 | brett.cannon | 2007-05-31 12:40:42 -0700 (Thu, 31 May 2007) | 2 lines
    Cause buildtools to raise a DeprecationWarning.
  ........
    r55721 | brett.cannon | 2007-05-31 13:01:11 -0700 (Thu, 31 May 2007) | 2 lines
    Have cfmfile raise a DeprecationWarning as per PEP 4.
  ........
    r55726 | neal.norwitz | 2007-05-31 21:56:47 -0700 (Thu, 31 May 2007) | 1 line
    Mail if there is an installation failure.
  ........
................
  r55730 | neal.norwitz | 2007-05-31 23:22:07 -0700 (Thu, 31 May 2007) | 2 lines
  Remove the code that was missed in rev 55303.
................
  r55738 | neal.norwitz | 2007-06-01 19:10:43 -0700 (Fri, 01 Jun 2007) | 1 line
  Fix doc breakage
................
  r55741 | neal.norwitz | 2007-06-02 00:41:58 -0700 (Sat, 02 Jun 2007) | 1 line
  Remove timing module (plus some remnants of other modules).
................
  r55742 | neal.norwitz | 2007-06-02 00:51:44 -0700 (Sat, 02 Jun 2007) | 1 line
  Remove posixfile module (plus some remnants of other modules).
................
  r55744 | neal.norwitz | 2007-06-02 10:18:56 -0700 (Sat, 02 Jun 2007) | 1 line
  Fix doc breakage.
................
  r55745 | neal.norwitz | 2007-06-02 11:32:16 -0700 (Sat, 02 Jun 2007) | 1 line
  Make a whatsnew 3.0 template.
................
  r55754 | neal.norwitz | 2007-06-03 23:24:18 -0700 (Sun, 03 Jun 2007) | 1 line
  SF #1730441, os._execvpe raises UnboundLocal due to new try/except semantics
................
  r55755 | neal.norwitz | 2007-06-03 23:26:00 -0700 (Sun, 03 Jun 2007) | 1 line
  Get rid of extra whitespace
................
  r55794 | guido.van.rossum | 2007-06-06 15:29:22 -0700 (Wed, 06 Jun 2007) | 3 lines
  Make this compile in GCC 2.96, which does not allow interspersing
  declarations and code.
................
											
										 
											2007-06-06 23:52:48 +00:00
										 |  |  | import warnings | 
					
						
							|  |  |  | warnings.warn("the buildtools module is deprecated", DeprecationWarning, 2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-03 07:27:49 +00:00
										 |  |  | class BuildError(Exception): | 
					
						
							|  |  |  |     pass | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # .pyc file (and 'PYC ' resource magic number) | 
					
						
							|  |  |  | MAGIC = imp.get_magic() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Template file (searched on sys.path) | 
					
						
							| 
									
										
										
										
											1999-02-14 23:12:06 +00:00
										 |  |  | TEMPLATE = "PythonInterpreter" | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Specification of our resource | 
					
						
							|  |  |  | RESTYPE = 'PYC ' | 
					
						
							|  |  |  | RESNAME = '__main__' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # A resource with this name sets the "owner" (creator) of the destination | 
					
						
							| 
									
										
										
										
											1999-03-17 22:57:55 +00:00
										 |  |  | # It should also have ID=0. Either of these alone is not enough. | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | OWNERNAME = "owner resource" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-03-17 22:57:55 +00:00
										 |  |  | # Default applet creator code | 
					
						
							|  |  |  | DEFAULT_APPLET_CREATOR="Pyta" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | # OpenResFile mode parameters | 
					
						
							|  |  |  | READ = 1 | 
					
						
							|  |  |  | WRITE = 2 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-02 23:03:50 +00:00
										 |  |  | # Parameter for FSOpenResourceFile | 
					
						
							|  |  |  | RESOURCE_FORK_NAME=Carbon.File.FSGetResourceForkName() | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-17 23:30:19 +00:00
										 |  |  | def findtemplate(template=None): | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     """Locate the applet template along sys.path""" | 
					
						
							|  |  |  |     if MacOS.runtimemodel == 'macho': | 
					
						
							|  |  |  |         return None | 
					
						
							|  |  |  |     if not template: | 
					
						
							|  |  |  |         template=TEMPLATE | 
					
						
							|  |  |  |     for p in sys.path: | 
					
						
							|  |  |  |         file = os.path.join(p, template) | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             file, d1, d2 = Carbon.File.FSResolveAliasFile(file, 1) | 
					
						
							|  |  |  |             break | 
					
						
							|  |  |  |         except (Carbon.File.Error, ValueError): | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |     else: | 
					
						
							| 
									
										
										
										
											2007-08-23 00:01:55 +00:00
										 |  |  |         raise BuildError("Template %r not found on sys.path" % (template,)) | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     file = file.as_pathname() | 
					
						
							|  |  |  |     return file | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def process(template, filename, destname, copy_codefragment=0, | 
					
						
							| 
									
										
										
										
											2004-12-27 15:51:03 +00:00
										 |  |  |         rsrcname=None, others=[], raw=0, progress="default", destroot=""): | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if progress == "default": | 
					
						
							|  |  |  |         progress = EasyDialogs.ProgressBar("Processing %s..."%os.path.split(filename)[1], 120) | 
					
						
							|  |  |  |         progress.label("Compiling...") | 
					
						
							|  |  |  |         progress.inc(0) | 
					
						
							|  |  |  |     # check for the script name being longer than 32 chars. This may trigger a bug | 
					
						
							|  |  |  |     # on OSX that can destroy your sourcefile. | 
					
						
							|  |  |  |     if '#' in os.path.split(filename)[1]: | 
					
						
							| 
									
										
										
										
											2007-08-23 00:01:55 +00:00
										 |  |  |         raise BuildError("BuildApplet could destroy your sourcefile on OSX, please rename: %s" % filename) | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Read the source and compile it | 
					
						
							|  |  |  |     # (there's no point overwriting the destination if it has a syntax error) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     fp = open(filename, 'rU') | 
					
						
							|  |  |  |     text = fp.read() | 
					
						
							|  |  |  |     fp.close() | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         code = compile(text + '\n', filename, "exec") | 
					
						
							| 
									
										
										
										
											2007-01-10 16:19:56 +00:00
										 |  |  |     except SyntaxError as arg: | 
					
						
							| 
									
										
										
										
											2007-08-23 00:01:55 +00:00
										 |  |  |         raise BuildError("Syntax error in script %s: %s" % (filename, arg)) | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     except EOFError: | 
					
						
							| 
									
										
										
										
											2007-08-23 00:01:55 +00:00
										 |  |  |         raise BuildError("End-of-file in script %s" % (filename,)) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Set the destination file name. Note that basename | 
					
						
							|  |  |  |     # does contain the whole filepath, only a .py is stripped. | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-04-17 08:48:32 +00:00
										 |  |  |     if filename[-3:].lower() == ".py": | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |         basename = filename[:-3] | 
					
						
							|  |  |  |         if MacOS.runtimemodel != 'macho' and not destname: | 
					
						
							|  |  |  |             destname = basename | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         basename = filename | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if not destname: | 
					
						
							|  |  |  |         if MacOS.runtimemodel == 'macho': | 
					
						
							|  |  |  |             destname = basename + '.app' | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             destname = basename + '.applet' | 
					
						
							|  |  |  |     if not rsrcname: | 
					
						
							|  |  |  |         rsrcname = basename + '.rsrc' | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Try removing the output file. This fails in MachO, but it should | 
					
						
							|  |  |  |     # do any harm. | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         os.remove(destname) | 
					
						
							|  |  |  |     except os.error: | 
					
						
							|  |  |  |         pass | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |     process_common(template, progress, code, rsrcname, destname, 0, | 
					
						
							| 
									
										
										
										
											2004-12-27 15:51:03 +00:00
										 |  |  |         copy_codefragment, raw, others, filename, destroot) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def update(template, filename, output): | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if MacOS.runtimemodel == 'macho': | 
					
						
							| 
									
										
										
										
											2007-08-23 00:01:55 +00:00
										 |  |  |         raise BuildError("No updating yet for MachO applets") | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if progress: | 
					
						
							|  |  |  |         progress = EasyDialogs.ProgressBar("Updating %s..."%os.path.split(filename)[1], 120) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         progress = None | 
					
						
							|  |  |  |     if not output: | 
					
						
							|  |  |  |         output = filename + ' (updated)' | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Try removing the output file | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         os.remove(output) | 
					
						
							|  |  |  |     except os.error: | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  |     process_common(template, progress, None, filename, output, 1, 1) | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | def process_common(template, progress, code, rsrcname, destname, is_update, | 
					
						
							| 
									
										
										
										
											2004-12-27 15:51:03 +00:00
										 |  |  |         copy_codefragment, raw=0, others=[], filename=None, destroot=""): | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if MacOS.runtimemodel == 'macho': | 
					
						
							|  |  |  |         return process_common_macho(template, progress, code, rsrcname, destname, | 
					
						
							| 
									
										
										
										
											2004-12-27 15:51:03 +00:00
										 |  |  |             is_update, raw, others, filename, destroot) | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if others: | 
					
						
							| 
									
										
										
										
											2007-08-23 00:01:55 +00:00
										 |  |  |         raise BuildError("Extra files only allowed for MachoPython applets") | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Create FSSpecs for the various files | 
					
						
							|  |  |  |     template_fsr, d1, d2 = Carbon.File.FSResolveAliasFile(template, 1) | 
					
						
							|  |  |  |     template = template_fsr.as_pathname() | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Copy data (not resources, yet) from the template | 
					
						
							|  |  |  |     if progress: | 
					
						
							|  |  |  |         progress.label("Copy data fork...") | 
					
						
							|  |  |  |         progress.set(10) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if copy_codefragment: | 
					
						
							|  |  |  |         tmpl = open(template, "rb") | 
					
						
							|  |  |  |         dest = open(destname, "wb") | 
					
						
							|  |  |  |         data = tmpl.read() | 
					
						
							|  |  |  |         if data: | 
					
						
							|  |  |  |             dest.write(data) | 
					
						
							|  |  |  |         dest.close() | 
					
						
							|  |  |  |         tmpl.close() | 
					
						
							|  |  |  |         del dest | 
					
						
							|  |  |  |         del tmpl | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Open the output resource fork | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if progress: | 
					
						
							|  |  |  |         progress.label("Copy resources...") | 
					
						
							|  |  |  |         progress.set(20) | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         output = Res.FSOpenResourceFile(destname, RESOURCE_FORK_NAME, WRITE) | 
					
						
							|  |  |  |     except MacOS.Error: | 
					
						
							|  |  |  |         destdir, destfile = os.path.split(destname) | 
					
						
							| 
									
										
										
										
											2007-05-02 19:09:54 +00:00
										 |  |  |         Res.FSCreateResourceFile(destdir, str(destfile), RESOURCE_FORK_NAME) | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |         output = Res.FSOpenResourceFile(destname, RESOURCE_FORK_NAME, WRITE) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Copy the resources from the target specific resource template, if any | 
					
						
							|  |  |  |     typesfound, ownertype = [], None | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         input = Res.FSOpenResourceFile(rsrcname, RESOURCE_FORK_NAME, READ) | 
					
						
							|  |  |  |     except (MacOS.Error, ValueError): | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  |         if progress: | 
					
						
							|  |  |  |             progress.inc(50) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         if is_update: | 
					
						
							|  |  |  |             skip_oldfile = ['cfrg'] | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             skip_oldfile = [] | 
					
						
							|  |  |  |         typesfound, ownertype = copyres(input, output, skip_oldfile, 0, progress) | 
					
						
							|  |  |  |         Res.CloseResFile(input) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Check which resource-types we should not copy from the template | 
					
						
							|  |  |  |     skiptypes = [] | 
					
						
							|  |  |  |     if 'vers' in typesfound: skiptypes.append('vers') | 
					
						
							|  |  |  |     if 'SIZE' in typesfound: skiptypes.append('SIZE') | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |     if 'BNDL' in typesfound: skiptypes = skiptypes + ['BNDL', 'FREF', 'icl4', | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |             'icl8', 'ics4', 'ics8', 'ICN#', 'ics#'] | 
					
						
							|  |  |  |     if not copy_codefragment: | 
					
						
							|  |  |  |         skiptypes.append('cfrg') | 
					
						
							| 
									
										
										
										
											2006-08-24 03:53:23 +00:00
										 |  |  | ##  skipowner = (ownertype != None) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Copy the resources from the template | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     input = Res.FSOpenResourceFile(template, RESOURCE_FORK_NAME, READ) | 
					
						
							|  |  |  |     dummy, tmplowner = copyres(input, output, skiptypes, 1, progress) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     Res.CloseResFile(input) | 
					
						
							| 
									
										
											  
											
												Merged revisions 62021,62029,62035-62038,62043-62044,62052-62053 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
  r62021 | benjamin.peterson | 2008-03-28 18:11:01 -0500 (Fri, 28 Mar 2008) | 2 lines
  NIL => NULL
........
  r62029 | amaury.forgeotdarc | 2008-03-28 20:42:31 -0500 (Fri, 28 Mar 2008) | 3 lines
  Correctly call the base class tearDown();
  otherwise running test_logging twice produce the errors we see on all buildbots
........
  r62035 | raymond.hettinger | 2008-03-29 05:42:07 -0500 (Sat, 29 Mar 2008) | 1 line
  Be explicit about what efficient means.
........
  r62036 | georg.brandl | 2008-03-29 06:46:18 -0500 (Sat, 29 Mar 2008) | 2 lines
  Fix capitalization.
........
  r62037 | amaury.forgeotdarc | 2008-03-29 07:42:54 -0500 (Sat, 29 Mar 2008) | 5 lines
  lib2to3 should install a logging handler only when run as a main program,
  not when used as a library.
  This may please the buildbots, which fail when test_lib2to3 is run before test_logging.
........
  r62043 | benjamin.peterson | 2008-03-29 10:24:25 -0500 (Sat, 29 Mar 2008) | 3 lines
  #2503 make singletons compared with "is" not == or !=
  Thanks to Wummel for the patch
........
  r62044 | gerhard.haering | 2008-03-29 14:11:52 -0500 (Sat, 29 Mar 2008) | 2 lines
  Documented the lastrowid attribute.
........
  r62052 | benjamin.peterson | 2008-03-30 14:35:10 -0500 (Sun, 30 Mar 2008) | 2 lines
  Updated README regarding doc formats
........
  r62053 | georg.brandl | 2008-03-30 14:41:39 -0500 (Sun, 30 Mar 2008) | 2 lines
  The other download formats will be available for 2.6 too.
........
											
										 
											2008-03-31 01:51:45 +00:00
										 |  |  | ##  if ownertype is None: | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  | ##      raise BuildError, "No owner resource found in either resource file or template" | 
					
						
							|  |  |  |     # Make sure we're manipulating the output resource file now | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     Res.UseResFile(output) | 
					
						
							| 
									
										
										
										
											1999-03-17 22:57:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 62021,62029,62035-62038,62043-62044,62052-62053 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
  r62021 | benjamin.peterson | 2008-03-28 18:11:01 -0500 (Fri, 28 Mar 2008) | 2 lines
  NIL => NULL
........
  r62029 | amaury.forgeotdarc | 2008-03-28 20:42:31 -0500 (Fri, 28 Mar 2008) | 3 lines
  Correctly call the base class tearDown();
  otherwise running test_logging twice produce the errors we see on all buildbots
........
  r62035 | raymond.hettinger | 2008-03-29 05:42:07 -0500 (Sat, 29 Mar 2008) | 1 line
  Be explicit about what efficient means.
........
  r62036 | georg.brandl | 2008-03-29 06:46:18 -0500 (Sat, 29 Mar 2008) | 2 lines
  Fix capitalization.
........
  r62037 | amaury.forgeotdarc | 2008-03-29 07:42:54 -0500 (Sat, 29 Mar 2008) | 5 lines
  lib2to3 should install a logging handler only when run as a main program,
  not when used as a library.
  This may please the buildbots, which fail when test_lib2to3 is run before test_logging.
........
  r62043 | benjamin.peterson | 2008-03-29 10:24:25 -0500 (Sat, 29 Mar 2008) | 3 lines
  #2503 make singletons compared with "is" not == or !=
  Thanks to Wummel for the patch
........
  r62044 | gerhard.haering | 2008-03-29 14:11:52 -0500 (Sat, 29 Mar 2008) | 2 lines
  Documented the lastrowid attribute.
........
  r62052 | benjamin.peterson | 2008-03-30 14:35:10 -0500 (Sun, 30 Mar 2008) | 2 lines
  Updated README regarding doc formats
........
  r62053 | georg.brandl | 2008-03-30 14:41:39 -0500 (Sun, 30 Mar 2008) | 2 lines
  The other download formats will be available for 2.6 too.
........
											
										 
											2008-03-31 01:51:45 +00:00
										 |  |  |     if ownertype is None: | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |         # No owner resource in the template. We have skipped the | 
					
						
							|  |  |  |         # Python owner resource, so we have to add our own. The relevant | 
					
						
							|  |  |  |         # bundle stuff is already included in the interpret/applet template. | 
					
						
							|  |  |  |         newres = Res.Resource('\0') | 
					
						
							|  |  |  |         newres.AddResource(DEFAULT_APPLET_CREATOR, 0, "Owner resource") | 
					
						
							|  |  |  |         ownertype = DEFAULT_APPLET_CREATOR | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if code: | 
					
						
							|  |  |  |         # Delete any existing 'PYC ' resource named __main__ | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |         try: | 
					
						
							|  |  |  |             res = Res.Get1NamedResource(RESTYPE, RESNAME) | 
					
						
							|  |  |  |             res.RemoveResource() | 
					
						
							|  |  |  |         except Res.Error: | 
					
						
							|  |  |  |             pass | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |         # Create the raw data for the resource from the code object | 
					
						
							|  |  |  |         if progress: | 
					
						
							|  |  |  |             progress.label("Write PYC resource...") | 
					
						
							|  |  |  |             progress.set(120) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |         data = marshal.dumps(code) | 
					
						
							|  |  |  |         del code | 
					
						
							|  |  |  |         data = (MAGIC + '\0\0\0\0') + data | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |         # Create the resource and write it | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |         id = 0 | 
					
						
							|  |  |  |         while id < 128: | 
					
						
							|  |  |  |             id = Res.Unique1ID(RESTYPE) | 
					
						
							|  |  |  |         res = Res.Resource(data) | 
					
						
							|  |  |  |         res.AddResource(RESTYPE, id, RESNAME) | 
					
						
							|  |  |  |         attrs = res.GetResAttrs() | 
					
						
							|  |  |  |         attrs = attrs | 0x04    # set preload | 
					
						
							|  |  |  |         res.SetResAttrs(attrs) | 
					
						
							|  |  |  |         res.WriteResource() | 
					
						
							|  |  |  |         res.ReleaseResource() | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Close the output file | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     Res.CloseResFile(output) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Now set the creator, type and bundle bit of the destination. | 
					
						
							|  |  |  |     # Done with FSSpec's, FSRef FInfo isn't good enough yet (2.3a1+) | 
					
						
							|  |  |  |     dest_fss = Carbon.File.FSSpec(destname) | 
					
						
							|  |  |  |     dest_finfo = dest_fss.FSpGetFInfo() | 
					
						
							|  |  |  |     dest_finfo.Creator = ownertype | 
					
						
							|  |  |  |     dest_finfo.Type = 'APPL' | 
					
						
							|  |  |  |     dest_finfo.Flags = dest_finfo.Flags | Carbon.Files.kHasBundle | Carbon.Files.kIsShared | 
					
						
							|  |  |  |     dest_finfo.Flags = dest_finfo.Flags & ~Carbon.Files.kHasBeenInited | 
					
						
							|  |  |  |     dest_fss.FSpSetFInfo(dest_finfo) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     macostools.touched(destname) | 
					
						
							|  |  |  |     if progress: | 
					
						
							|  |  |  |         progress.label("Done.") | 
					
						
							|  |  |  |         progress.inc(0) | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | def process_common_macho(template, progress, code, rsrcname, destname, is_update, | 
					
						
							| 
									
										
										
										
											2004-12-27 15:51:03 +00:00
										 |  |  |         raw=0, others=[], filename=None, destroot=""): | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # Check that we have a filename | 
					
						
							|  |  |  |     if filename is None: | 
					
						
							| 
									
										
										
										
											2007-08-23 00:01:55 +00:00
										 |  |  |         raise BuildError("Need source filename on MacOSX") | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     # First make sure the name ends in ".app" | 
					
						
							|  |  |  |     if destname[-4:] != '.app': | 
					
						
							|  |  |  |         destname = destname + '.app' | 
					
						
							|  |  |  |     # Now deduce the short name | 
					
						
							|  |  |  |     destdir, shortname = os.path.split(destname) | 
					
						
							|  |  |  |     if shortname[-4:] == '.app': | 
					
						
							|  |  |  |         # Strip the .app suffix | 
					
						
							|  |  |  |         shortname = shortname[:-4] | 
					
						
							|  |  |  |     # And deduce the .plist and .icns names | 
					
						
							|  |  |  |     plistname = None | 
					
						
							|  |  |  |     icnsname = None | 
					
						
							|  |  |  |     if rsrcname and rsrcname[-5:] == '.rsrc': | 
					
						
							|  |  |  |         tmp = rsrcname[:-5] | 
					
						
							|  |  |  |         plistname = tmp + '.plist' | 
					
						
							|  |  |  |         if os.path.exists(plistname): | 
					
						
							|  |  |  |             icnsname = tmp + '.icns' | 
					
						
							|  |  |  |             if not os.path.exists(icnsname): | 
					
						
							|  |  |  |                 icnsname = None | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             plistname = None | 
					
						
							| 
									
										
										
										
											2003-04-22 14:33:48 +00:00
										 |  |  |     if not icnsname: | 
					
						
							|  |  |  |         dft_icnsname = os.path.join(sys.prefix, 'Resources/Python.app/Contents/Resources/PythonApplet.icns') | 
					
						
							|  |  |  |         if os.path.exists(dft_icnsname): | 
					
						
							|  |  |  |             icnsname = dft_icnsname | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if not os.path.exists(rsrcname): | 
					
						
							|  |  |  |         rsrcname = None | 
					
						
							|  |  |  |     if progress: | 
					
						
							|  |  |  |         progress.label('Creating bundle...') | 
					
						
							|  |  |  |     import bundlebuilder | 
					
						
							|  |  |  |     builder = bundlebuilder.AppBuilder(verbosity=0) | 
					
						
							|  |  |  |     builder.mainprogram = filename | 
					
						
							|  |  |  |     builder.builddir = destdir | 
					
						
							|  |  |  |     builder.name = shortname | 
					
						
							| 
									
										
										
										
											2004-12-27 15:51:03 +00:00
										 |  |  |     builder.destroot = destroot | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     if rsrcname: | 
					
						
							|  |  |  |         realrsrcname = macresource.resource_pathname(rsrcname) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |         builder.files.append((realrsrcname, | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |             os.path.join('Contents/Resources', os.path.basename(rsrcname)))) | 
					
						
							|  |  |  |     for o in others: | 
					
						
							|  |  |  |         if type(o) == str: | 
					
						
							|  |  |  |             builder.resources.append(o) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             builder.files.append(o) | 
					
						
							|  |  |  |     if plistname: | 
					
						
							|  |  |  |         import plistlib | 
					
						
							|  |  |  |         builder.plist = plistlib.Plist.fromFile(plistname) | 
					
						
							|  |  |  |     if icnsname: | 
					
						
							|  |  |  |         builder.iconfile = icnsname | 
					
						
							|  |  |  |     if not raw: | 
					
						
							|  |  |  |         builder.argv_emulation = 1 | 
					
						
							|  |  |  |     builder.setup() | 
					
						
							|  |  |  |     builder.build() | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |     if progress: | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |         progress.label('Done.') | 
					
						
							|  |  |  |         progress.inc(0) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  | ##  macostools.touched(dest_fss) | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Copy resources between two resource file descriptors. | 
					
						
							| 
									
										
										
										
											1999-03-17 22:57:55 +00:00
										 |  |  | # skip a resource named '__main__' or (if skipowner is set) with ID zero. | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | # Also skip resources with a type listed in skiptypes. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | def copyres(input, output, skiptypes, skipowner, progress=None): | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     ctor = None | 
					
						
							|  |  |  |     alltypes = [] | 
					
						
							|  |  |  |     Res.UseResFile(input) | 
					
						
							|  |  |  |     ntypes = Res.Count1Types() | 
					
						
							|  |  |  |     progress_type_inc = 50/ntypes | 
					
						
							|  |  |  |     for itype in range(1, 1+ntypes): | 
					
						
							|  |  |  |         type = Res.Get1IndType(itype) | 
					
						
							|  |  |  |         if type in skiptypes: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         alltypes.append(type) | 
					
						
							|  |  |  |         nresources = Res.Count1Resources(type) | 
					
						
							|  |  |  |         progress_cur_inc = progress_type_inc/nresources | 
					
						
							|  |  |  |         for ires in range(1, 1+nresources): | 
					
						
							|  |  |  |             res = Res.Get1IndResource(type, ires) | 
					
						
							|  |  |  |             id, type, name = res.GetResInfo() | 
					
						
							| 
									
										
										
										
											2007-04-17 08:48:32 +00:00
										 |  |  |             lcname = name.lower() | 
					
						
							| 
									
										
										
										
											1999-03-17 22:57:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |             if lcname == OWNERNAME and id == 0: | 
					
						
							|  |  |  |                 if skipowner: | 
					
						
							|  |  |  |                     continue # Skip this one | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     ctor = type | 
					
						
							|  |  |  |             size = res.size | 
					
						
							|  |  |  |             attrs = res.GetResAttrs() | 
					
						
							|  |  |  |             if progress: | 
					
						
							|  |  |  |                 progress.label("Copy %s %d %s"%(type, id, name)) | 
					
						
							|  |  |  |                 progress.inc(progress_cur_inc) | 
					
						
							|  |  |  |             res.LoadResource() | 
					
						
							|  |  |  |             res.DetachResource() | 
					
						
							|  |  |  |             Res.UseResFile(output) | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 res2 = Res.Get1Resource(type, id) | 
					
						
							|  |  |  |             except MacOS.Error: | 
					
						
							|  |  |  |                 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) | 
					
						
							|  |  |  |             res.WriteResource() | 
					
						
							|  |  |  |             attrs = attrs | res.GetResAttrs() | 
					
						
							|  |  |  |             res.SetResAttrs(attrs) | 
					
						
							|  |  |  |             Res.UseResFile(input) | 
					
						
							|  |  |  |     return alltypes, ctor | 
					
						
							| 
									
										
										
										
											1998-07-31 09:42:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-09 22:08:52 +00:00
										 |  |  | def copyapptree(srctree, dsttree, exceptlist=[], progress=None): | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     names = [] | 
					
						
							|  |  |  |     if os.path.exists(dsttree): | 
					
						
							|  |  |  |         shutil.rmtree(dsttree) | 
					
						
							|  |  |  |     os.mkdir(dsttree) | 
					
						
							|  |  |  |     todo = os.listdir(srctree) | 
					
						
							|  |  |  |     while todo: | 
					
						
							|  |  |  |         this, todo = todo[0], todo[1:] | 
					
						
							|  |  |  |         if this in exceptlist: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         thispath = os.path.join(srctree, this) | 
					
						
							|  |  |  |         if os.path.isdir(thispath): | 
					
						
							|  |  |  |             thiscontent = os.listdir(thispath) | 
					
						
							|  |  |  |             for t in thiscontent: | 
					
						
							|  |  |  |                 todo.append(os.path.join(this, t)) | 
					
						
							|  |  |  |         names.append(this) | 
					
						
							|  |  |  |     for this in names: | 
					
						
							|  |  |  |         srcpath = os.path.join(srctree, this) | 
					
						
							|  |  |  |         dstpath = os.path.join(dsttree, this) | 
					
						
							|  |  |  |         if os.path.isdir(srcpath): | 
					
						
							|  |  |  |             os.mkdir(dstpath) | 
					
						
							|  |  |  |         elif os.path.islink(srcpath): | 
					
						
							|  |  |  |             endpoint = os.readlink(srcpath) | 
					
						
							|  |  |  |             os.symlink(endpoint, dstpath) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             if progress: | 
					
						
							|  |  |  |                 progress.label('Copy '+this) | 
					
						
							|  |  |  |                 progress.inc(0) | 
					
						
							|  |  |  |             shutil.copy2(srcpath, dstpath) | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-03-29 21:21:28 +00:00
										 |  |  | def writepycfile(codeobject, cfile): | 
					
						
							| 
									
										
										
										
											2003-04-09 13:25:43 +00:00
										 |  |  |     import marshal | 
					
						
							|  |  |  |     fc = open(cfile, 'wb') | 
					
						
							|  |  |  |     fc.write('\0\0\0\0') # MAGIC placeholder, written later | 
					
						
							|  |  |  |     fc.write('\0\0\0\0') # Timestap placeholder, not needed | 
					
						
							|  |  |  |     marshal.dump(codeobject, fc) | 
					
						
							|  |  |  |     fc.flush() | 
					
						
							|  |  |  |     fc.seek(0, 0) | 
					
						
							|  |  |  |     fc.write(MAGIC) | 
					
						
							|  |  |  |     fc.close() |