Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all output files for projects #312

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions gazu/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
38 changes: 25 additions & 13 deletions gazu/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,39 @@ 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

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


Expand Down
17 changes: 17 additions & 0 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading