Exemple #1
0
	def write_carbonfile(self, cfile):
		"""Write new carbon data to self."""
		if not cfile: return
		log.Log("Writing carbon data to %s" % (self.index,), 7)
		from Carbon.File import FSSpec
		from Carbon.File import FSRef
		import Carbon.Files
		import MacOS
		fsobj = FSSpec(self.path)
		finderinfo = fsobj.FSpGetFInfo()
		finderinfo.Creator = cfile['creator']
		finderinfo.Type = cfile['type']
		finderinfo.Location = cfile['location']
		finderinfo.Flags = cfile['flags']
		fsobj.FSpSetFInfo(finderinfo)

		"""Write Creation Date to self (if stored in metadata)."""
		try:
			cdate = cfile['createDate']
			fsref = FSRef(fsobj)
			cataloginfo, d1, d2, d3 = fsref.FSGetCatalogInfo(Carbon.Files.kFSCatInfoCreateDate)
			cataloginfo.createDate = (0, cdate, 0)
			fsref.FSSetCatalogInfo(Carbon.Files.kFSCatInfoCreateDate, cataloginfo)
			self.set_carbonfile(cfile)
		except KeyError: self.set_carbonfile(cfile)
Exemple #2
0
    def build_alias_executable(self, target, script):
        # Build an alias executable for the target
        appdir, resdir, plist = self.create_bundle(target, script)

        # symlink python executable
        execdst = os.path.join(appdir, 'Contents', 'MacOS', 'python')
        self.symlink(sys.executable, execdst)

        # make PYTHONHOME
        pyhome = os.path.join(resdir, 'lib', 'python' + sys.version[:3])
        realhome = os.path.join(sys.prefix, 'lib', 'python' + sys.version[:3])
        makedirs(pyhome)
        self.symlink('../../site.py', os.path.join(pyhome, 'site.py'))
        self.symlink(os.path.join(realhome, 'config'),
                     os.path.join(pyhome, 'config'))

        # symlink data files
        # XXX: fixme: need to integrate automatic data conversion
        for src, dest in self.iter_data_files():
            dest = os.path.join(resdir, dest)
            if src == dest:
                continue
            makedirs(os.path.dirname(dest))
            self.symlink(os.path.abspath(src), dest)

        # symlink frameworks
        for src in self.iter_frameworks():
            dest = os.path.join(appdir, 'Contents', 'Frameworks',
                                os.path.basename(src))
            if src == dest:
                continue
            makedirs(os.path.dirname(dest))
            self.symlink(os.path.abspath(src), dest)

        self.compile_datamodels(resdir)
        self.compile_mappingmodels(resdir)

        from Carbon.File import FSRef
        aliasdata = FSRef(script).FSNewAliasMinimal().data

        bootfn = '__boot__'
        bootfile = file(os.path.join(resdir, bootfn + '.py'), 'w')
        for fn in target.prescripts:
            bootfile.write(self.get_bootstrap_data(fn))
            bootfile.write('\n\n')
        bootfile.write('try:\n')
        bootfile.write('    _run((%r, %r))\n' % (
            aliasdata,
            os.path.realpath(script),
        ))
        bootfile.write('except KeyboardInterrupt:\n')
        bootfile.write('    pass\n')
        bootfile.close()

        target.appdir = appdir
        return appdir
Exemple #3
0
def readPlistFromResource(path, restype='plst', resid=0):
    """Read plst resource from the resource fork of path.
    """
    from Carbon.File import FSRef, FSGetResourceForkName
    from Carbon.Files import fsRdPerm
    from Carbon import Res
    fsRef = FSRef(path)
    resNum = Res.FSOpenResourceFile(fsRef, FSGetResourceForkName(), fsRdPerm)
    Res.UseResFile(resNum)
    plistData = Res.Get1Resource(restype, resid).data
    Res.CloseResFile(resNum)
    return readPlistFromString(plistData)
def readPlistFromResource(path, restype='plst', resid=0):
    warnings.warnpy3k('In 3.x, readPlistFromResource is removed.',
                      stacklevel=2)
    from Carbon.File import FSRef, FSGetResourceForkName
    from Carbon.Files import fsRdPerm
    from Carbon import Res
    fsRef = FSRef(path)
    resNum = Res.FSOpenResourceFile(fsRef, FSGetResourceForkName(), fsRdPerm)
    Res.UseResFile(resNum)
    plistData = Res.Get1Resource(restype, resid).data
    Res.CloseResFile(resNum)
    return readPlistFromString(plistData)
