2
2
from typing import List
3
3
from diffgram .file .file import File
4
4
from diffgram .job .job import Job
5
+ from uuid import uuid4
5
6
6
7
7
8
class CompoundChildFile :
@@ -21,6 +22,8 @@ class CompoundChildFile:
21
22
assume_new_instances_machine_made : bool
22
23
convert_names_to_label_files : bool
23
24
video_split_duration : int
25
+ local_id : str
26
+ ordinal : int
24
27
25
28
def __init__ (self ,
26
29
child_file_type : str ,
@@ -38,7 +41,8 @@ def __init__(self,
38
41
frame_packet_map : dict = None ,
39
42
assume_new_instances_machine_made : bool = None ,
40
43
convert_names_to_label_files : bool = None ,
41
- video_split_duration : int = None ):
44
+ video_split_duration : int = None ,
45
+ ordinal : int = 0 ):
42
46
self .child_file_type = child_file_type
43
47
self .path = path
44
48
self .url = url
@@ -55,6 +59,11 @@ def __init__(self,
55
59
self .assume_new_instances_machine_made = assume_new_instances_machine_made
56
60
self .convert_names_to_label_files = convert_names_to_label_files
57
61
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
58
67
59
68
60
69
class CompoundFile :
@@ -68,6 +77,12 @@ def __init__(self, project: Project, name: str, directory_id: int):
68
77
self .directory_id = directory_id
69
78
self .child_files_to_upload = []
70
79
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
+
71
86
def remove_compound_file (self , child_file : CompoundChildFile ) -> List [CompoundChildFile ]:
72
87
self .child_files_to_upload .remove (child_file )
73
88
return self .child_files_to_upload
@@ -83,6 +98,7 @@ def __create_compound_parent_file(self):
83
98
self .project .handle_errors (response )
84
99
data = response .json ()
85
100
self .parent_file_data = data .get ('file' )
101
+ self .__refresh_compound_file_from_data_dict (data .get ('file' ))
86
102
print ('self,' , self .parent_file_data )
87
103
return data .get ('file' )
88
104
@@ -125,7 +141,8 @@ def add_child_from_local(self,
125
141
instance_list : list = None ,
126
142
frame_packet_map : dict = None ,
127
143
assume_new_instances_machine_made : bool = True ,
128
- convert_names_to_label_files : bool = True ):
144
+ convert_names_to_label_files : bool = True ,
145
+ ordinal : int = 0 ):
129
146
new_child_file = CompoundChildFile (
130
147
child_file_type = "from_local" ,
131
148
path = path ,
@@ -145,7 +162,8 @@ def add_child_file_from_url(self,
145
162
job_id : int = None ,
146
163
video_split_duration : int = None ,
147
164
instance_list : list = None ,
148
- frame_packet_map : dict = None ):
165
+ frame_packet_map : dict = None ,
166
+ ordinal : int = 0 ):
149
167
new_child_file = CompoundChildFile (
150
168
child_file_type = "from_url" ,
151
169
url = url ,
@@ -167,7 +185,8 @@ def add_child_from_blob_path(self,
167
185
media_type : str = 'image' ,
168
186
instance_list : list = None ,
169
187
file_name : str = None ,
170
- frame_packet_map : dict = None
188
+ frame_packet_map : dict = None ,
189
+ ordinal : int = 0
171
190
):
172
191
new_child_file = CompoundChildFile (
173
192
child_file_type = "from_blob_path" ,
@@ -184,7 +203,10 @@ def add_child_from_blob_path(self,
184
203
return new_child_file
185
204
186
205
def upload (self ):
206
+ if len (self .child_files_to_upload ) == 0 :
207
+ raise AssertionError ('Need to add at least one child file to the compound file before calling upload()' )
187
208
parent_file_data : dict = self .__create_compound_parent_file ()
209
+
188
210
for child_file in self .child_files_to_upload :
189
211
self .__create_child_file (child_file )
190
212
return parent_file_data
0 commit comments