def open(self, version, force=False, representation=None, reference_depth=0, skip_update_check=False): """the open action for nuke environment """ version_full_path = os.path.normpath(version.absolute_full_path) # delete all the comps and open new one #comps = self.fusion.GetCompList().values() #for comp_ in comps: # comp_.Close() self.fusion.LoadComp(version_full_path.encode()) rfm = RecentFileManager() rfm.add(self.name, version.absolute_full_path) # set the project_directory #self.project_directory = os.path.dirname(version.absolute_path) # TODO: file paths in different OS'es should be replaced with the current one # Check if the file paths are starting with a string matching one of # the OS'es project_directory path and replace them with a relative one # matching the current OS # replace paths #self.replace_external_paths() # return True to specify everything was ok and an empty list # for the versions those needs to be updated return empty_reference_resolution()
def test_add_method_also_calls_save(self): """testing if the add method also calls save method """ rfm1 = RecentFileManager() rfm1.add('New Env', 'some path') rfm2 = RecentFileManager() self.assertEqual(rfm2['New Env'], ['some path'])
def test_recent_files_attribute_is_working_properly(self): """testing if the recent_files attribute is working properly """ rfm1 = RecentFileManager() rfm1.add('New Env', 'some path') self.assertEqual( rfm1.recent_files, {'New Env': ['some path']} )
def test_add_method_with_a_new_environment_name(self): """testing if the add method is able to add files to a new environment """ rfm = RecentFileManager() rfm.add('New Env', 'some path') self.assertEqual( rfm.recent_files['New Env'][0], 'some path' )
def test_restore_limits_maximum_files_stored(self): """testing if restore limits the maximum files stored """ rm = RecentFileManager() for i in range(anima.max_recent_files + 100): rm.add('Env1', 'some path %s' % i) rm2 = RecentFileManager() self.assertEqual(len(rm2['Env1']), anima.max_recent_files)
def test_add_method_also_calls_save(self): """testing if the add method also calls save method """ rfm1 = RecentFileManager() rfm1.add('New Env', 'some path') rfm2 = RecentFileManager() self.assertEqual( rfm2['New Env'], ['some path'] )
def test_restore_limits_maximum_files_stored(self): """testing if restore limits the maximum files stored """ rm = RecentFileManager() for i in range(anima.max_recent_files + 100): rm.add('Env1', 'some path %s' % i) rm2 = RecentFileManager() self.assertEqual( len(rm2['Env1']), anima.max_recent_files )
def test_RecentFileManager_is_indexable(self): """testing if the RecentFileManager instance is indexable with the environment name """ rfm1 = RecentFileManager() rfm1.add('Env1', 'Path1') rfm1.add('Env1', 'Path2') rfm1.add('Env1', 'Path3') rfm1.add('Env2', 'Path4') rfm1.add('Env2', 'Path5') rfm1.add('Env2', 'Path6') self.assertEqual(rfm1['Env1'], ['Path3', 'Path2', 'Path1']) self.assertEqual(rfm1['Env2'], ['Path6', 'Path5', 'Path4'])
def test_add_method_is_working_properly(self): """testing if the add method will add a new file entry to the recent files list """ rfm = RecentFileManager() test_values = [('Photoshop', 'some path'), ('Maya', 'some other path'), ('Maya', 'some new other path'), ('Photoshop', 'some path 2')] for test_value in test_values: env_name = test_value[0] path = test_value[1] rfm.add(env_name, path) self.assertEqual(rfm.recent_files[env_name][0], path)
def save_as(self, version, run_pre_publishers=True): """"the save action for fusion environment uses Fusions own python binding """ # set the extension to '.comp' # refresh the current comp self.comp = self.fusion.GetCurrentComp() from stalker import Version assert isinstance(version, Version) # its a new version please update the paths version.update_paths() version.extension = self.extensions[0] version.created_with = self.name # set project_directory self.project_directory = os.path.dirname(version.absolute_path) # create the main write node self.create_main_saver_node(version) # set range from the shot self.set_range_from_shot(version) # replace read and write node paths # self.replace_external_paths() # create the path before saving try: os.makedirs(version.absolute_path) except OSError: # path already exists OSError pass version_full_path = os.path.normpath(version.absolute_full_path) self.comp.Lock() self.comp.Save(version_full_path if sys.version_info[0] >= 3 else version_full_path.encode()) self.comp.Unlock() # create a local copy self.create_local_copy(version) rfm = RecentFileManager() rfm.add(self.name, version.absolute_full_path) return True
def open(self, version, force=False, representation=None, reference_depth=0, skip_update_check=False): """open action for photoshop environment :param version: stalker.models.version.Version instance :param force: force open file :return: """ version_full_path = version.absolute_full_path version_full_path = version_full_path.replace('/', '\\') self.photoshop.Load(version_full_path) rfm = RecentFileManager() rfm.add(self.name, version.absolute_full_path) return empty_reference_resolution()
def get_version_from_recent_files(self): """This will try to create a :class:`.Version` instance by looking at the recent files list. It will return None if it can not find one. :return: :class:`.Version` """ version = None logger.debug("trying to get the version from recent file list") # read the fileName from recent files list # try to get the a valid asset file from starting the last recent file rfm = RecentFileManager() try: recent_files = rfm[self.name] except KeyError: logger.debug('no recent files') recent_files = None if recent_files is not None: for recent_file in recent_files: version = self.get_version_from_full_path(recent_file) if version is not None: break logger.debug("version from recent files is: %s" % version) return version
def get_version_from_recent_files(self): """It will try to create a :class:`~oyProjectManager.models.version.Version` instance by looking at the recent files list. It will return None if it can not find one. :return: :class:`~oyProjectManager.models.version.Version` """ # full_path = self.fusion_prefs["LastCompFile"] # return self.get_version_from_full_path(full_path) version = None rfm = RecentFileManager() try: recent_files = rfm[self.name] except KeyError: logger.debug('no recent files') recent_files = None if recent_files is not None: for i in range(len(recent_files)): version = self.get_version_from_full_path(recent_files[i]) if version is not None: break logger.debug("version from recent files is: %s" % version) return version
def test_restore_is_working_properly(self): """testing if the restore method is working properly """ rfm1 = RecentFileManager() rfm1.add('New Env', 'some path') rfm1.save() rfm2 = RecentFileManager() # clear the recent files rfm2.recent_files = [] rfm2.restore() self.assertEqual( rfm2.recent_files['New Env'][0], 'some path' )
def save_as(self, version): """"the save action for fusion environment uses Fusions own python binding """ # set the extension to '.comp' from stalker import Version assert isinstance(version, Version) # its a new version please update the paths version.update_paths() version.extension = '.comp' version.created_with = self.name # set project_directory self.project_directory = os.path.dirname(version.absolute_path) # create the main write node self.create_main_saver_node(version) # replace read and write node paths #self.replace_external_paths() # create the path before saving try: os.makedirs(version.absolute_path) except OSError: # path already exists OSError pass version_full_path = os.path.normpath(version.absolute_full_path) self.comp.Lock() self.comp.Save(version_full_path.encode()) self.comp.Unlock() # create a local copy self.create_local_copy(version) rfm = RecentFileManager() rfm.add(self.name, version.absolute_full_path) return True
def test_add_method_pops_previous_versions_and_inserts_them_to_0(self): """testing if an entry will be popped from the recent_files list if it is added to the list again """ rfm1 = RecentFileManager() rfm1.add('Env1', 'path1') rfm1.add('Env1', 'path2') rfm1.add('Env1', 'path3') self.assertEqual(rfm1['Env1'], ['path3', 'path2', 'path1']) rfm1.add('Env1', 'path1') self.assertEqual(rfm1['Env1'], ['path1', 'path3', 'path2'])
def test_add_method_is_working_properly(self): """testing if the add method will add a new file entry to the recent files list """ rfm = RecentFileManager() test_values = [ ('Photoshop', 'some path'), ('Maya', 'some other path'), ('Maya', 'some new other path'), ('Photoshop', 'some path 2') ] for test_value in test_values: env_name = test_value[0] path = test_value[1] rfm.add(env_name, path) self.assertEqual( rfm.recent_files[env_name][0], path )
def open(self, version, force=False, representation=None, reference_depth=0, skip_update_check=False): """the open action for nuke environment """ version_full_path = os.path.normpath(version.absolute_full_path) # # delete all the comps and open new one # comps = self.fusion.GetCompList().values() # for comp_ in comps: # comp_.Close() self.fusion.LoadComp(version_full_path if sys.version_info[0] >= 3 else version_full_path.encode()) self.comp.Lock() # set the project_directory # get the current comp fist self.comp = self.fusion.GetCurrentComp() self.project_directory = os.path.dirname(version.absolute_path) # update the savers self.create_main_saver_node(version) # file paths in different OS'es should be replaced with a path that is suitable for the current one # update loaders self.fix_loader_paths() self.comp.Unlock() rfm = RecentFileManager() rfm.add(self.name, version.absolute_full_path) # return True to specify everything was ok and an empty list # for the versions those needs to be updated return empty_reference_resolution()
def test_RecentFileManager_is_indexable(self): """testing if the RecentFileManager instance is indexable with the environment name """ rfm1 = RecentFileManager() rfm1.add('Env1', 'Path1') rfm1.add('Env1', 'Path2') rfm1.add('Env1', 'Path3') rfm1.add('Env2', 'Path4') rfm1.add('Env2', 'Path5') rfm1.add('Env2', 'Path6') self.assertEqual( rfm1['Env1'], ['Path3', 'Path2', 'Path1'] ) self.assertEqual( rfm1['Env2'], ['Path6', 'Path5', 'Path4'] )
def test_add_method_pops_previous_versions_and_inserts_them_to_0(self): """testing if an entry will be popped from the recent_files list if it is added to the list again """ rfm1 = RecentFileManager() rfm1.add('Env1', 'path1') rfm1.add('Env1', 'path2') rfm1.add('Env1', 'path3') self.assertEqual( rfm1['Env1'], ['path3', 'path2', 'path1'] ) rfm1.add('Env1', 'path1') self.assertEqual( rfm1['Env1'], ['path1', 'path3', 'path2'] )
def append_to_recent_files(self, path): """appends the given path to the recent files list """ # add the file to the recent file list rfm = RecentFileManager() rfm.add(self.name, path)
def save_as(self, version, run_pre_publishers=True): """"the save action for fusion environment uses Fusions own python binding """ # set the extension to '.comp' # refresh the current comp self.comp = self.fusion.GetCurrentComp() from stalker import Version assert isinstance(version, Version) # its a new version please update the paths version.update_paths() version.extension = self.extensions[0] version.created_with = self.name # set project_directory self.project_directory = os.path.dirname(version.absolute_path) # create the main write node self.create_main_saver_node(version) # check if this is a shot related task is_shot_related_task = False shot = None from stalker import Shot for task in version.task.parents: if isinstance(task, Shot): is_shot_related_task = True shot = task break fps = None imf = None if not is_shot_related_task: # use the Project image_format fps = version.task.project.fps imf = version.task.project.image_format else: # use the shot image_format if shot: fps = shot.fps imf = shot.image_format # set comp resolution and fps if imf: self.comp.SetPrefs({ # Image Format "Comp.FrameFormat.Width": imf.width, "Comp.FrameFormat.Height": imf.height, "Comp.FrameFormat.AspectY": imf.pixel_aspect, "Comp.FrameFormat.AspectX": imf.pixel_aspect, # FPS "Comp.FrameFormat.Rate": fps, # set project frame format to 16bit "Comp.FrameFormat.DepthFull": 2.0, "Comp.FrameFormat.DepthLock": True, }) # replace read and write node paths # self.replace_external_paths() # create the path before saving try: os.makedirs(version.absolute_path) except OSError: # path already exists OSError pass version_full_path = os.path.normpath(version.absolute_full_path) self.comp.Lock() self.comp.Save(version_full_path.encode()) self.comp.Unlock() # create a local copy self.create_local_copy(version) rfm = RecentFileManager() rfm.add(self.name, version.absolute_full_path) return True
def test_remove_method_removes_files_from_given_env(self): """testing if the given path will be removed from the given environment """ rfm1 = RecentFileManager() rfm1.add('Env1', 'Path1') rfm1.add('Env1', 'Path2') rfm1.add('Env1', 'Path3') rfm1.add('Env2', 'Path4') rfm1.add('Env2', 'Path5') rfm1.add('Env2', 'Path6') self.assertEqual( rfm1['Env1'], ['Path3', 'Path2', 'Path1'] ) self.assertEqual( rfm1['Env2'], ['Path6', 'Path5', 'Path4'] ) rfm1.remove('Env1', 'Path1') self.assertEqual( rfm1['Env1'], ['Path3', 'Path2'] ) rfm1.remove('Env1', 'Path3') self.assertEqual( rfm1['Env1'], ['Path2'] ) rfm1.remove('Env2', 'Path5') self.assertEqual( rfm1['Env2'], ['Path6', 'Path4'] )
def test_restore_is_working_properly(self): """testing if the restore method is working properly """ rfm1 = RecentFileManager() rfm1.add('New Env', 'some path') rfm1.save() rfm2 = RecentFileManager() # clear the recent files rfm2.recent_files = [] rfm2.restore() self.assertEqual(rfm2.recent_files['New Env'][0], 'some path')
def test_recent_files_attribute_is_working_properly(self): """testing if the recent_files attribute is working properly """ rfm1 = RecentFileManager() rfm1.add('New Env', 'some path') self.assertEqual(rfm1.recent_files, {'New Env': ['some path']})
def tearDown(self): """clean up test """ os.remove( RecentFileManager.cache_file_full_path() )
def test_add_method_with_a_new_environment_name(self): """testing if the add method is able to add files to a new environment """ rfm = RecentFileManager() rfm.add('New Env', 'some path') self.assertEqual(rfm.recent_files['New Env'][0], 'some path')
def tearDown(self): """clean up test """ os.remove(RecentFileManager.cache_file_full_path())
def test_remove_method_removes_files_from_given_env(self): """testing if the given path will be removed from the given environment """ rfm1 = RecentFileManager() rfm1.add('Env1', 'Path1') rfm1.add('Env1', 'Path2') rfm1.add('Env1', 'Path3') rfm1.add('Env2', 'Path4') rfm1.add('Env2', 'Path5') rfm1.add('Env2', 'Path6') self.assertEqual(rfm1['Env1'], ['Path3', 'Path2', 'Path1']) self.assertEqual(rfm1['Env2'], ['Path6', 'Path5', 'Path4']) rfm1.remove('Env1', 'Path1') self.assertEqual(rfm1['Env1'], ['Path3', 'Path2']) rfm1.remove('Env1', 'Path3') self.assertEqual(rfm1['Env1'], ['Path2']) rfm1.remove('Env2', 'Path5') self.assertEqual(rfm1['Env2'], ['Path6', 'Path4'])