Ejemplo n.º 1
0
 def test_copy(self):
     try:
         os.unlink(TESTFN2)
     except:
         pass
     macostools.copy(test_support.TESTFN, TESTFN2)
     self.assertEqual(self.compareData(), '')
Ejemplo n.º 2
0
def copycwproject(path, name):
	"""Copy CW project (if needed) and remember for hexbinning"""
	global project_files
	
	dstdir = os.path.join(TOP, CWDIR)
	if not os.path.exists(dstdir):
		print dstdir
		print 'No CW-project dir, skip', name
		return
	dstfile = os.path.join(dstdir, name)
	# Check that we're not in the dest directory
	if dstfile == path:
		return

	# If the destination doesn't exists or is older that the source
	# we copy and remember it
	
	if os.path.exists(dstfile) and \
			os.stat(dstfile)[8] > os.stat(path)[8]:
		print 'Not copying', path,'- Up-to-date'
	else:
		print 'Copy', path
		macostools.copy(path, dstfile)
	
	fss = macfs.FSSpec(dstfile)
	creator = fss.GetCreatorType()[0]
	
	if project_files.has_key(creator):
		project_files[creator].append(fss)
	else:
		project_files[creator] = [fss]	
Ejemplo n.º 3
0
 def test_copy(self):
     try:
         os.unlink(TESTFN2)
     except:
         pass
     macostools.copy(test_support.TESTFN, TESTFN2)
     self.assertEqual(self.compareData(), '')
Ejemplo n.º 4
0
 def rundir(self, path, destprefix, doit):
     files = os.listdir(path)
     todo = []
     rv = 1
     for f in files:
         if self.exc.match(f):
             continue
         fullname = os.path.join(path, f)
         if os.path.isdir(fullname):
             todo.append(fullname)
         else:
             dest = self.inc.match(fullname)
             if dest == None:
                 print 'Not yet resolved:', fullname
                 rv = 0
             if dest:
                 if doit:
                     print 'COPY ', fullname
                     print '  -> ', os.path.join(destprefix, dest)
                     macostools.copy(fullname,
                                     os.path.join(destprefix, dest), 1)
     for d in todo:
         if not self.rundir(d, destprefix, doit):
             rv = 0
     return rv
Ejemplo n.º 5
0
	def rundir(self, path, destprefix, doit):
		files = os.listdir(path)
		todo = []
		rv = 1
		for f in files:
			if self.exc.match(f):
				continue
			fullname = os.path.join(path, f)
			if os.path.isdir(fullname):
				todo.append(fullname)
			else:
				dest = self.inc.match(fullname)
				if dest == None:
					print 'Not yet resolved:', fullname
					rv = 0
				if dest:
					if doit:
						print 'COPY ', fullname
						print '  -> ', os.path.join(destprefix, dest)
						try:
							macostools.copy(fullname, os.path.join(destprefix, dest), 1)
						except: #DBG
							print '*** Copy failed mysteriously, try again'
							print '*** cwd', os.getcwd() #DBG
							print '*** fsspec', macfs.FSSpec(fullname) #DBG
							# Get rid of open files
							try:
								i = 1 / 0
							except:
								pass
							macostools.copy(fullname, os.path.join(destprefix, dest), 1)
		for d in todo:
			if not self.rundir(d, destprefix, doit):
				rv = 0
		return rv
Ejemplo n.º 6
0
def copycwproject(path, name):
    """Copy CW project (if needed) and remember for hexbinning"""
    global project_files

    dstdir = os.path.join(TOP, CWDIR)
    if not os.path.exists(dstdir):
        print dstdir
        print 'No CW-project dir, skip', name
        return
    dstfile = os.path.join(dstdir, name)
    # Check that we're not in the dest directory
    if dstfile == path:
        return

    # If the destination doesn't exists or is older that the source
    # we copy and remember it

    if os.path.exists(dstfile) and \
      os.stat(dstfile)[8] > os.stat(path)[8]:
        print 'Not copying', path, '- Up-to-date'
    else:
        print 'Copy', path
        macostools.copy(path, dstfile)

    fss = macfs.FSSpec(dstfile)
    creator = fss.GetCreatorType()[0]

    if project_files.has_key(creator):
        project_files[creator].append(fss)
    else:
        project_files[creator] = [fss]
