def test_update_paths_will_preserve_extension(self): """testing if update_paths method will preserve the extension. """ # create a FilenameTemplate for Task instances ft = FilenameTemplate( name="Task Filename Template", target_entity_type="Task", path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}", filename="{{task.nice_name}}_{{version.take_name}}" '_v{{"%03d"|format(version.version_number)}}{{extension}}', ) self.test_project.structure.templates.append(ft) new_version1 = Version(**self.kwargs) DBSession.add(new_version1) DBSession.commit() new_version1.update_paths() self.assertEqual(new_version1.path, "tp/SH001/Task1") extension = ".ma" new_version1.extension = extension self.assertEqual(new_version1.filename, "Task1_TestTake_v001.ma") # rename the task and update the paths self.test_task1.name = "Task2" # now call update_paths and expect the extension to be preserved new_version1.update_paths() self.assertEqual(new_version1.filename, "Task2_TestTake_v001.ma") self.assertEqual(new_version1.extension, extension)
def upload_version(self, task, file_object, take_name=None, extension=''): """Uploads versions to the Task.path/ folder and creates a Version object to there. Again the Version object will have a Repository root relative path. The filename of the version will be automatically generated by Stalker. :param task: The task that a version is uploaded to. Should be an instance of :class:`.Task` class. :param file_object: A file like object holding the content of the version. :param str take_name: A string showing the the take name of the Version. If skipped defaults.version_take_name will be used. :param str extension: The file extension of the version. :returns: :class:`.Version` instance. """ from stalker import defaults, Version if take_name is None: take_name = defaults.version_take_name v = Version(task=task, take_name=take_name, created_with='Stalker Pyramid') v.update_paths() v.extension = extension # upload it self.upload_file(file_object, v.absolute_path, v.filename) return v
def create_version(task, take_name): """Creates a new version :param task: the task :param take_name: the take_name name :return: the version """ # just renew the scene #pymel.core.newFile(force=True) v = Version(task=task, take_name=take_name) v.update_paths() db.DBSession.add(v) db.DBSession.commit() #self.maya_env.save_as(v) return v
def test_absolute_full_path_works_properly(self): """testing if the absolute_full_path attribute works properly """ ft = FilenameTemplate( name="Task Filename Template", target_entity_type="Task", path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}", filename="{{task.nice_name}}_{{version.take_name}}" '_v{{"%03d"|format(version.version_number)}}{{extension}}', ) self.test_project.structure.templates.append(ft) new_version1 = Version(**self.kwargs) DBSession.add(new_version1) DBSession.commit() new_version1.update_paths() new_version1.extension = ".ma" self.assertEqual(new_version1.extension, ".ma") self.assertEqual(new_version1.absolute_full_path, "/mnt/T/tp/SH001/Task1/Task1_TestTake_v001.ma")
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 test_upload_version_output_is_working_properly(self): """testing if MediaManager.upload_version_output() is working properly """ v = Version(task=self.test_task2) db.DBSession.add(v) db.DBSession.commit() v.update_paths() db.DBSession.add(v) db.DBSession.commit() # upload an image file as an output to a version of test_task2 with open(self.test_video_path_mp4) as f: link = self.test_media_manager.upload_version_output( v, f, 'test_video.mp4') # now expect the return_val to be a Link instance self.assertIsInstance(link, Link) # expect the Link full_path to be: # Version.path/Outputs/Stalker_Pyramid/ self.assertEqual(os.path.dirname(link.full_path), os.path.join(v.path, 'Outputs/Stalker_Pyramid')) # expect the Link.thumbnail.full_path to be in # Version.path/Outputs/Stalker_Pyramid/ForWeb/ self.assertEqual( os.path.dirname(link.thumbnail.full_path), os.path.join(v.path, 'Outputs/Stalker_Pyramid/ForWeb')) # and expect the Link.thumbnail.thumbnail.full_path to be in # Version.path/Outputs/Stalker_Pyramid/Thumbnail/ self.assertEqual( os.path.dirname(link.thumbnail.thumbnail.full_path), os.path.join(self.test_task2.path, 'Outputs/Stalker_Pyramid/Thumbnail'))
def create_version(self, task, take_name): """A helper method for creating a new version :param task: the task :param take_name: the take_name name :return: the Version instance """ # just renew the scene v = Version(task=task, take_name=take_name) v.update_paths() DBSession.add(v) DBSession.commit() # create a file try: os.makedirs(os.path.dirname(v.absolute_full_path)) except OSError: # dir exists pass with open(v.absolute_full_path, 'w+'): pass return v
def create_version(self, task, take_name): """A helper method for creating a new version :param task: the task :param take_name: the take_name name :return: the Version instance """ # just renew the scene v = Version(task=task, take_name=take_name) v.update_paths() db.DBSession.add(v) db.DBSession.commit() # create a file try: os.makedirs(os.path.dirname(v.absolute_full_path)) except OSError: # dir exists pass with open(v.absolute_full_path, 'w+'): pass return v
def copy_versions(self): """copies versions from one task to another """ # get from task from_task = self.get_task_from_tree_view(self.from_task_tree_view) # get logged in user logged_in_user = self.get_logged_in_user() if not from_task: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select a task from <b>From Task</b> list') return # get to task to_task = self.get_task_from_tree_view(self.to_task_tree_view) if not to_task: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select a task from <b>To Task</b> list') return # check if tasks are the same if from_task == to_task: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select two different tasks') return # get take names and related versions # get distinct take names from stalker.db.session import DBSession from_take_names = map( lambda x: x[0], DBSession.query(distinct(Version.take_name)).filter( Version.task == from_task).order_by(Version.take_name).all()) # create versions for each take answer = QtWidgets.QMessageBox.question( self, 'Info', "Will copy %s versions from take names:<br><br>" "%s" "<br><br>" "Is that Ok?" % (len(from_take_names), '<br>'.join(from_take_names)), QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No) if answer == QtWidgets.QMessageBox.Yes: for take_name in from_take_names: latest_version = Version.query\ .filter_by(task=from_task)\ .filter_by(take_name=take_name)\ .order_by(Version.version_number.desc())\ .first() # create a new version new_version = Version(task=to_task, take_name=take_name) new_version.created_by = logged_in_user new_version.extension = latest_version.extension new_version.description = \ 'Moved from another task (id=%s) with Version Mover' % \ latest_version.task.id new_version.created_with = latest_version.created_with DBSession.add(new_version) DBSession.commit() # update path new_version.update_paths() DBSession.add(new_version) DBSession.commit() # now copy the last_version file to the new_version path try: os.makedirs(new_version.absolute_path) except OSError: # path exists pass # move the file there shutil.copyfile(latest_version.absolute_full_path, new_version.absolute_full_path) # inform the user QtWidgets.QMessageBox.information( self, 'Success', 'Successfully copied %s versions' % len(from_take_names))
code='FPE', status_list=proj_statuses, repository=repo, structure=flat_struct) # now lets create a Task t1 = Task(name='Building 1', project=p1) t2 = Task(name='Model', parent=t1) t3 = Task(name='Lighting', parent=t1, depends=[t2]) # store all the data in the database db.DBSession.add_all([t1, t2, t3]) # this is enough to store the rest # lets create a Maya file for the Model task t2_v1 = Version(task=t1) t2_v1.update_paths() # for now this is needed to render the template, but will # remove it later on t2_v1.extension = '.ma' # set the extension for maya # lets create a new version for Lighting t3_v1 = Version(task=t3) t3_v1.update_paths() t3_v1.extension = '.ma' # you should see that all are in the same folder print(t2_v1.absolute_full_path) print(t3_v1.absolute_full_path) # # Lets create a second Project that use some other folder structure #
def test_get_version_from_full_path_with_multiple_repositories(self): """testing if the get version from full path is working fine with multiple repositories and with same version names """ repo1 = Repository(name="Test Repo 1", linux_path="/mnt/T/", windows_path="T:/", osx_path="/Volumes/T/") DBSession.add(repo1) repo2 = Repository(name="Test Repo 2", linux_path="/mnt/S/", windows_path="S:/", osx_path="/Volumes/S/") DBSession.add(repo2) task_ft = FilenameTemplate( name="Task Filename Template", target_entity_type="Task", path="$REPO{{project.repository.id}}/{{project.code}}/" "{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}", filename="{{task.nice_name}}_{{version.take_name}}" '_v{{"%03d"|format(version.version_number)}}', ) DBSession.add(task_ft) structure1 = Structure(name="Commercial Project Structure", templates=[task_ft]) DBSession.add(structure1) status1 = Status(name="Status 1", code="STS1") status2 = Status(name="Status 2", code="STS2") status3 = Status(name="Status 3", code="STS3") DBSession.add_all([status1, status2, status3]) proj_status_list = StatusList( name="Project Statuses", target_entity_type="Project", statuses=[status1, status2, status3] ) DBSession.add(proj_status_list) task_status_list = StatusList( name="Task Statuses", target_entity_type="Task", statuses=[status1, status2, status3] ) DBSession.add(task_status_list) version_status_list = StatusList( name="Version Statuses", target_entity_type="Version", statuses=[status1, status2, status3] ) DBSession.add(version_status_list) project1 = Project( name="Test Project 1", code="TP1", repositories=[repo1], structure=structure1, status_list=proj_status_list ) DBSession.add(project1) project2 = Project( name="Test Project 2", code="TP2", repositories=[repo2], structure=structure1, status_list=proj_status_list ) DBSession.add(project2) task1 = Task(name="Test Task 1", code="TT1", project=project1, status_list=task_status_list) DBSession.add(task1) task2 = Task(name="Test Task 1", code="TT1", project=project2, status_list=task_status_list) DBSession.add(task2) DBSession.commit() # now create versions version1 = Version(task=task1, status_list=version_status_list) DBSession.add(version1) DBSession.commit() version1.update_paths() version2 = Version(task=task2, status_list=version_status_list) DBSession.add(version2) DBSession.commit() version2.update_paths() DBSession.commit() logger.debug("version1.full_path : %s" % version1.full_path) logger.debug("version2.full_path : %s" % version2.full_path) # now try to get the versions with an EnvironmentBase instance env = EnvironmentBase() # version1 version1_found = env.get_version_from_full_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(version1_found, version1) # version2 version2_found = env.get_version_from_full_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(version2_found, version2) # version1 in windows version1_found = env.get_version_from_full_path("T:/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(version1_found, version1) # version2 in windows version2_found = env.get_version_from_full_path("S:/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(version2_found, version2) # version1 in linux version1_found = env.get_version_from_full_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(version1_found, version1) # version2 in linux version2_found = env.get_version_from_full_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(version2_found, version2) # version1 in osx version1_found = env.get_version_from_full_path("/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(version1_found, version1) # version2 in osx version2_found = env.get_version_from_full_path("/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(version2_found, version2)
def test_trim_repo_path_with_multiple_repositories(self): """testing if the trim_repo_path is working fine with multiple repositories and with same version names """ repo0 = Repository( name="Test Repo 0", linux_path="/mnt/T/with_a_very_long_path_which_will_cause_errors/", windows_path="T:/with_a_very_long_path_which_will_cause_errors/", osx_path="/Volumes/T/" "with_a_very_long_path_which_will_cause_errors/", ) DBSession.add(repo0) repo1 = Repository(name="Test Repo 1", linux_path="/mnt/T/", windows_path="T:/", osx_path="/Volumes/T/") DBSession.add(repo1) repo2 = Repository(name="Test Repo 2", linux_path="/mnt/S/", windows_path="S:/", osx_path="/Volumes/S/") DBSession.add(repo2) task_ft = FilenameTemplate( name="Task Filename Template", target_entity_type="Task", path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}", filename="{{task.nice_name}}_{{version.take_name}}" '_v{{"%03d"|format(version.version_number)}}', ) DBSession.add(task_ft) structure1 = Structure(name="Commercial Project Structure", templates=[task_ft]) DBSession.add(structure1) status1 = Status(name="Status 1", code="STS1") status2 = Status(name="Status 2", code="STS2") status3 = Status(name="Status 3", code="STS3") DBSession.add_all([status1, status2, status3]) proj_status_list = StatusList( name="Project Statuses", target_entity_type="Project", statuses=[status1, status2, status3] ) DBSession.add(proj_status_list) task_status_list = StatusList( name="Task Statuses", target_entity_type="Task", statuses=[status1, status2, status3] ) DBSession.add(task_status_list) version_status_list = StatusList( name="Version Statuses", target_entity_type="Version", statuses=[status1, status2, status3] ) DBSession.add(version_status_list) project1 = Project( name="Test Project 1", code="TP1", repositories=[repo1], structure=structure1, status_list=proj_status_list ) DBSession.add(project1) project2 = Project( name="Test Project 2", code="TP2", repositories=[repo2], structure=structure1, status_list=proj_status_list ) DBSession.add(project2) task1 = Task(name="Test Task 1", code="TT1", project=project1, status_list=task_status_list) DBSession.add(task1) task2 = Task(name="Test Task 1", code="TT1", project=project2, status_list=task_status_list) DBSession.add(task2) DBSession.commit() # now create versions version1 = Version(task=task1, status_list=version_status_list) DBSession.add(version1) DBSession.commit() version1.update_paths() version2 = Version(task=task1, status_list=version_status_list) DBSession.add(version2) DBSession.commit() version2.update_paths() version3 = Version(task=task2, status_list=version_status_list) DBSession.add(version3) DBSession.commit() version3.update_paths() version4 = Version(task=task2, status_list=version_status_list) DBSession.add(version4) DBSession.commit() version4.update_paths() DBSession.commit() logger.debug("version1.full_path : %s" % version1.full_path) logger.debug("version2.full_path : %s" % version2.full_path) logger.debug("version3.full_path : %s" % version2.full_path) logger.debug("version4.full_path : %s" % version2.full_path) # now try to get the versions with an EnvironmentBase instance env = EnvironmentBase() expected_value1 = "TP1/Test_Task_1/Test_Task_1_Main_v001" expected_value2 = "TP2/Test_Task_1/Test_Task_1_Main_v001" # version1 native trimmed_path = env.trim_repo_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value1) # version2 native trimmed_path = env.trim_repo_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value2) # version1 windows trimmed_path = env.trim_repo_path("T:/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value1) # version2 windows trimmed_path = env.trim_repo_path("S:/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value2) # version1 linux trimmed_path = env.trim_repo_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value1) # version2 linux trimmed_path = env.trim_repo_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value2) # version1 osx trimmed_path = env.trim_repo_path("/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value1) # version2 osx trimmed_path = env.trim_repo_path("/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value2)
def test_update_paths_will_render_the_appropriate_template_from_the_related_project(self): """testing if update_paths method will update the Version.full_path by rendering the related Project FilenameTemplate. """ # create a FilenameTemplate for Task instances # A Template for Assets # ......../Assets/{{asset.type.name}}/{{asset.nice_name}}/{{task.type.name}}/ # # Project1/Assets/Character/Sero/Modeling/Sero_Modeling_Main_v001.ma # # + Project1 # | # +-+ Assets (Task) # | | # | +-+ Characters # | | # | +-+ Sero (Asset) # | | # | +-> Version 1 # | | # | +-+ Modeling (Task) # | | # | +-+ Body Modeling (Task) # | | # | +-+ Coarse Modeling (Task) # | | | # | | +-> Version 1 (Version) # | | # | +-+ Fine Modeling (Task) # | | # | +-> Version 1 (Version): Fine_Modeling_Main_v001.ma # | Assets/Sero/Modeling/Body_Modeling/Fine_Modeling/Fine_Modeling_Main_v001.ma # | # +-+ Shots (Task) # | # +-+ Shot 10 (Shot) # | | # | +-+ Layout (Task) # | | # | +-> Version 1 (Version): Layout_v001.ma # | Shots/Shot_1/Layout/Layout_Main_v001.ma # | # +-+ Shot 2 (Shot) # | # +-+ FX (Task) # | # +-> Version 1 (Version) ft = FilenameTemplate( name="Task Filename Template", target_entity_type="Task", path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}", filename="{{task.nice_name}}_{{version.take_name}}" '_v{{"%03d"|format(version.version_number)}}{{extension}}', ) self.test_project.structure.templates.append(ft) new_version1 = Version(**self.kwargs) DBSession.add(new_version1) DBSession.commit() new_version1.update_paths() self.assertEqual(new_version1.path, "tp/SH001/Task1") new_version1.extension = ".ma" self.assertEqual(new_version1.filename, "Task1_TestTake_v001.ma")
repository=repo, structure=flat_struct ) # now lets create a Task t1 = Task(name='Building 1', project=p1) t2 = Task(name='Model', parent=t1) t3 = Task(name='Lighting', parent=t1, depends=[t2]) # store all the data in the database db.DBSession.add_all([t1, t2, t3]) # this is enough to store the rest # lets create a Maya file for the Model task t2_v1 = Version(task=t1) t2_v1.update_paths() # for now this is needed to render the template, but will # remove it later on t2_v1.extension = '.ma' # set the extension for maya # lets create a new version for Lighting t3_v1 = Version(task=t3) t3_v1.update_paths() t3_v1.extension = '.ma' # you should see that all are in the same folder print(t2_v1.absolute_full_path) print(t3_v1.absolute_full_path) # # Lets create a second Project that use some other folder structure #
def copy_versions(self): """copies versions from one task to another """ # get from task from_task = self.get_task_from_tree_view(self.from_task_tree_view) # get logged in user logged_in_user = self.get_logged_in_user() if not from_task: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select a task from <b>From Task</b> list' ) return # get to task to_task = self.get_task_from_tree_view(self.to_task_tree_view) if not to_task: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select a task from <b>To Task</b> list' ) return # check if tasks are the same if from_task == to_task: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select two different tasks' ) return # get take names and related versions # get distinct take names from_take_names = map( lambda x: x[0], db.DBSession.query(distinct(Version.take_name)) .filter(Version.task == from_task) .order_by(Version.take_name) .all() ) # create versions for each take answer = QtWidgets.QMessageBox.question( self, 'Info', "Will copy %s versions from take names:<br><br>" "%s" "<br><br>" "Is that Ok?" % ( len(from_take_names), '<br>'.join(from_take_names) ), QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No ) if answer == QtWidgets.QMessageBox.Yes: for take_name in from_take_names: latest_version = Version.query\ .filter_by(task=from_task)\ .filter_by(take_name=take_name)\ .order_by(Version.version_number.desc())\ .first() # create a new version new_version = Version( task=to_task, take_name=take_name ) new_version.created_by = logged_in_user new_version.extension = latest_version.extension new_version.description = \ 'Moved from another task (id=%s) with Version Mover' % \ latest_version.task.id new_version.created_with = latest_version.created_with db.DBSession.add(new_version) db.DBSession.commit() # update path new_version.update_paths() db.DBSession.add(new_version) db.DBSession.commit() # now copy the last_version file to the new_version path try: os.makedirs(new_version.absolute_path) except OSError: # path exists pass # move the file there shutil.copyfile( latest_version.absolute_full_path, new_version.absolute_full_path ) # inform the user QtWidgets.QMessageBox.information( self, 'Success', 'Successfully copied %s versions' % len(from_take_names) )
def test_readme_tutorial_code(setup_sqlite3): """Tests the tutorial code in README.rst """ from stalker import db db.setup() db.init() from stalker.db.session import DBSession assert str(DBSession.connection().engine.url) == 'sqlite://' from stalker import User me = User(name='Erkan Ozgur Yilmaz', login='******', email='*****@*****.**', password='******') # Save the user to database DBSession.save(me) from stalker import Repository repo = Repository(name='Commercial Projects Repository', code='CPR', windows_path='Z:/Projects', linux_path='/mnt/Z/Projects', osx_path='/Volumes/Z/Projects') from stalker import FilenameTemplate task_template = FilenameTemplate( name='Standard Task Filename Template', target_entity_type='Task', # This is for files saved for Tasks path='{{project.repository.path}}/{{project.code}}/' '{%- for parent_task in parent_tasks -%}' '{{parent_task.nice_name}}/' '{%- endfor -%}', # This is Jinja2 template code filename= '{{version.nice_name}}_v{{"%03d"|format(version.version_number)}}') from stalker import Structure standard_folder_structure = Structure( name='Standard Project Folder Structure', templates=[task_template], custom_template= '{{project.code}}/References' # If you need extra folders ) from stalker import Project new_project = Project( name='Test Project', code='TP', structure=standard_folder_structure, repositories=[repo ], # if you have more than one repository you can do it ) from stalker import ImageFormat hd1080 = ImageFormat(name='1080p', width=1920, height=1080) new_project.image_format = hd1080 # Save the project and all the other data it is connected to it DBSession.save(new_project) from stalker import Task, Asset, Shot, Type # define Character asset type char_type = Type(name='Character', code='CHAR', target_entity_type='Asset') character1 = Asset(name='Character 1', code='CHAR1', type=char_type, project=new_project) # Save the Asset DBSession.save(character1) model = Task(name='Model', parent=character1) rigging = Task( name='Rig', parent=character1, depends=[model ], # For project management, define that Rig can not start # before Model ends. ) # Save the new tasks DBSession.save([model, rigging]) # A shot and some tasks for it shot = Shot(name='SH001', code='SH001', project=new_project) # Save the Shot DBSession.save(shot) animation = Task( name='Animation', parent=shot, ) lighting = Task( name='Lighting', parent=shot, depends=[animation], # Lighting can not start before Animation ends, schedule_timing=1, schedule_unit='d', # The task expected to take 1 day to complete resources=[me]) DBSession.save([animation, lighting]) from stalker import Version new_version = Version(task=animation) new_version.update_paths() # to render the naming convention template new_version.extension = '.ma' # let's say that we have created under Maya assert new_version.absolute_full_path == \ "%sTP/SH001/Animation/SH001_Animation_Main_v001.ma" % \ repo.path assert new_version.version_number == 1 new_version2 = Version(task=animation) new_version2.update_paths() # to render the naming convention template new_version2.extension = '.ma' # let's say that we have created under Maya assert new_version2.version_number == 2
def test_get_version_from_full_path_with_multiple_repositories(self): """testing if the get version from full path is working fine with multiple repositories and with same version names """ repo1 = Repository(name='Test Repo 1', linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T/') DBSession.add(repo1) repo2 = Repository(name='Test Repo 2', linux_path='/mnt/S/', windows_path='S:/', osx_path='/Volumes/S/') DBSession.add(repo2) task_ft = FilenameTemplate( name='Task Filename Template', target_entity_type='Task', path='$REPO{{project.repository.code}}/{{project.code}}/' '{%- for parent_task in parent_tasks -%}' '{{parent_task.nice_name}}/{%- endfor -%}', filename='{{task.nice_name}}_{{version.take_name}}' '_v{{"%03d"|format(version.version_number)}}', ) DBSession.add(task_ft) structure1 = Structure(name='Commercial Project Structure', templates=[task_ft]) DBSession.add(structure1) status1 = Status(name='Status 1', code='STS1') status2 = Status(name='Status 2', code='STS2') status3 = Status(name='Status 3', code='STS3') DBSession.add_all([status1, status2, status3]) proj_status_list = \ StatusList.query.filter_by(target_entity_type='Project').first() task_status_list = \ StatusList.query.filter_by(target_entity_type='Task').first() version_status_list = StatusList(name='Version Statuses', target_entity_type='Version', statuses=[status1, status2, status3]) DBSession.add(version_status_list) project1 = Project(name='Test Project 1', code='TP1', repositories=[repo1], structure=structure1, status_list=proj_status_list) DBSession.add(project1) project2 = Project(name='Test Project 2', code='TP2', repositories=[repo2], structure=structure1, status_list=proj_status_list) DBSession.add(project2) task1 = Task(name='Test Task 1', code='TT1', project=project1, status_list=task_status_list) DBSession.add(task1) task2 = Task(name='Test Task 1', code='TT1', project=project2, status_list=task_status_list) DBSession.add(task2) DBSession.commit() # now create versions version1 = Version(task=task1, status_list=version_status_list) DBSession.add(version1) DBSession.commit() version1.update_paths() version2 = Version(task=task2, status_list=version_status_list) DBSession.add(version2) DBSession.commit() version2.update_paths() DBSession.commit() logger.debug('version1.full_path : %s' % version1.full_path) logger.debug('version2.full_path : %s' % version2.full_path) # now try to get the versions with an EnvironmentBase instance env = EnvironmentBase() # version1 version1_found = env.get_version_from_full_path( '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(version1_found, version1) # version2 version2_found = env.get_version_from_full_path( '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(version2_found, version2) # version1 in windows version1_found = env.get_version_from_full_path( 'T:/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(version1_found, version1) # version2 in windows version2_found = env.get_version_from_full_path( 'S:/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(version2_found, version2) # version1 in linux version1_found = env.get_version_from_full_path( '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(version1_found, version1) # version2 in linux version2_found = env.get_version_from_full_path( '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(version2_found, version2) # version1 in osx version1_found = env.get_version_from_full_path( '/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(version1_found, version1) # version2 in osx version2_found = env.get_version_from_full_path( '/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(version2_found, version2)
) # and append it to our project structure commercial_project_structure.templates.append(task_template) # commit to database db.DBSession.commit() # no need to add anything, project is already on db from stalker import Version vers1 = Version( task=comp ) # we need to update the paths vers1.update_paths() # check the path and filename 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
'$REPO{{project.repository.id}}/{{project.code}}/{%- for p in parent_tasks -%}{{p.nice_name}}/{%- endfor -%}', filename='{{version.nice_name}}_v{{"%03d"|format(version.version_number)}}' ) # and append it to our project structure commercial_project_structure.templates.append(task_template) # commit to database DBSession.commit() # no need to add anything, project is already on db from stalker import Version vers1 = Version(task=comp) # we need to update the paths vers1.update_paths() # check the path and filename 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
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 test_trim_repo_path_with_multiple_repositories(self): """testing if the trim_repo_path is working fine with multiple repositories and with same version names """ repo0 = Repository( name='Test Repo 0', linux_path='/mnt/T/with_a_very_long_path_which_will_cause_errors/', windows_path='T:/with_a_very_long_path_which_will_cause_errors/', osx_path='/Volumes/T/' 'with_a_very_long_path_which_will_cause_errors/') DBSession.add(repo0) repo1 = Repository(name='Test Repo 1', linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T/') DBSession.add(repo1) repo2 = Repository(name='Test Repo 2', linux_path='/mnt/S/', windows_path='S:/', osx_path='/Volumes/S/') DBSession.add(repo2) task_ft = FilenameTemplate( name='Task Filename Template', target_entity_type='Task', path='{{project.code}}/{%- for parent_task in parent_tasks -%}' '{{parent_task.nice_name}}/{%- endfor -%}', filename='{{task.nice_name}}_{{version.take_name}}' '_v{{"%03d"|format(version.version_number)}}', ) DBSession.add(task_ft) structure1 = Structure(name='Commercial Project Structure', templates=[task_ft]) DBSession.add(structure1) status1 = Status(name='Status 1', code='STS1') status2 = Status(name='Status 2', code='STS2') status3 = Status(name='Status 3', code='STS3') DBSession.add_all([status1, status2, status3]) proj_status_list = \ StatusList.query.filter_by(target_entity_type='Project').first() task_status_list = \ StatusList.query.filter_by(target_entity_type='Task').first() DBSession.add(task_status_list) project1 = Project(name='Test Project 1', code='TP1', repositories=[repo1], structure=structure1, status_list=proj_status_list) DBSession.add(project1) project2 = Project(name='Test Project 2', code='TP2', repositories=[repo2], structure=structure1, status_list=proj_status_list) DBSession.add(project2) task1 = Task(name='Test Task 1', code='TT1', project=project1, status_list=task_status_list) DBSession.add(task1) task2 = Task(name='Test Task 1', code='TT1', project=project2, status_list=task_status_list) DBSession.add(task2) DBSession.commit() # now create versions version1 = Version(task=task1, status_list=version_status_list) DBSession.add(version1) DBSession.commit() version1.update_paths() version2 = Version(task=task1) DBSession.add(version2) DBSession.commit() version2.update_paths() version3 = Version(task=task2) DBSession.add(version3) DBSession.commit() version3.update_paths() version4 = Version(task=task2) DBSession.add(version4) DBSession.commit() version4.update_paths() DBSession.commit() logger.debug('version1.full_path : %s' % version1.full_path) logger.debug('version2.full_path : %s' % version2.full_path) logger.debug('version3.full_path : %s' % version2.full_path) logger.debug('version4.full_path : %s' % version2.full_path) # now try to get the versions with an EnvironmentBase instance env = EnvironmentBase() expected_value1 = 'TP1/Test_Task_1/Test_Task_1_Main_v001' expected_value2 = 'TP2/Test_Task_1/Test_Task_1_Main_v001' # version1 native trimmed_path = env.trim_repo_path( '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value1) # version2 native trimmed_path = env.trim_repo_path( '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value2) # version1 windows trimmed_path = env.trim_repo_path( 'T:/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value1) # version2 windows trimmed_path = env.trim_repo_path( 'S:/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value2) # version1 linux trimmed_path = env.trim_repo_path( '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value1) # version2 linux trimmed_path = env.trim_repo_path( '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value2) # version1 osx trimmed_path = env.trim_repo_path( '/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value1) # version2 osx trimmed_path = env.trim_repo_path( '/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value2)
def test_naming_case(self): """Test the case where naming should contain both Sequence Shot and other stuff (this is based on https://github.com/eoyilmaz/anima/issues/23) """ from stalker.db.session import DBSession from stalker import Project, Task, Sequence, Shot, FilenameTemplate, \ Version, Structure ft = FilenameTemplate( name='Normal Naming Convention', target_entity_type='Task', path= '$REPO{{project.repository.id}}/{{project.code}}/{%- for parent_task in parent_tasks -%}{{parent_task.nice_name}}/{%- endfor -%}', filename="""{%- for p in parent_tasks -%} {%- if p.entity_type == 'Sequence' -%} {{p.name}} {%- elif p.entity_type == 'Shot' -%} _{{p.name}}{{p.children[0].name}} {%- endif -%} {%- endfor -%} {%- set fx = parent_tasks[-2] -%} _{{fx.name}}_{{version.take_name}}_v{{"%02d"|format(version.version_number)}}""", ) DBSession.add(ft) st = Structure(name='Normal Project Structure', templates=[ft]) DBSession.add(st) test_project = Project(name='test001', code='test001', structure=st) DBSession.add(test_project) DBSession.commit() seq_task = Task(name='seq', project=test_project) DBSession.add(seq_task) ep101 = Sequence(name='ep101', code='ep101', parent=seq_task) DBSession.add(ep101) shot_task = Task(name='shot', parent=ep101) DBSession.add(shot_task) s001 = Shot(name='s001', code='s001', parent=shot_task) DBSession.add(s001) c001 = Task(name='c001', parent=s001) DBSession.add(c001) effects_scene = Task(name='effectScenes', parent=c001) DBSession.add(effects_scene) fxA = Task(name='fxA', parent=effects_scene) DBSession.add(fxA) maya = Task(name='maya', parent=fxA) DBSession.add(maya) DBSession.commit() v = Version(task=maya) v.update_paths() v.extension = '.ma' DBSession.add(v) DBSession.commit() assert v.filename == 'ep101_s001c001_fxA_Main_v01.ma'