From 2ab23974cac9fca328cc7ad6c6825831fdf9c563 Mon Sep 17 00:00:00 2001 From: Evan Blaudy Date: Tue, 26 Mar 2024 01:37:30 +0100 Subject: [PATCH 1/3] [requirements] upgrade some requirements --- .pre-commit-config.yaml | 2 +- setup.cfg | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 22c8c71d..6f7a8693 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,6 +5,6 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 24.2.0 + rev: 24.3.0 hooks: - id: black diff --git a/setup.cfg b/setup.cfg index 47873ad7..62f43bbb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,5 +48,5 @@ test = requests_mock lint = - black==24.2.0; python_version >= '3.8' - pre-commit==3.6.2; python_version >= '3.9' + black==24.3.0; python_version >= '3.8' + pre-commit==3.7.0; python_version >= '3.9' From c17cd0d35c11fbf2814d8cb39cc15de93df72194 Mon Sep 17 00:00:00 2001 From: Evan Blaudy Date: Tue, 26 Mar 2024 01:41:29 +0100 Subject: [PATCH 2/3] [shots] change import_edl to import_otio: it's possible to import every supported files for OTIO --- gazu/shot.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/gazu/shot.py b/gazu/shot.py index ea6e02e2..795af8fb 100644 --- a/gazu/shot.py +++ b/gazu/shot.py @@ -615,23 +615,42 @@ def import_shots_with_csv(project, csv_file_path, client=default): ) -def import_edl(project, edl_file_path, episode=None, client=default): +def import_otio( + project, + otio_file_path, + episode=None, + naming_convention=None, + match_case=True, + client=default, +): """ - Import shots from an EDL file. + Import shots from an OpenTimelineIO file (works also for every OTIO + adapters). Args: project (str / dict): The project dict or the project ID. - edl_file_path (str): The EDL file path. + otio_file_path (str): The OTIO file path. episode (str / dict): The episode dict or the episode ID. """ + if naming_convention is None: + if episode is not None: + naming_convention = ( + "${project_name}_${episode_name}-${sequence_name}-${shot_name}" + ) + else: + naming_convention = "${project_name}_${sequence_name}-${shot_name}" project = normalize_model_parameter(project) - path = "import/edl/projects/%s" % project["id"] + path = "/import/otio/projects/%s" % project["id"] if episode is not None: episode = normalize_model_parameter(episode) path += "/episodes/%s" % episode["id"] return raw.upload( path, - edl_file_path, + otio_file_path, + data={ + "naming_convention": naming_convention, + "match_case": match_case, + }, client=client, ) From 4d13213e48197217fad125bbf56ff04515236fd7 Mon Sep 17 00:00:00 2001 From: Evan Blaudy Date: Tue, 26 Mar 2024 01:58:01 +0100 Subject: [PATCH 3/3] [qa] add tests for gazu.shot.import_otio / gazu.shot.import_shots_with_csv --- tests/fixtures/test.csv | 1 + tests/fixtures/test.edl | 5 +++ tests/test_shot.py | 74 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/test.csv create mode 100644 tests/fixtures/test.edl diff --git a/tests/fixtures/test.csv b/tests/fixtures/test.csv new file mode 100644 index 00000000..07369a20 --- /dev/null +++ b/tests/fixtures/test.csv @@ -0,0 +1 @@ +;;;;; diff --git a/tests/fixtures/test.edl b/tests/fixtures/test.edl new file mode 100644 index 00000000..645256b5 --- /dev/null +++ b/tests/fixtures/test.edl @@ -0,0 +1,5 @@ +TITLE: Timeline 1 +FCM: NON-DROP FRAME + +001 AX V C 00:00:00:00 00:00:05:00 01:00:00:00 01:00:05:00 +* FROM CLIP NAME: TEST_E001-SEQ001_0001.mov diff --git a/tests/test_shot.py b/tests/test_shot.py index 4afc03d1..606b8439 100644 --- a/tests/test_shot.py +++ b/tests/test_shot.py @@ -6,7 +6,7 @@ import gazu.client import gazu.shot -from utils import fakeid, mock_route +from utils import fakeid, mock_route, add_verify_file_callback class ShotTestCase(unittest.TestCase): @@ -692,3 +692,75 @@ def test_exports_shots_with_csv(self): with open("./test.csv", "r") as export_csv: self.assertEqual(csv, export_csv.read()) os.remove("./test.csv") + + def test_import_otio(self): + with open("./tests/fixtures/test.edl", "rb") as test_file: + with requests_mock.Mocker() as mock: + mock_route( + mock, + "POST", + "/import/otio/projects/%s" % fakeid("project-1"), + text={"success": True}, + ) + + add_verify_file_callback( + mock, + {"file": test_file.read()}, + "/import/otio/projects/%s" % fakeid("project-1"), + ) + + self.assertEqual( + gazu.shot.import_otio( + fakeid("project-1"), "./tests/fixtures/test.edl" + ), + {"success": True}, + ) + + with open("./tests/fixtures/test.edl", "rb") as test_file: + with requests_mock.Mocker() as mock: + mock_route( + mock, + "POST", + "/import/otio/projects/%s/episodes/%s" + % (fakeid("project-1"), fakeid("episode-1")), + text={"success": True}, + ) + + add_verify_file_callback( + mock, + {"file": test_file.read()}, + "/import/otio/projects/%s/episodes/%s" + % (fakeid("project-1"), fakeid("episode-1")), + ) + + self.assertEqual( + gazu.shot.import_otio( + fakeid("project-1"), + "./tests/fixtures/test.edl", + episode=fakeid("episode-1"), + ), + {"success": True}, + ) + + def test_import_shots_with_csv(self): + with open("./tests/fixtures/test.csv", "rb") as test_file: + with requests_mock.Mocker() as mock: + mock_route( + mock, + "POST", + "import/csv/projects/%s/shots" % fakeid("project-1"), + text={"success": True}, + ) + + add_verify_file_callback( + mock, + {"file": test_file.read()}, + "import/csv/projects/%s/shots" % fakeid("project-1"), + ) + + self.assertEqual( + gazu.shot.import_shots_with_csv( + fakeid("project-1"), "./tests/fixtures/test.csv" + ), + {"success": True}, + )