Skip to content

Commit a0d1674

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents c3598b4 + 63a52ba commit a0d1674

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

sdk/diffgram/file/compound_file.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import List
33
from diffgram.file.file import File
44
from diffgram.job.job import Job
5+
from uuid import uuid4
56

67

78
class CompoundChildFile:
@@ -21,6 +22,8 @@ class CompoundChildFile:
2122
assume_new_instances_machine_made: bool
2223
convert_names_to_label_files: bool
2324
video_split_duration: int
25+
local_id: str
26+
ordinal: int
2427

2528
def __init__(self,
2629
child_file_type: str,
@@ -38,7 +41,8 @@ def __init__(self,
3841
frame_packet_map: dict = None,
3942
assume_new_instances_machine_made: bool = None,
4043
convert_names_to_label_files: bool = None,
41-
video_split_duration: int = None):
44+
video_split_duration: int = None,
45+
ordinal: int = 0):
4246
self.child_file_type = child_file_type
4347
self.path = path
4448
self.url = url
@@ -55,6 +59,11 @@ def __init__(self,
5559
self.assume_new_instances_machine_made = assume_new_instances_machine_made
5660
self.convert_names_to_label_files = convert_names_to_label_files
5761
self.video_split_duration = video_split_duration
62+
self.local_id = str(uuid4())
63+
self.ordinal = ordinal
64+
65+
def set_ordinal(self, value: int):
66+
self.ordinal = value
5867

5968

6069
class CompoundFile:
@@ -68,6 +77,12 @@ def __init__(self, project: Project, name: str, directory_id: int):
6877
self.directory_id = directory_id
6978
self.child_files_to_upload = []
7079

80+
def __refresh_compound_file_from_data_dict(self, data: dict):
81+
if not data:
82+
return
83+
for key in data:
84+
setattr(self, key, data[key])
85+
7186
def remove_compound_file(self, child_file: CompoundChildFile) -> List[CompoundChildFile]:
7287
self.child_files_to_upload.remove(child_file)
7388
return self.child_files_to_upload
@@ -83,6 +98,7 @@ def __create_compound_parent_file(self):
8398
self.project.handle_errors(response)
8499
data = response.json()
85100
self.parent_file_data = data.get('file')
101+
self.__refresh_compound_file_from_data_dict(data.get('file'))
86102
return data.get('file')
87103

88104
def __create_child_file(self, child_file: CompoundChildFile):
@@ -124,7 +140,8 @@ def add_child_from_local(self,
124140
instance_list: list = None,
125141
frame_packet_map: dict = None,
126142
assume_new_instances_machine_made: bool = True,
127-
convert_names_to_label_files: bool = True):
143+
convert_names_to_label_files: bool = True,
144+
ordinal: int = 0):
128145
new_child_file = CompoundChildFile(
129146
child_file_type = "from_local",
130147
path = path,
@@ -144,7 +161,8 @@ def add_child_file_from_url(self,
144161
job_id: int = None,
145162
video_split_duration: int = None,
146163
instance_list: list = None,
147-
frame_packet_map: dict = None):
164+
frame_packet_map: dict = None,
165+
ordinal: int = 0):
148166
new_child_file = CompoundChildFile(
149167
child_file_type = "from_url",
150168
url = url,
@@ -166,7 +184,8 @@ def add_child_from_blob_path(self,
166184
media_type: str = 'image',
167185
instance_list: list = None,
168186
file_name: str = None,
169-
frame_packet_map: dict = None
187+
frame_packet_map: dict = None,
188+
ordinal: int = 0
170189
):
171190
new_child_file = CompoundChildFile(
172191
child_file_type = "from_blob_path",
@@ -183,7 +202,10 @@ def add_child_from_blob_path(self,
183202
return new_child_file
184203

185204
def upload(self):
205+
if len(self.child_files_to_upload) == 0:
206+
raise AssertionError('Need to add at least one child file to the compound file before calling upload()')
186207
parent_file_data: dict = self.__create_compound_parent_file()
208+
187209
for child_file in self.child_files_to_upload:
188210
self.__create_child_file(child_file)
189211
return parent_file_data

0 commit comments

Comments
 (0)