Exemplo n.º 1
0
    def testOpenRF(self):
        try:
            fp = open(test_support.TESTFN, 'w')
            fp.write('hello world\n')
            fp.close()

            rfp = MacOS.openrf(test_support.TESTFN, '*wb')
            rfp.write('goodbye world\n')
            rfp.close()


            fp = open(test_support.TESTFN, 'r')
            data = fp.read()
            fp.close()
            self.assertEquals(data, 'hello world\n')

            rfp = MacOS.openrf(test_support.TESTFN, '*rb')
            data = rfp.read(100)
            data2 = rfp.read(100)
            rfp.close()
            self.assertEquals(data, 'goodbye world\n')
            self.assertEquals(data2, '')


        finally:
            os.unlink(test_support.TESTFN)
Exemplo n.º 2
0
    def _platform_cp(self, source_path, destination_path):
        ## copy file data
        source = self._open(source_path, 'rb')
        destination = self._open(destination_path, 'wb')

        self._raw_copy(source, destination)
        source.close()
        destination.close()

        ## copy resource file data
        source = MacOS.openrf(source_path, '*rb')
        destination = MacOS.openrf(destination_path, '*wb')
        self._raw_copy(source, destination)
        source.close()
        destination.close()

        ## set creator/type on the Macintosh
        source_spec = macfs.FSSpec(source_path)
        (creator, type) = source_spec.GetCreatorType()
        destination_spec = macfs.FSSpec(destination_path)
        destination_spec.SetCreatorType(creator, type)

        ## copy file mode/time bits
        st = os.stat(source_path)
        mtime = st[stat.ST_MTIME]
        destination_spec.SetDates(mtime, mtime, mtime)
Exemplo n.º 3
0
    def _platform_cp(self, source_path, destination_path):
        ## copy file data
        source = self._open(source_path, 'rb')
        destination = self._open(destination_path, 'wb')

        self._raw_copy(source, destination)
        source.close()
        destination.close()

        ## copy resource file data
        source = MacOS.openrf(source_path, '*rb')
        destination = MacOS.openrf(destination_path, '*wb')
        self._raw_copy(source, destination)
        source.close()
        destination.close()

        ## set creator/type on the Macintosh
        source_spec = macfs.FSSpec(source_path)
        (creator, type) = source_spec.GetCreatorType()
        destination_spec = macfs.FSSpec(destination_path)
        destination_spec.SetCreatorType(creator, type)

        ## copy file mode/time bits
        st = os.stat(source_path)
        mtime = st[stat.ST_MTIME]
        destination_spec.SetDates(mtime, mtime, mtime)
Exemplo n.º 4
0
 def setUp(self):
     fp = open(test_support.TESTFN, 'w')
     fp.write('hello world\n')
     fp.close()
     rfp = MacOS.openrf(test_support.TESTFN, '*wb')
     rfp.write('goodbye world\n')
     rfp.close()
Exemplo n.º 5
0
 def setUp(self):
     fp = open(test_support.TESTFN, 'w')
     fp.write('hello world\n')
     fp.close()
     rfp = MacOS.openrf(test_support.TESTFN, '*wb')
     rfp.write('goodbye world\n')
     rfp.close()
Exemplo n.º 6
0
 def compareData(self, isrf, data):
     if isrf:
         fp = MacOS.openrf(TESTFN2, '*rb')
     else:
         fp = open(TESTFN2, 'rb')
     filedata = fp.read(1000)
     self.assertEqual(data, filedata)
Exemplo n.º 7
0
 def compareData(self, isrf, data):
     if isrf:
         fp = MacOS.openrf(TESTFN2, '*rb')
     else:
         fp = open(TESTFN2, 'rb')
     filedata = fp.read(1000)
     self.assertEqual(data, filedata)
Exemplo n.º 8
0
 def compareData(self):
     fp = open(test_support.TESTFN, 'r')
     data1 = fp.read()
     fp.close()
     fp = open(TESTFN2, 'r')
     data2 = fp.read()
     fp.close()
     if data1 != data2:
         return 'Data forks differ'
     rfp = MacOS.openrf(test_support.TESTFN, '*rb')
     data1 = rfp.read(1000)
     rfp.close()
     rfp = MacOS.openrf(TESTFN2, '*rb')
     data2 = rfp.read(1000)
     rfp.close()
     if data1 != data2:
         return 'Resource forks differ'
     return ''
