Skip to content

Commit f24279f

Browse files
authored
Expose json indent to the otio_json adapter (#641)
* Expose json indent to the otio_json adapter * Added docs for otio_json adapter Co-authored-by: Robyn Rindge <[email protected]>
1 parent 1fd68d7 commit f24279f

File tree

2 files changed

+98
-8
lines changed

2 files changed

+98
-8
lines changed

docs/tutorials/otio-plugins.md

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,61 @@ This adapter lets you read and write native .otio files
116116

117117
*Supported Features (with arguments)*:
118118

119-
- read_from_file:
119+
- read_from_file:
120+
```
121+
De-serializes an OpenTimelineIO object from a file
122+
123+
Args:
124+
filepath (str): The path to an otio file to read from
125+
126+
Returns:
127+
OpenTimeline: An OpenTimeline object
128+
```
120129
- filepath
121-
- read_from_string:
130+
- read_from_string:
131+
```
132+
De-serializes an OpenTimelineIO object from a json string
133+
134+
Args:
135+
input_str (str): A string containing json serialized otio contents
136+
137+
Returns:
138+
OpenTimeline: An OpenTimeline object
139+
```
122140
- input_str
123-
- write_to_file:
141+
- write_to_file:
142+
```
143+
Serializes an OpenTimelineIO object into a file
144+
145+
Args:
146+
input_otio (OpenTimeline): An OpenTimeline object
147+
filepath (str): The name of an otio file to write to
148+
indent (int): number of spaces for each json indentation level. Use
149+
-1 for no indentation or newlines.
150+
151+
Returns:
152+
bool: Write success
153+
154+
Raises:
155+
ValueError: on write error
156+
```
124157
- input_otio
125158
- filepath
126-
- write_to_string:
159+
- indent
160+
- write_to_string:
161+
```
162+
Serializes an OpenTimelineIO object into a string
163+
164+
Args:
165+
input_otio (OpenTimeline): An OpenTimeline object
166+
indent (int): number of spaces for each json indentation level. Use
167+
-1 for no indentation or newlines.
168+
169+
Returns:
170+
str: A json serialized string representation
171+
```
127172
- input_otio
173+
- indent
128174

129175

130176

src/py-opentimelineio/opentimelineio/adapters/otio_json.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,60 @@
3333

3434

3535
def read_from_file(filepath):
36+
"""
37+
De-serializes an OpenTimelineIO object from a file
38+
39+
Args:
40+
filepath (str): The path to an otio file to read from
41+
42+
Returns:
43+
OpenTimeline: An OpenTimeline object
44+
"""
3645
return core.deserialize_json_from_file(filepath)
3746

3847

3948
def read_from_string(input_str):
49+
"""
50+
De-serializes an OpenTimelineIO object from a json string
51+
52+
Args:
53+
input_str (str): A string containing json serialized otio contents
54+
55+
Returns:
56+
OpenTimeline: An OpenTimeline object
57+
"""
4058
return core.deserialize_json_from_string(input_str)
4159

4260

43-
def write_to_string(input_otio):
44-
return core.serialize_json_to_string(input_otio)
61+
def write_to_string(input_otio, indent=4):
62+
"""
63+
Serializes an OpenTimelineIO object into a string
64+
65+
Args:
66+
input_otio (OpenTimeline): An OpenTimeline object
67+
indent (int): number of spaces for each json indentation level. Use
68+
-1 for no indentation or newlines.
69+
70+
Returns:
71+
str: A json serialized string representation
72+
"""
73+
return core.serialize_json_to_string(input_otio, indent)
74+
75+
76+
def write_to_file(input_otio, filepath, indent=4):
77+
"""
78+
Serializes an OpenTimelineIO object into a file
79+
80+
Args:
81+
input_otio (OpenTimeline): An OpenTimeline object
82+
filepath (str): The name of an otio file to write to
83+
indent (int): number of spaces for each json indentation level. Use
84+
-1 for no indentation or newlines.
4585
86+
Returns:
87+
bool: Write success
4688
47-
def write_to_file(input_otio, filepath):
48-
return core.serialize_json_to_file(input_otio, filepath)
89+
Raises:
90+
ValueError: on write error
91+
"""
92+
return core.serialize_json_to_file(input_otio, filepath, indent)

0 commit comments

Comments
 (0)