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

various improvements #320

Merged
merged 3 commits into from
Mar 26, 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
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},
)
Loading