Exemplo n.º 9
0
 def compareData(self):
     fp = open(test_support.TESTFN, 'r')
     data1 = fp.read()
     fp.close()
     fp = open(TESTFN2, 'r')
     data2 = fp.read()
     fp.close()
     if data1 != data2:
         return 'Data forks differ'
     rfp = MacOS.openrf(test_support.TESTFN, '*rb')
     data1 = rfp.read(1000)
     rfp.close()
     rfp = MacOS.openrf(TESTFN2, '*rb')
     data2 = rfp.read(1000)
     rfp.close()
     if data1 != data2:
         return 'Resource forks differ'
     return ''
Exemplo n.º 10
0
def openrf(path, mode):

    if have_macos:
        try:
            return MacOS.openrf(mac_path(path), "*" + mode)
        except MacOS.Error:
            pass

    try:
        return open(os.path.join(path, "..namedfork", "rsrc"), mode)
    except IOError:
        pass

    return None
Exemplo n.º 11
0
def openrf(path, mode):

    if have_macos:
        try:
            return MacOS.openrf(mac_path(path), "*"+mode)
        except MacOS.Error:
            pass

    try:
        return open(os.path.join(path,"..namedfork","rsrc"),mode)
    except IOError:
        pass

    return None
Exemplo n.º 12
0
    def fromFile(self, path):
        s = os.lstat(path)

        self.md5 = ''
        self.rfmd5 = ''

        # Find resource fork size manually
        if S_ISREG(s[ST_MODE]):
            rf = MacOS.openrf(path, 'r')
            rf.seek(0, 2)  #seeks to end of file
            self.rfSize = rf.tell()

            rfNumBytes = int(self.rfSize)

            if gUseMD5 and rfNumBytes > 0:
                rf.seek(0)
                h = hashlib.md5()
                h.update(rf.read(rfNumBytes))
                self.rfmd5 = h.hexdigest()

            rf.close()
        else:
            self.rfSize = 0

        # Find data md5
        if gUseMD5 and S_ISREG(s[ST_MODE]) and s[ST_SIZE] > 0:
            f = open(path, 'r')
            h = hashlib.md5()

            d = f.read(4096)
            while d:
                h.update(d)
                d = f.read(4096)

            #h.update(f.read())
            self.md5 = h.hexdigest()

        self.name = path
        self.mode = s[ST_MODE]
        self.uid = s[ST_UID]
        self.gid = s[ST_GID]
        self.size = s[ST_SIZE]
        self.creationDate = s[ST_CTIME]
        self.modificationDate = s[ST_MTIME]

        if S_ISLNK(s[ST_MODE]):
            self.linkPath = os.readlink(path)
        else:
            self.linkPath = ''
Exemplo n.º 13
0
 def fromFile(self, path):
     s = os.lstat(path)
     
     self.md5 = ''
     self.rfmd5 = ''
     
     # Find resource fork size manually
     if S_ISREG(s[ST_MODE]):
         rf = MacOS.openrf(path, 'r')
         rf.seek(0, 2) #seeks to end of file
         self.rfSize = rf.tell()
         
         rfNumBytes = int(self.rfSize)
         
         if gUseMD5 and rfNumBytes > 0:
             rf.seek(0)
             h = hashlib.md5()
             h.update(rf.read(rfNumBytes))
             self.rfmd5 = h.hexdigest()
         
         rf.close()
     else:
         self.rfSize = 0
         
     # Find data md5
     if gUseMD5 and S_ISREG(s[ST_MODE]) and s[ST_SIZE] > 0:
         f = open(path, 'r')
         h = hashlib.md5()
         
         d = f.read(4096)
         while d:
             h.update(d)
             d = f.read(4096)
         
         #h.update(f.read())
         self.md5 = h.hexdigest()
     
     self.name = path
     self.mode = s[ST_MODE]
     self.uid = s[ST_UID]
     self.gid = s[ST_GID]
     self.size = s[ST_SIZE]
     self.creationDate = s[ST_CTIME]
     self.modificationDate = s[ST_MTIME]
     
     if S_ISLNK(s[ST_MODE]):
         self.linkPath = os.readlink(path)
     else:
         self.linkPath = ''