Exemple #5
0
def writePlistToResource(rootObject, path, restype='plst', resid=0):
    """Write 'rootObject' as a plst resource to the resource fork of path.
    """
    from Carbon.File import FSRef, FSGetResourceForkName
    from Carbon.Files import fsRdWrPerm
    from Carbon import Res
    plistData = writePlistToString(rootObject)
    fsRef = FSRef(path)
    resNum = Res.FSOpenResourceFile(fsRef, FSGetResourceForkName(), fsRdWrPerm)
    Res.UseResFile(resNum)
    try:
        Res.Get1Resource(restype, resid).RemoveResource()
    except Res.Error:
        pass
    res = Res.Resource(plistData)
    res.AddResource(restype, resid, '')
    res.WriteResource()
    Res.CloseResFile(resNum)
def writePlistToResource(rootObject, path, restype='plst', resid=0):
    warnings.warnpy3k('In 3.x, writePlistToResource is removed.', stacklevel=2)
    from Carbon.File import FSRef, FSGetResourceForkName
    from Carbon.Files import fsRdWrPerm
    from Carbon import Res
    plistData = writePlistToString(rootObject)
    fsRef = FSRef(path)
    resNum = Res.FSOpenResourceFile(fsRef, FSGetResourceForkName(), fsRdWrPerm)
    Res.UseResFile(resNum)
    try:
        Res.Get1Resource(restype, resid).RemoveResource()
    except Res.Error:
        pass

    res = Res.Resource(plistData)
    res.AddResource(restype, resid, '')
    res.WriteResource()
    Res.CloseResFile(resNum)
Exemple #7
0
def carbonfile_get(rpath):
	"""Return carbonfile value for local rpath"""
	# Note, after we drop support for Mac OS X 10.0 - 10.3, it will no longer
	# be necessary to read the finderinfo struct since it is a strict subset
	# of the data stored in the com.apple.FinderInfo extended attribute
	# introduced in 10.4. Indeed, FSpGetFInfo() is deprecated on 10.4.
	from Carbon.File import FSSpec
	from Carbon.File import FSRef
	import Carbon.Files
	import MacOS
	try:
		fsobj = FSSpec(rpath.path)
		finderinfo = fsobj.FSpGetFInfo()
		cataloginfo, d1, d2, d3 = FSRef(fsobj).FSGetCatalogInfo(Carbon.Files.kFSCatInfoCreateDate)
		cfile = {'creator': finderinfo.Creator,
				 'type': finderinfo.Type,
				 'location': finderinfo.Location,
				 'flags': finderinfo.Flags,
				 'createDate': cataloginfo.createDate[1]}
		return cfile
	except MacOS.Error:
		log.Log("Cannot read carbonfile information from %s" %
				(rpath.path,), 2)
		return None
Exemple #8
0

def carbonfile_get(rpath):
    """Return carbonfile value for local rpath"""
    # Note, after we drop support for Mac OS X 10.0 - 10.3, it will no longer
    # be necessary to read the finderinfo struct since it is a strict subset
    # of the data stored in the com.apple.FinderInfo extended attribute
    # introduced in 10.4. Indeed, FSpGetFInfo() is deprecated on 10.4.
    from Carbon.File import FSSpec
    from Carbon.File import FSRef
    import Carbon.Files
    import MacOS
    try:
        fsobj = FSSpec(rpath.path)
        finderinfo = fsobj.FSpGetFInfo()
        cataloginfo, d1, d2, d3 = FSRef(fsobj).FSGetCatalogInfo(
            Carbon.Files.kFSCatInfoCreateDate)
        cfile = {
            'creator': finderinfo.Creator,
            'type': finderinfo.Type,
            'location': finderinfo.Location,
            'flags': finderinfo.Flags,
            'createDate': cataloginfo.createDate[1]
        }
        return cfile
    except MacOS.Error:
        log.Log("Cannot read carbonfile information from %s" % (rpath.path, ),
                2)
        return None


# These functions are overwritten by the eas_acls.py module.  We can't