diff --git a/gazu/files.py b/gazu/files.py index ca0e153..a84bd69 100644 --- a/gazu/files.py +++ b/gazu/files.py @@ -270,6 +270,52 @@ def all_output_files_for_asset_instance( return raw.fetch_all(path, params, client=client) +def all_output_files_for_project( + project, + output_type=None, + task_type=None, + name=None, + representation=None, + file_status=None, + client=default, +): + """ + Args: + entity (str / dict): The entity dict or ID. + output_type (str / dict): The output type dict or ID. + task_type (str / dict): The task type dict or ID. + name (str): The file name + representation (str): The file representation + file_status (str / dict): The file status + + Returns: + list: + Output files for a given project (asset or shot), output type, + task_type, name and representation + """ + project = normalize_model_parameter(project) + output_type = normalize_model_parameter(output_type) + task_type = normalize_model_parameter(task_type) + file_status = normalize_model_parameter(file_status) + path = "projects/{project_id}/output-files".format( + project_id=project["id"] + ) + + params = {} + if output_type: + params["output_type_id"] = output_type["id"] + if task_type: + params["task_type_id"] = task_type["id"] + if representation: + params["representation"] = representation + if name: + params["name"] = name + if file_status: + params["file_status_id"] = file_status["id"] + + return raw.fetch_all(path, params, client=client) + + @cache def all_softwares(client=default): """ diff --git a/gazu/person.py b/gazu/person.py index d000517..fc033d6 100644 --- a/gazu/person.py +++ b/gazu/person.py @@ -122,7 +122,12 @@ def get_person_by_email(email, client=default): @cache -def get_person_by_full_name(full_name, client=default): +def get_person_by_full_name( + full_name, + first_name=None, + last_name=None, + client=default +): """ Args: full_name (str): User's full name @@ -130,19 +135,26 @@ def get_person_by_full_name(full_name, client=default): Returns: dict: Person corresponding to given name. """ - if " " in full_name: - first_name, last_name = full_name.lower().split(" ") - else: - first_name, last_name = full_name.lower().strip(), "" - for person in all_persons(): - is_right_first_name = ( - first_name == person["first_name"].lower().strip() - ) - is_right_last_name = ( - len(last_name) == 0 or last_name == person["last_name"].lower() + if first_name is not None and last_name is not None: + return raw.fetch_first( + "persons", + {"first_name": first_name, "last_name": last_name}, + client=client, ) - if is_right_first_name and is_right_last_name: - return person + else: + if " " in full_name: + first_name, last_name = full_name.lower().split(" ") + else: + first_name, last_name = full_name.lower().strip(), "" + for person in all_persons(): + is_right_first_name = ( + first_name == person["first_name"].lower().strip() + ) + is_right_last_name = ( + len(last_name) == 0 or last_name == person["last_name"].lower() + ) + if is_right_first_name and is_right_last_name: + return person return None diff --git a/tests/test_files.py b/tests/test_files.py index 462959e..966cb74 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -562,6 +562,23 @@ def test_get_output_files_for_asset_instance(self): self.assertEqual(output_files[0]["id"], "output-file-01") self.assertEqual(output_files[0]["name"], "main") + def test_get_output_files_for_project(self): + with requests_mock.mock() as mock: + base_path = "projects/project-01/output-files" + path = gazu.client.url_path_join("data", base_path) + params = {"output_type_id": "output-type-1"} + + mock.get( + gazu.client.get_full_url( + gazu.client.build_path_with_params(path, params) + ), + text=json.dumps([{"id": "output-file-01", "name": "main"}]), + ) + output_files = gazu.files.all_output_files_for_project( + {"id": "project-01"}, output_type={"id": "output-type-1"} + ) + self.assertEqual(output_files[0]["name"], "main") + def test_update_modification_date(self): with requests_mock.mock() as mock: path = "/actions/working-files/working-file-01/modified"