def test_is_latest_published_version_is_working_properly(self): """testing if the is_latest_published_version is working properly """ new_version1 = Version(**self.kwargs) DBSession.add(new_version1) DBSession.commit() new_version2 = Version(**self.kwargs) DBSession.add(new_version2) DBSession.commit() new_version3 = Version(**self.kwargs) DBSession.add(new_version3) DBSession.commit() new_version4 = Version(**self.kwargs) DBSession.add(new_version4) DBSession.commit() new_version5 = Version(**self.kwargs) DBSession.add(new_version5) DBSession.commit() new_version1.is_published = True new_version3.is_published = True new_version4.is_published = True self.assertFalse(new_version1.is_latest_published_version()) self.assertFalse(new_version2.is_latest_published_version()) self.assertFalse(new_version3.is_latest_published_version()) self.assertTrue(new_version4.is_latest_published_version()) self.assertFalse(new_version5.is_latest_published_version())
def get_latest_repr_version(self, take_name): """returns the latest published version or creates a new version :param str take_name: The take_name :return: """ from stalker import Version # filter to get the latest published version v = Version.query\ .filter(Version.task == self.version.task)\ .filter(Version.take_name == take_name)\ .filter(Version.is_published == True)\ .order_by(Version.version_number.desc())\ .first() if v is None: # create a new version v = Version( created_by=self.logged_in_user, task=self.version.task, take_name=take_name ) v.is_published = True else: # change updated by v.updated_by = self.logged_in_user return v
def loads(self, data): """Decodes Stalker data :param data: :return: """ from stalker.db.session import DBSession from stalker import Asset, Task, Shot, Sequence, Version, Type if isinstance(data, str): data = json.loads(data) # get the entity_type entity_type = data['entity_type'] # set default entity class to Task entity_class = Task if entity_type == 'Asset': entity_class = Asset elif entity_type == 'Shot': entity_class = Shot # this is a bug data['sequences'] = [] elif entity_type == 'Sequence': entity_class = Sequence version_data = data['versions'] data['versions'] = [] # get the type if 'type' in data: type_data = data['type'] if type_data: type_name = type_data['name'] type_ = Type.query.filter(Type.name == type_name).first() if not type_: # create a Type type_ = Type(**type_data) data['type'] = type_ data['project'] = self.project entity = entity_class(**data) DBSession.add(entity) DBSession.commit() # create Versions if version_data: for v_data in version_data: # get Version info v_data['task'] = entity v = Version(**v_data) # update version_number v.version_number = v_data['version_number'] v.is_published = v_data['is_published'] # for each child task call a new StalkerEntityDecoder for t in data['tasks']: child_task = self.loads(t) entity.tasks.append(child_task) return entity
def test_inequality_operator(self): """testing inequality of two Version instances """ new_version1 = Version(**self.kwargs) DBSession.add(new_version1) DBSession.commit() new_version2 = Version(**self.kwargs) DBSession.add(new_version2) DBSession.commit() new_version3 = Version(**self.kwargs) DBSession.add(new_version3) DBSession.commit() new_version4 = Version(**self.kwargs) DBSession.add(new_version4) DBSession.commit() new_version5 = Version(**self.kwargs) DBSession.add(new_version5) DBSession.commit() new_version1.is_published = True new_version3.is_published = True new_version4.is_published = True self.assertTrue(new_version1 != new_version2) self.assertTrue(new_version1 != new_version3) self.assertTrue(new_version1 != new_version4) self.assertTrue(new_version1 != new_version5) self.assertTrue(new_version2 != new_version3) self.assertTrue(new_version2 != new_version4) self.assertTrue(new_version2 != new_version5) self.assertTrue(new_version3 != new_version4) self.assertTrue(new_version3 != new_version5) self.assertTrue(new_version4 != new_version5)
def update_versions(self, reference_resolution): """A mock update_versions implementation, does the update indeed but partially. :param reference_resolution: The reference_resolution dictionary :return: a list of new versions """ # first get the resolution list new_versions = [] from stalker import Version # store the current version current_version = self.get_current_version() # loop through 'create' versions and update their references # and create a new version for each of them for version in reference_resolution['create']: local_reference_resolution = self.open(version, force=True) # save as a new version new_version = Version( task=version.task, take_name=version.take_name, parent=version, description='Automatically created with ' 'Deep Reference Update' ) new_version.is_published = True for v in self._version.inputs: new_version.inputs.append(v.latest_published_version) new_versions.append(new_version) # check if we are still in the same scene current_version_after_create = self.get_current_version() if current_version: if current_version != current_version_after_create: # so we are in a different scene just reopen the previous scene self.open(current_version) # we got a new local_reference_resolution but we should have given # a previous one, so use it, # # append all the 'create' items to 'update' items, # so we can update them with update_first_level_versions() reference_resolution['update'].extend( reference_resolution['create'] ) self.update_first_level_versions(reference_resolution) return new_versions
def export_camera(): """exports camera and the related shot node """ from stalker import Task, Version from anima.env import mayaEnv m = mayaEnv.Maya() v = m.get_current_version() shot = pm.ls(type='shot')[0] try: sequencer = pm.ls(shot.message.connections(), type='sequencer')[0] except IndexError: sequencer = None camera = None if shot: camera = shot.currentCamera.get() camera_task = \ Task.query\ .filter(Task.parent == v.task.parent)\ .filter(Task.name == 'Camera').first() if camera_task: from stalker import LocalSession local_session = LocalSession() logged_in_user = local_session.logged_in_user cam_v = Version(task=camera_task, description='Exported from %s task on Publish' % v.task.name) cam_v.update_paths() cam_v.extension = '.ma' cam_v.is_published = True cam_v.created_by = cam_v.updated_by = logged_in_user pm.select([shot, camera, sequencer]) m.export_as(cam_v)
def publish_model_as_look_dev(cls): """Publishes Model versions as LookDev versions of the same task. Also handles references etc. """ # # Create LookDev for Current Model Task # from stalker import Task, Version, Type, LocalSession from stalker.db.session import DBSession from anima import defaults from anima.env import mayaEnv do_db_setup() m = mayaEnv.Maya() local_session = LocalSession() logged_in_user = local_session.logged_in_user if not logged_in_user: raise RuntimeError('Please login to Stalker') model_type = Type.query.filter(Type.name=="Model").first() look_dev_type = \ Type.query.filter(Type.name=="Look Development").first() current_version = m.get_current_version() model_task = current_version.task if model_task.type != model_type: raise RuntimeError('This is not a Model version') if not current_version.is_published: raise RuntimeError('Please Publish this maya scene') if current_version.take_name != 'Main': raise RuntimeError('This is not the Main take') # find lookDev look_dev = Task.query\ .filter(Task.parent == model_task.parent)\ .filter(Task.type == look_dev_type).first() if not look_dev: raise RuntimeError( 'There is no LookDev task, please inform your Stalker admin' ) previous_look_dev_version = \ Version.query\ .filter(Version.task == look_dev)\ .filter(Version.take_name == 'Main')\ .first() description = 'Auto Created By %s ' % logged_in_user.name take_name = defaults.version_take_name if not previous_look_dev_version: # do the trick pm.newFile(f=1) # create a new version new_version = Version( task=look_dev, description=description, take_name=take_name, created_by=logged_in_user ) new_version.is_published = True m.save_as(new_version) # reference the model version pm.createReference( current_version.absolute_full_path, gl=True, namespace=current_version.nice_name, options='v=0' ) pm.saveFile() DBSession.add(new_version) else: latest_look_dev_version = previous_look_dev_version.latest_version reference_resolution = m.open(latest_look_dev_version, force=True, skip_update_check=True) m.update_versions(reference_resolution) if reference_resolution['update'] \ or reference_resolution['create']: # create a new version new_version = Version( task=look_dev, description=description, take_name=take_name, created_by=logged_in_user, parent=latest_look_dev_version ) new_version.is_published = True m.save_as(new_version) # reopen model scene m.open(current_version, force=True, skip_update_check=True)
print(vers1.filename) # 'SH001_comp_Main_v001' print(vers1.full_path) # '$REPO33/FC/SH001/comp/SH001_comp_Main_v001' # now the absolute values, values with repository root # because I'm running this code in a Linux laptop, my results are using the # linux path of the repository print(vers1.absolute_path) # '/mnt/M/commercials/FC/SH001/comp' print(vers1.absolute_full_path ) # '/mnt/M/commercials/FC/SH001/comp/SH001_comp_Main_v001' # check the version_number print(vers1.version_number) # 1 # commit to database DBSession.commit() vers1.is_published = False # I still work on this version, this is not a # usable one # be sure that you've committed the previous version to the database # to let Stalker now what number to give for the next version vers2 = Version(task=comp) vers2.update_paths() # this call probably will disappear in next version of # Stalker, so Stalker will automatically update the # paths on Version.__init__() print(vers2.version_number) # 2 print(vers2.filename) # 'SH001_comp_Main_v002' # before creating a new version commit this one to db DBSession.commit()
def assign_version(request): """assigns the version to the given entity """ logged_in_user = get_logged_in_user(request) # TODO: this should be renamed to create version # collect data link_ids = get_multi_integer(request, 'link_ids') task_id = request.params.get('task_id', -1) link = Link.query.filter(Link.id.in_(link_ids)).first() task = Task.query.filter_by(id=task_id).first() logger.debug('link_ids : %s' % link_ids) logger.debug('link : %s' % link) logger.debug('task_id : %s' % task_id) logger.debug('task : %s' % task) if task and link: # delete the link and create a version instead full_path = convert_file_link_to_full_path(link.full_path) take_name = request.params.get('take_name', defaults.version_take_name) publish = bool(request.params.get('publish')) logger.debug('publish : %s' % publish) path_and_filename, extension = os.path.splitext(full_path) version = Version(task=task, take_name=take_name, created_by=logged_in_user) version.is_published = publish # generate path values version.update_paths() version.extension = extension # specify that this version is created with Stalker Pyramid version.created_with = 'StalkerPyramid' # TODO: that should also be a # config value # now move the link file to the version.absolute_full_path try: os.makedirs( os.path.dirname(version.absolute_full_path) ) except OSError: # dir exists pass logger.debug('full_path : %s' % full_path) logger.debug('version.absolute_full_path : %s' % version.absolute_full_path) shutil.copyfile(full_path, version.absolute_full_path) os.remove(full_path) # it is now safe to delete the link DBSession.add(task) DBSession.delete(link) DBSession.add(version) return HTTPOk()
def loads(self, data, parent=None): """Decodes Stalker data :param data: :return: """ from stalker.db.session import DBSession from stalker import Asset, Task, Shot, Sequence, Version, Type if isinstance(data, str): data = json.loads(data) # get the entity_type entity_type = data['entity_type'] # set default entity class to Task entity_class = Task if entity_type == 'Asset': entity_class = Asset elif entity_type == 'Shot': entity_class = Shot # this is a bug data['sequences'] = [] elif entity_type == 'Sequence': entity_class = Sequence # get the type if 'type' in data: type_data = data['type'] if type_data and not isinstance(type_data, Type): type_name = type_data['name'] type_ = Type.query.filter(Type.name == type_name).first() if not type_: # create a Type type_ = Type(**type_data) data['type'] = type_ # store version data version_data = sorted(data['versions'], key=lambda x: x["version_number"]) data['versions'] = [] data['project'] = self.project # check if the data exists before creating it entity = entity_class.query\ .filter(entity_class.project==self.project)\ .filter(entity_class.parent==parent)\ .filter(entity_class.name==data['name'])\ .first() if not entity: # then create it entity = entity_class(**data) DBSession.add(entity) DBSession.commit() # create Versions if version_data: for v_data in version_data: # check version number and take name # if there is a version with the same version_number # don't create it take_name = v_data['take_name'] version_number = v_data['version_number'] v = Version.query\ .filter(Version.task==entity)\ .filter(Version.take_name==take_name)\ .filter(Version.version_number==version_number)\ .first() if not v: # then create it # get Version info v_data['task'] = entity v = Version(**v_data) # update version_number v.version_number = v_data['version_number'] v.is_published = v_data['is_published'] DBSession.commit() # for each child task call a new StalkerEntityDecoder for t in data['tasks']: self.loads(t, parent=entity) if parent: entity.parent = parent return entity
print(vers1.path) # '$REPO33/FC/SH001/comp' print(vers1.filename) # 'SH001_comp_Main_v001' print(vers1.full_path) # '$REPO33/FC/SH001/comp/SH001_comp_Main_v001' # now the absolute values, values with repository root # because I'm running this code in a Linux laptop, my results are using the # linux path of the repository print(vers1.absolute_path) # '/mnt/M/commercials/FC/SH001/comp' print(vers1.absolute_full_path) # '/mnt/M/commercials/FC/SH001/comp/SH001_comp_Main_v001' # check the version_number print(vers1.version_number) # 1 # commit to database db.DBSession.commit() vers1.is_published = False # I still work on this version, this is not a # usable one # be sure that you've committed the previous version to the database # to let Stalker now what number to give for the next version vers2 = Version(task=comp) vers2.update_paths() # this call probably will disappear in next version of # Stalker, so Stalker will automatically update the # paths on Version.__init__() print(vers2.version_number) # 2 print(vers2.filename) # 'SH001_comp_Main_v002' # before creating a new version commit this one to db db.DBSession.commit()