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)
def __init__(self, name_finfo_dlen_rlen, ofp): name, finfo, dlen, rlen = name_finfo_dlen_rlen if type(ofp) == type(''): ofname = ofp ofp = open(ofname, 'w') if os.name == 'mac': fss = FSSpec(ofname) fss.SetCreatorType('BnHq', 'TEXT') ofp.write('(This file must be converted with BinHex 4.0)\n\n:') hqxer = _Hqxcoderengine(ofp) self.ofp = _Rlecoderengine(hqxer) self.crc = 0 if finfo is None: finfo = FInfo() self.dlen = dlen self.rlen = rlen self._writeinfo(name, finfo) self.state = _DID_HEADER
def getfileinfo(name): finfo = FSSpec(name).FSpGetFInfo() dir, file = os.path.split(name) fp = open(name, 'rb') fp.seek(0, 2) dlen = fp.tell() fp = openrf(name, '*rb') fp.seek(0, 2) rlen = fp.tell() return (file, finfo, dlen, rlen)
def getfileinfo(name): finfo = FSSpec(name).FSpGetFInfo() dir, file = os.path.split(name) # XXX Get resource/data sizes fp = open(name, 'rb') fp.seek(0, 2) dlen = fp.tell() fp = openrf(name, '*rb') fp.seek(0, 2) rlen = fp.tell() return file, finfo, dlen, rlen
def hexbin(inp, out): """(infilename, outfilename) - Decode binhexed file""" ifp = HexBin(inp) finfo = ifp.FInfo if not out: out = ifp.FName if os.name == 'mac': ofss = FSSpec(out) out = ofss.as_pathname() ofp = open(out, 'wb') # XXXX Do translation on non-mac systems while 1: d = ifp.read(128000) if not d: break ofp.write(d) ofp.close() ifp.close_data() d = ifp.read_rsrc(128000) if d: ofp = openrsrc(out, 'wb') ofp.write(d) while 1: d = ifp.read_rsrc(128000) if not d: break ofp.write(d) ofp.close() if os.name == 'mac': nfinfo = ofss.GetFInfo() nfinfo.Creator = finfo.Creator nfinfo.Type = finfo.Type nfinfo.Flags = finfo.Flags ofss.SetFInfo(nfinfo) ifp.close()
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
""" 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
def alias_to(file): path = os.path.join(os.getcwd(), file) fss = FSSpec(path) return fss.NewAlias()