def test_server_path_returns_the_correct_value_for_the_current_os(self): """testing if server_path returns the correct value for the operating system """ repo = Repository() self.assertEqual(self.temp_projects_folder, os.environ[conf.repository_env_key]) self.assertEqual(repo.server_path, self.temp_projects_folder)
def test_REPO_has_home_shortcut(self): """testing if the $REPO path is expanded correctly if it has "~" kind of shortcuts """ test_value = "~/Project" os.environ[conf.repository_env_key] = test_value repo = Repository() self.assertEqual(repo.server_path, os.path.expanduser(test_value))
def test_setup_is_working_fine(self): """testing if test setup is working fine """ # now create a repository and ask the server path and check if it # matches the test_settings repo = Repository() # BUG: works only under linux fix it later self.assertEqual(repo.server_path, self.temp_projects_folder)
def test_relative_path_returns_a_path_with_env_var(self): """testing if the relative_path returns a path starting with $REPO """ test_value = "TEST/Seqs/Seq1/Shots/SH001/FX/SH001_Main_FX_v001_oy.hip" test_path = os.path.join(self.temp_projects_folder, test_value) expected = "$" + conf.repository_env_key + "/" + test_value repo = Repository() self.assertEqual(repo.relative_path(test_path), expected)
def __init_on_load__(self): """init when loaded from the db """ self.repository = Repository() from oyProjectManager import conf self.conf = conf self._sequenceList = [] self._exists = None
def reference(self, version): """References the given Version instance to the current Maya scene. :param version: The desired :class:`~oyProjectManager.models.version.Version` instance to be referenced. """ # use the file name without extension as the namespace namespace = os.path.basename(version.filename) repo = Repository() workspace_path = pm.workspace.path new_version_full_path = version.full_path if version.full_path.startswith(workspace_path): new_version_full_path = utils.relpath( workspace_path, version.full_path.replace("\\", "/"), "/", "..") # replace the path with environment variable new_version_full_path = repo.relative_path(new_version_full_path) ref = pm.createReference(new_version_full_path, gl=True, loadReferenceDepth='none', namespace=namespace, options='v=0') # replace external paths self.replace_external_paths(1) # set the reference state to loaded if not ref.isLoaded(): ref.load() # append the referenced version to the current versions references # attribute current_version = self.get_current_version() if current_version: current_version.references.append(version) current_version.save() return True
def __init__(self, name, code=None, client=None): # do not initialize if it is created from the DB if hasattr(self, "__skip_init__"): logging.debug("skipping the __init__ on Project") return logger.debug("initializing the Project") # get the config from oyProjectManager import conf self.conf = conf self.repository = Repository() self.name = name if code is None: code = self.name self._code = self._condition_code(code) self.shot_number_prefix = self.conf.shot_number_prefix self.shot_number_padding = self.conf.shot_number_padding self.rev_number_prefix = self.conf.rev_number_prefix self.rev_number_padding = self.conf.rev_number_padding self.ver_number_prefix = self.conf.ver_number_prefix self.ver_number_padding = self.conf.ver_number_padding # set the default resolution default_resolution_key = conf.default_resolution_preset default_resolution = conf.resolution_presets[default_resolution_key] self.fps = self.conf.default_fps self.width = default_resolution[0] self.height = default_resolution[1] self.pixel_aspect = default_resolution[2] # and the structure self.structure = self.conf.project_structure # add the client self.client = client
def test_get_project_name_is_working_properly(self): """testing if the get_project_name method is working properly """ test_values = [ (os.path.join(self.temp_projects_folder, "TEST/Seqs/Seq1/Edit"), "TEST"), (self.temp_projects_folder + "/../" + os.path.normpath( self.temp_projects_folder).split(os.path.sep)[-1] + "/TEST/Seqs/Seq1/Edit", "TEST"), (None, None), (self.temp_projects_folder, None), ] repo = Repository() print "self.repo.server_path", repo.server_path for test_value in test_values: self.assertEqual(repo.get_project_name(test_value[0]), test_value[1])
def update_versions(self, version_tuple_list): """update versions to the latest version """ repo = Repository() repo_env_key = "$" + conf.repository_env_key previous_version_full_path = '' latest_version = None for version_tuple in version_tuple_list: version = version_tuple[0] reference = version_tuple[1] version_full_path = version_tuple[2] if version_full_path != previous_version_full_path: latest_version = version.latest_version() previous_version_full_path = version_full_path reference.replaceWith( latest_version.full_path.replace(repo.server_path, repo_env_key))
def test_osx_path_attribute_is_read_only(self): """testing if the osx_path is read only """ repo = Repository() self.assertRaises(AttributeError, setattr, repo, "osx_path", "some value")
def replace_external_paths(self, mode=0): """Replaces all the external paths replaces: references: to a path which starts with $REPO env variable in absolute mode and a workspace relative path in relative mode file : to a path which starts with $REPO env variable in absolute mode and a workspace relative path in relative mode Absolute mode works best for now. .. note:: After v0.2.2 the system doesn't care about the mentalrayTexture nodes because the lack of a good environment variable support from that node. Use regular maya file nodes with mib_texture_filter_lookup nodes to have the same sharp results. :param mode: Defines the process mode: if mode == 0 : replaces with relative paths if mode == 1 : replaces with absolute paths """ # TODO: Also check for image planes and replace the path logger.debug("replacing paths with mode: %i" % mode) # create a repository repo = Repository() repo_env_key = "$" + conf.repository_env_key workspace_path = pm.workspace.path # fix for paths like S:/ (ending with a slash) for $REPO server_path = os.environ[conf.repository_env_key] if server_path.endswith('/'): server_path = server_path[:-1] # replace reference paths with $REPO for ref in pm.listReferences(): unresolved_path = ref.unresolvedPath().replace("\\", "/") if not unresolved_path.startswith("$" + conf.repository_env_key): # make it absolute if not os.path.isabs(unresolved_path): unresolved_path = os.path.join(workspace_path, unresolved_path) if unresolved_path.startswith(server_path): new_ref_path = "" if mode: # convert to absolute path new_ref_path = ref.path.replace( server_path, repo_env_key) else: # convert to relative path new_ref_path = utils.relpath(workspace_path, ref.path) logger.info("replacing reference:", ref.path) logger.info("replacing with:", new_ref_path) ref.replaceWith(new_ref_path) types_and_attrs = { 'aiImage': 'filename', 'aiStandIn': 'dso', 'file': 'fileTextureName', 'imagePlane': 'imageName', 'audio': 'filename', 'AlembicNode': 'abc_File', 'gpuCache': 'cacheFileName', } for node_type in types_and_attrs.keys(): attr_name = types_and_attrs[node_type] for node in pm.ls(type=node_type): path = node.getAttr(attr_name) if path: path = path.replace("\\", "/") logger.info("replacing file texture: %s" % path) path = os.path.normpath(os.path.expandvars(path)) if path: path = path.replace("\\", "/") # convert to absolute if not os.path.isabs(path): path = os.path.join(workspace_path, path).replace("\\", "/") new_path = "" if mode: # convert to absolute new_path = path.replace(server_path, "$%s" % conf.repository_env_key) else: # convert to relative new_path = utils.relpath(workspace_path, path, "/", "..") logger.info("with: %s" % new_path) node.setAttr(attr_name, new_path)