Esempio n. 1
0
    def test_add_extension_existing(self):
        test_file = common.get_test_file('extension_add_existing.aaf')
        shutil.copy(common.test_file_01(), test_file)

        original_pids = []
        original_classdefs_count = None
        original_typedef_count = None
        with aaf2.open(test_file, 'r') as f:
            original_classdefs_count = len(f.metadict['ClassDefinitions'])
            original_typedef_count = len(f.metadict['TypeDefinitions'])
            for classdef in f.metadict['ClassDefinitions'].values():
                # make sure non of the properties and dynamics
                for pdef in classdef['Properties'].values():
                    pid = pdef['LocalIdentification'].value
                    if pdef['LocalIdentification'].value >= 0x8000:
                        original_pids.append(pid)

        # open files 'rw' and add extensions
        with aaf2.open(test_file, 'rw', extensions=True) as f:
            pass

        all_pids = []
        with aaf2.open(test_file, 'r') as f:
            new_classdefs_count = len(f.metadict['ClassDefinitions'])
            new_typedef_count = len(f.metadict['TypeDefinitions'])
            for classdef in f.metadict['ClassDefinitions'].values():
                for pdef in classdef['Properties'].values():
                    pid = pdef['LocalIdentification'].value
                    # make sure there are no duplicate pids
                    self.assertTrue(pid not in all_pids)
                    all_pids.append(pid)

        self.assertTrue(new_classdefs_count > original_classdefs_count)
        self.assertTrue(new_typedef_count > original_typedef_count)
Esempio n. 2
0
    def test_save_as(self):

        new_file = os.path.join(common.sandbox(), 'save_r+.aaf')
        test_file = common.test_file_01()
        shutil.copy(test_file, new_file)

        with aaf2.open(new_file, 'r+') as f:
            f.save()

        # should contents compare!
        with aaf2.open(new_file, 'r') as f:
            common.walk_aaf(f.root)
Esempio n. 3
0
    def test_mob_id_swap(self):
        new_file = os.path.join(common.sandbox(), 'swap_id.aaf')
        test_file = common.test_file_01()
        shutil.copy(test_file, new_file)
        new_mobid = aaf2.mobid.MobID.new()
        with aaf2.open(new_file, 'rw') as f:
            comp = next(f.content.compositionmobs())
            comp.mob_id = new_mobid

        with aaf2.open(new_file, 'r') as f:
            comp = next(f.content.compositionmobs())
            assert comp.mob_id == new_mobid
Esempio n. 4
0
    def test_duplicate_pids_existing(self):
        result_file = common.get_test_file('duplicate_pids_existing.aaf')
        shutil.copy(common.test_file_01(), result_file)

        with aaf2.open(result_file, 'w', extensions=False) as f:
            self.assertFalse(has_duplicate_pid(f))

        with aaf2.open(result_file, 'r') as f:
            self.assertFalse(has_duplicate_pid(f))

        with aaf2.open(result_file, 'rw', extensions=True) as f:
            self.assertFalse(has_duplicate_pid(f))

        with aaf2.open(result_file, 'r') as f:
            self.assertFalse(has_duplicate_pid(f))
Esempio n. 5
0
    def test_rmtree(self):
        src_file = common.test_file_01()
        test_file = os.path.join(test_dir, "move2_test.aaf")
        shutil.copy(src_file, test_file)

        remove_list = []
        remove_root = "/Header-2/Content-3b03"

        property_streams = []

        with open(test_file, 'rb+') as f:
            cfb = CompoundFileBinary(f, 'rb+')
            # for root, storage_items, streams in cfb.walk():
            #     for item in streams:
            #         print("!!", item.path())

            for root, storage_items, streams in cfb.walk(remove_root):

                for item in storage_items:
                    remove_list.append(item.path())
                for item in streams:
                    remove_list.append(item.path())

            cfb.rmtree('/Header-2/Content-3b03')

            for item in remove_list:
                assert not cfb.exists(item)

            for root, storage_items, streams in cfb.walk():
                for item in streams:
                    if item.name == 'properties':
                        property_streams.append(item.path())

            for item in property_streams:
                cfb.remove(item)

            for item in property_streams:
                assert not cfb.exists(item)

            cfb.close()

        with open(test_file, 'rb') as f:
            cfb = CompoundFileBinary(f, 'rb')
            for item in remove_list:
                assert not cfb.exists(item)

            for item in property_streams:
                assert not cfb.exists(item)
Esempio n. 6
0
    def test_move2(self):
        src_file = common.test_file_01()
        test_file = os.path.join(test_dir, "move2_test.aaf")
        shutil.copy(src_file, test_file)

        dir_list = []
        stream_list = []
        move_root = "/Header-2/Content-3b03"

        with open(test_file, 'rb+') as f:
            cfb = CompoundFileBinary(f, 'rb+')
            for root, storage_items, streams in cfb.walk(move_root):

                for item in storage_items:
                    dir_list.append(item.path())
                for item in streams:
                    stream_list.append(item.path())

            cfb.makedir('/tmp')
            cfb.move(move_root, '/tmp/')

            for item in dir_list:
                assert not cfb.exists(item)
                new_path = item.replace(move_root, '/tmp/Content-3b03')
                assert cfb.exists(new_path)
                assert cfb.find(new_path).isdir()

            for item in stream_list:
                assert not cfb.exists(item)
                new_path = item.replace(move_root, '/tmp/Content-3b03')
                assert cfb.exists(new_path)
                assert cfb.find(new_path).isfile()

            cfb.close()

        with open(test_file, 'rb') as f:
            cfb = CompoundFileBinary(f, 'rb')
            for item in dir_list:
                assert not cfb.exists(item)
                new_path = item.replace(move_root, '/tmp/Content-3b03')
                assert cfb.exists(new_path)
                assert cfb.find(new_path).isdir()

            for item in stream_list:
                assert not cfb.exists(item)
                new_path = item.replace(move_root, '/tmp/Content-3b03')
                assert cfb.exists(new_path)
                assert cfb.find(new_path).isfile()
Esempio n. 7
0
    def test_reattach(self):
        new_file = os.path.join(common.sandbox(), 'test_reattach.aaf')
        test_file = common.test_file_01()
        shutil.copy(test_file, new_file)

        mob_ids = []
        original_child_count = 0

        checksums = {}

        with aaf2.open(new_file, 'r+') as f:
            mobs = f.content['Mobs'].value

            for m in mobs:
                for item, streams in m.walk_references():
                    assert item.dir is not None
                    original_child_count += 1

                    for item in streams:
                        path, crc = stream_checksum(item)
                        path = path.replace(m.dir.path(), str(m.mob_id))
                        checksums[path] = crc

            assert original_child_count > len(mobs)

            mob_ids = [m.mob_id for m in mobs]
            f.content['Mobs'].value = []

            child_count = 0
            for m in mobs:
                for item, streams in m.walk_references():
                    assert item.dir is None
                    child_count += 1

            assert child_count == original_child_count

            f.content['Mobs'].value = mobs
            child_count = 0
            for m in mobs:
                for item, streams in m.walk_references():
                    assert item.dir is not None
                    child_count += 1
                    for item in streams:
                        path, crc = stream_checksum(item)
                        path = path.replace(m.dir.path(), str(m.mob_id))
                        assert checksums[path] == crc

            assert child_count == original_child_count

        with aaf2.open(new_file, 'r') as f:
            for mob_id in mob_ids:
                assert f.content.mobs.get(mob_id, None) is not None

            mobs = f.content['Mobs'].value
            child_count = 0
            for m in mobs:
                for item, streams in m.walk_references():
                    assert item.dir is not None
                    child_count += 1

                    for item in streams:
                        path, crc = stream_checksum(item)
                        path = path.replace(m.dir.path(), str(m.mob_id))
                        assert checksums[path] == crc

            assert child_count == original_child_count