Ejemplo n.º 7
0
	def rundir(self, path, destprefix, doit):
		files = os.listdir(path)
		todo = []
		rv = 1
		for f in files:
			if self.exc.match(f):
				continue
			fullname = os.path.join(path, f)
			if os.path.isdir(fullname):
				todo.append(fullname)
			else:
				dest = self.inc.match(fullname)
				if dest == None:
					print 'Not yet resolved:', fullname
					rv = 0
				if dest:
					if doit:
						print 'COPY ', fullname
						print '  -> ', os.path.join(destprefix, dest)
						macostools.copy(fullname, os.path.join(destprefix, dest), 1)
		for d in todo:
			if not self.rundir(d, destprefix, doit):
				rv = 0
		return rv
Ejemplo n.º 8
0
def osx_copy(dest, source, env):
    from macostools import copy
    copy(source, dest)
    shutil.copymode(source, dest)
Ejemplo n.º 9
0
def copyfile(src, dst):
    """
        Use the Mac OS X-specific version of copyfile() so that
        Mac OS X stuff gets handled properly.
        """
    macostools.copy(src, dst)
Ejemplo n.º 10
0
#
Ejemplo n.º 11
0
"""macgen_info - Generate CodeWarrior project, config source, resource file"""
Ejemplo n.º 12
0
def copy_file (src, dst,
               preserve_mode=1,
               preserve_times=1,
               update=0,
               link=None,
               verbose=1,
               dry_run=0):

    """Copy a file 'src' to 'dst'.  If 'dst' is a directory, then 'src' is
    copied there with the same name; otherwise, it must be a filename.  (If
    the file exists, it will be ruthlessly clobbered.)  If 'preserve_mode'
    is true (the default), the file's mode (type and permission bits, or
    whatever is analogous on the current platform) is copied.  If
    'preserve_times' is true (the default), the last-modified and
    last-access times are copied as well.  If 'update' is true, 'src' will
    only be copied if 'dst' does not exist, or if 'dst' does exist but is
    older than 'src'.

    'link' allows you to make hard links (os.link) or symbolic links
    (os.symlink) instead of copying: set it to "hard" or "sym"; if it is
    None (the default), files are copied.  Don't set 'link' on systems that
    don't support it: 'copy_file()' doesn't check if hard or symbolic
    linking is available.

    Under Mac OS, uses the native file copy function in macostools; on
    other systems, uses '_copy_file_contents()' to copy file contents.

    Return a tuple (dest_name, copied): 'dest_name' is the actual name of
    the output file, and 'copied' is true if the file was copied (or would
    have been copied, if 'dry_run' true).
    """
    # XXX if the destination file already exists, we clobber it if
    # copying, but blow up if linking.  Hmmm.  And I don't know what
    # macostools.copyfile() does.  Should definitely be consistent, and
    # should probably blow up if destination exists and we would be
    # changing it (ie. it's not already a hard/soft link to src OR
    # (not update) and (src newer than dst).

    from distutils.dep_util import newer
    from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE

    if not os.path.isfile(src):
        raise DistutilsFileError, \
              "can't copy '%s': doesn't exist or not a regular file" % src

    if os.path.isdir(dst):
        dir = dst
        dst = os.path.join(dst, os.path.basename(src))
    else:
        dir = os.path.dirname(dst)

    if update and not newer(src, dst):
        if verbose >= 1:
            log.debug("not copying %s (output up-to-date)", src)
        return dst, 0

    try:
        action = _copy_action[link]
    except KeyError:
        raise ValueError, \
              "invalid value '%s' for 'link' argument" % link

    if verbose >= 1:
        if os.path.basename(dst) == os.path.basename(src):
            log.info("%s %s -> %s", action, src, dir)
        else:
            log.info("%s %s -> %s", action, src, dst)

    if dry_run:
        return (dst, 1)

    # On Mac OS, use the native file copy routine
    if os.name == 'mac':
        import macostools
        try:
            macostools.copy(src, dst, 0, preserve_times)
        except os.error, exc:
            raise DistutilsFileError, \
                  "could not copy '%s' to '%s': %s" % (src, dst, exc[-1])
Ejemplo n.º 13
0
def copyfile(src, dst):
    """
        Use the Mac OS X-specific version of copyfile() so that
        Mac OS X stuff gets handled properly.
        """
    macostools.copy(src, dst)
Ejemplo n.º 14
0
# This python script creates Finder aliases for all the
Ejemplo n.º 15
0
"""distutils.file_util
Ejemplo n.º 16
0
#
Ejemplo n.º 17
0
#
Ejemplo n.º 18
0
def osx_copy(dest, source, env):
    from macostools import copy

    copy(source, dest)
    shutil.copymode(source, dest)
Ejemplo n.º 19
0
def generate(output, module_dict, debug=0, with_ifdef=0):
    problems = 0
    output_created=0
    if not os.path.exists(output):
        print 'Creating project folder', output
        os.mkdir(output)
        output_created = 1
    # Resolve aliases, if needed
    try:
        fss, dummy1, dummy2 = macfs.ResolveAliasFile(output)
    except macfs.error:
        pass
    else:
        newname = fss.as_pathname()
        if newname != output:
            if debug:
                print 'Alias', output
                print 'Resolved to', newname
            output = newname
    # Construct the filenames
    dummy, outfile = os.path.split(output)
    build, ext = os.path.splitext(outfile)
    if build == 'build' and ext[0] == '.':
        # This is probably a good name for the project
        projname = ext[1:]
    else:
        projname = 'frozenapplet.prj'
    config_name = os.path.join(output, ':macfrozenconfig.c')
    project_name = os.path.join(output, ':' + projname + '.prj')
    resource_name = os.path.join(output, ':frozenmodules.rsrc')
    bundle_name = os.path.join(output, ':frozenbundle.rsrc')

    # Fill the output folder, if needed.
    if output_created:
        # Create the project, if needed
        if not os.path.exists(project_name):
            print 'Creating project', project_name
            if not os.path.exists(PROJECT_TEMPLATE):
                print '** No template CodeWarrior project found at', PROJECT_TEMPLATE
                print '   To generate standalone Python applications from source you need'
                print '   a full source distribution. Check http://www.cwi.nl/~jack/macpython.html'
                print '   for details.'
                problems = 1
            else:
                macostools.copy(PROJECT_TEMPLATE, project_name)
                print 'A template CodeWarrior project has been copied to', project_name
                print 'It is up to you to make the following changes:'
                print '- Change the output file name'
                print '- Change the search path, unless the folder is in the python home'
                print '- Add sourcefiles/libraries for any extension modules used'
                print '- Remove unused sources, to speed up the build process'
                print '- Remove unused resource files (like tcl/tk) for a smaller binary'
                problems = 1
                macostools.copy(BUNDLE_TEMPLATE, bundle_name)
                print 'A template bundle file has also been copied to', bundle_name
                print 'You may want to adapt signature, size resource, etc'


    # Create the resource file
    macgen_rsrc.generate(resource_name, module_dict, debug=debug)

    # Create the config.c file
    if not os.path.exists(CONFIG_TEMPLATE):
        print '** No template config.c found at', PROJECT_TEMPLATE
        print '   To generate standalone Python applications from source you need'
        print '   a full source distribution. Check http://www.cwi.nl/~jack/macpython.html'
        print '   for details.'
        problems = 1
    else:
        # Find elegible modules (builtins and dynamically loaded modules)
        c_modules = []
        for module in module_dict.keys():
            if module_dict[module].gettype() in ('builtin', 'dynamic'):
                # if the module is in a package we have no choice but
                # to put it at the toplevel in the frozen application.
                if '.' in module:
                    module = module.split('.')[-1]
                c_modules.append(module)
        ifp = open(CONFIG_TEMPLATE)
        ofp = open(config_name, 'w')
        makeconfig.makeconfig(ifp, ofp, c_modules, with_ifdef)
        ifp.close()
        ofp.close()
        MacOS.SetCreatorAndType(config_name, 'CWIE', 'TEXT')

    if warnings(module_dict):
        problems = 1
    return problems
Ejemplo n.º 20
0
#
Ejemplo n.º 21
0
 def test_copy(self):
     test_support.unlink(TESTFN2)
     macostools.copy(test_support.TESTFN, TESTFN2)
     self.assertEqual(self.compareData(), '')
Ejemplo n.º 22
0
# This python script creates Finder aliases for all the
Ejemplo n.º 23
0
"""distutils.file_util
Ejemplo n.º 24
0
#
Ejemplo n.º 25
0
def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0, link=None, verbose=1, dry_run=0):

    """Copy a file 'src' to 'dst'.  If 'dst' is a directory, then 'src' is
    copied there with the same name; otherwise, it must be a filename.  (If
    the file exists, it will be ruthlessly clobbered.)  If 'preserve_mode'
    is true (the default), the file's mode (type and permission bits, or
    whatever is analogous on the current platform) is copied.  If
    'preserve_times' is true (the default), the last-modified and
    last-access times are copied as well.  If 'update' is true, 'src' will
    only be copied if 'dst' does not exist, or if 'dst' does exist but is
    older than 'src'.

    'link' allows you to make hard links (os.link) or symbolic links
    (os.symlink) instead of copying: set it to "hard" or "sym"; if it is
    None (the default), files are copied.  Don't set 'link' on systems that
    don't support it: 'copy_file()' doesn't check if hard or symbolic
    linking is available.

    Under Mac OS, uses the native file copy function in macostools; on
    other systems, uses '_copy_file_contents()' to copy file contents.

    Return a tuple (dest_name, copied): 'dest_name' is the actual name of
    the output file, and 'copied' is true if the file was copied (or would
    have been copied, if 'dry_run' true).
    """
    # XXX if the destination file already exists, we clobber it if
    # copying, but blow up if linking.  Hmmm.  And I don't know what
    # macostools.copyfile() does.  Should definitely be consistent, and
    # should probably blow up if destination exists and we would be
    # changing it (ie. it's not already a hard/soft link to src OR
    # (not update) and (src newer than dst).

    from distutils.dep_util import newer
    from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE

    if not os.path.isfile(src):
        raise DistutilsFileError, "can't copy '%s': doesn't exist or not a regular file" % src

    if os.path.isdir(dst):
        dir = dst
        dst = os.path.join(dst, os.path.basename(src))
    else:
        dir = os.path.dirname(dst)

    if update and not newer(src, dst):
        if verbose >= 1:
            log.debug("not copying %s (output up-to-date)", src)
        return dst, 0

    try:
        action = _copy_action[link]
    except KeyError:
        raise ValueError, "invalid value '%s' for 'link' argument" % link

    if verbose >= 1:
        if os.path.basename(dst) == os.path.basename(src):
            log.info("%s %s -> %s", action, src, dir)
        else:
            log.info("%s %s -> %s", action, src, dst)

    if dry_run:
        return (dst, 1)

    # On Mac OS, use the native file copy routine
    if os.name == "mac":
        import macostools

        try:
            macostools.copy(src, dst, 0, preserve_times)
        except os.error, exc:
            raise DistutilsFileError, "could not copy '%s' to '%s': %s" % (src, dst, exc[-1])
Ejemplo n.º 26
0
 def test_copy(self):
     test_support.unlink(TESTFN2)
     macostools.copy(test_support.TESTFN, TESTFN2)
     self.assertEqual(self.compareData(), "")