Skip to content

Commit

Permalink
Merge pull request #320 from EvanBldy/master
Browse files Browse the repository at this point in the history
various improvements
  • Loading branch information
EvanBldy authored Mar 26, 2024
2 parents c094555 + 4d13213 commit fd9b8e5
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 24 additions & 5 deletions gazu/shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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'
1 change: 1 addition & 0 deletions tests/fixtures/test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
;;;;;
5 changes: 5 additions & 0 deletions tests/fixtures/test.edl
Original file line number Diff line number Diff line change
@@ -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
74 changes: 73 additions & 1 deletion tests/test_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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},
)

0 comments on commit fd9b8e5

Please sign in to comment.