Exemplo n.º 14
0
    def testOpenRF(self):
        try:
            fp = open(test_support.TESTFN, 'w')
            fp.write('hello world\n')
            fp.close()

            rfp = MacOS.openrf(test_support.TESTFN, '*wb')
            rfp.write('goodbye world\n')
            rfp.close()

            fp = open(test_support.TESTFN, 'r')
            data = fp.read()
            fp.close()
            self.assertEquals(data, 'hello world\n')

            rfp = MacOS.openrf(test_support.TESTFN, '*rb')
            data = rfp.read(100)
            data2 = rfp.read(100)
            rfp.close()
            self.assertEquals(data, 'goodbye world\n')
            self.assertEquals(data2, '')

        finally:
            os.unlink(test_support.TESTFN)
Exemplo n.º 15
0
 def tofile(self, path, resonly=False):
     outfile = open(path, 'wb')
     data = False
     if resonly:
         if self.resourcefork is None:
             raise Error, "No resource fork found"
         fp = open(path, 'wb')
         fp.write(self.resourcefork)
         fp.close()
     elif (self.resourcefork is None and self.datafork is None):
         raise Error, "No useful forks found"
     else:
         if self.datafork is not None:
             fp = open(path, 'wb')
             fp.write(self.datafork)
             fp.close()
         if self.resourcefork is not None:
             fp = MacOS.openrf(path, '*wb')
             fp.write(self.resourcefork)
             fp.close()
Exemplo n.º 16
0
 def tofile(self, path, resonly=False):
     outfile = open(path, "wb")
     data = False
     if resonly:
         if self.resourcefork is None:
             raise Error, "No resource fork found"
         fp = open(path, "wb")
         fp.write(self.resourcefork)
         fp.close()
     elif self.resourcefork is None and self.datafork is None:
         raise Error, "No useful forks found"
     else:
         if self.datafork is not None:
             fp = open(path, "wb")
             fp.write(self.datafork)
             fp.close()
         if self.resourcefork is not None:
             fp = MacOS.openrf(path, "*wb")
             fp.write(self.resourcefork)
             fp.close()
Exemplo n.º 17
0
# applesingle - a module to decode AppleSingle files
import struct
import MacOS
import sys
Error = "applesingle.Error"
verbose = 0
# File header format: magic, version, unused, number of entries
AS_HEADER_FORMAT = "ll16sh"
AS_HEADER_LENGTH = 26
# The flag words for AppleSingle
AS_MAGIC = 0x00051600
AS_VERSION = 0x00020000
# Entry header format: id, offset, length
AS_ENTRY_FORMAT = "lll"
AS_ENTRY_LENGTH = 12
# The id values
AS_DATAFORK = 1
AS_RESOURCEFORK = 2
AS_IGNORE = (3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15)

def decode(input, output, resonly=0):
    if type(input) == type(''):
        input = open(input, 'rb')
    # Should we also test for FSSpecs or FSRefs?
    header = input.read(AS_HEADER_LENGTH)
    print ` header `
    try:
        magic, version, dummy, nentry = struct.unpack(AS_HEADER_FORMAT, header)
    except ValueError, arg:
        raise Error, "Unpack header error: %s" % arg
Exemplo n.º 18
0
# applesingle - a module to decode AppleSingle files
import struct
import MacOS
import sys
Error="applesingle.Error"
verbose=0
# File header format: magic, version, unused, number of entries
AS_HEADER_FORMAT="ll16sh"
AS_HEADER_LENGTH=26
# The flag words for AppleSingle
AS_MAGIC=0x00051600
AS_VERSION=0x00020000
# Entry header format: id, offset, length
AS_ENTRY_FORMAT="lll"
AS_ENTRY_LENGTH=12
# The id values
AS_DATAFORK=1
AS_RESOURCEFORK=2
AS_IGNORE=(3,4,5,6,8,9,10,11,12,13,14,15)
def decode(input, output, resonly=0):
	if type(input) == type(''):
		input = open(input, 'rb')
	# Should we also test for FSSpecs or FSRefs?
	header = input.read(AS_HEADER_LENGTH)
	print `header`
	try:
		magic, version, dummy, nentry = struct.unpack(AS_HEADER_FORMAT, header)
	except ValueError, arg:
		raise Error, "Unpack header error: %s"%arg
	if verbose: