Ejemplo n.º 1
0
    def _test_groupcheckin(self):

        # FIXME: can't find maya_render.####.iff
        return

        file_path = "./maya_render.####.iff"
        range = FileRange(1, 12)

        # create new test files
        expanded_paths = FileGroup.expand_paths(file_path, range)
        for expanded_path in expanded_paths:
            file = open(expanded_path, 'w')
            file.write("file: %s" % expanded_path)
            file.close()

        # checkin the frames
        file_types = ["main"]
        file_paths = [file_path]

        checkin = FileGroupCheckin(self.person, file_paths, file_types, range, \
            column="frames")
        checkin.execute()

        # delete the test files
        for expanded_path in expanded_paths:
            os.unlink(expanded_path)
Ejemplo n.º 2
0
    def _test_preallocation_checkin(self):

        snapshot_type = "file"
        context = "preallocation"
        file_name = 'whatever.jpg'
        file_type = 'jpg'

        # create an empty snapshot
        snapshot = Snapshot.create(self.person,
                                   snapshot_type=snapshot_type,
                                   context=context)

        # preallocate with no name or type
        path = snapshot.get_preallocated_path()
        server = Config.get_value("install", "server")
        if server:
            expected = "%s_preallocation_%s_v001" % (self.person.get_code(),
                                                     server)
        else:
            expected = "%s_preallocation_v001" % (self.person.get_code())

        self.assertEquals(True, path.endswith(expected))

        # preallocate with a file name and file type
        # since it's meant for FileAppendCheckin, the checkin_type should be 'strict'
        path = snapshot.get_preallocated_path(file_type,
                                              file_name,
                                              checkin_type='strict')
        if server:
            self.assertEquals(
                True, None != re.search(
                    'unittest/person/\w+/preallocation/whatever_preallocation_\w+_v001.jpg$',
                    path))
        else:
            self.assertEquals(
                True, None != re.search(
                    'unittest/person/\w+/preallocation/whatever_preallocation_v001.jpg$',
                    path))

        # create a file directly in the path location and register in
        # transaction
        f = open(path, 'wb')
        f.write("wowow")
        f.close()

        # add this file to the snapshot and force the name
        snapshot_code = snapshot.get_code()
        checkin = FileAppendCheckin(snapshot_code, [path], [file_type],
                                    keep_file_name=True,
                                    mode='preallocate')
        checkin.execute()

        # check that it worked
        snapshot = checkin.get_snapshot()
        lib_dir = snapshot.get_lib_dir()
        file_name = snapshot.get_file_name_by_type(file_type)
        self.assertEquals(True, os.path.exists("%s/%s" % (lib_dir, file_name)))

        # test preallocation on a sequence
        file_name = "images_%0.4d.png"
        file_type = 'sequence'
        file_range = FileRange(1, 5)

        # should specify strict checkin_type for Append checkin after
        path = snapshot.get_preallocated_path(file_type=file_type,
                                              file_name=file_name,
                                              checkin_type='strict')
        # imitate a render by building files directly to the path
        for i in range(1, 6):
            cur_path = path % i
            f = open(cur_path, 'wb')
            f.write("wowow")
            f.close()

        # register these files
        snapshot_code = snapshot.get_code()

        # should specify strict checkin_type for Append checkin
        checkin = FileGroupAppendCheckin(snapshot_code, [path], [file_type], file_range, \
                keep_file_name=True, mode='preallocate', checkin_type='strict')
        checkin.execute()

        snapshot = checkin.get_snapshot()

        # get the file paths
        file_names = snapshot.get_expanded_file_names(file_type)
        lib_dir = snapshot.get_lib_dir()
        for file_name in file_names:
            path = "%s/%s" % (lib_dir, file_name)
            self.assertEquals(True, os.path.exists(path))