Skip to content

Commit c06a303

Browse files
Merge branch 'main' of https://github.com/diffgram/python-sdk into schema
2 parents 6e2765b + d14a1ed commit c06a303

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

Diff for: sdk/diffgram/core/diffgram_dataset_iterator.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,24 @@ def gen_tag_instances(self, instance_list):
187187
result.append(elm)
188188
return result
189189

190-
def get_file_instances(self, diffgram_file):
191-
sample = {'diffgram_file': diffgram_file}
190+
def get_file_instances(self, diffgram_file) -> dict:
191+
if not diffgram_file:
192+
return
193+
sample = {'diffgram_file': diffgram_file, 'type': diffgram_file.type}
192194
if diffgram_file.type not in ['image', 'frame', 'compound']:
193195
logging.warning('File type "{}" is not supported yet'.format(diffgram_file.type))
194196
return sample
195197
if diffgram_file.type in ['image', 'frame']:
196198
sample['image'] = self.get_image_data(diffgram_file)
199+
elif diffgram_file.type is not None and diffgram_file.type.startswith('compound'):
200+
from diffgram.file.compound_file import CompoundFile
201+
compound_file: CompoundFile = diffgram_file
202+
sample['children'] = []
203+
child_files = compound_file.fetch_child_files(with_instances = True)
204+
print('chsad', child_files)
205+
for child in child_files:
206+
result = self.get_file_instances(child)
207+
sample['children'].append(result)
197208
instance_list = diffgram_file.instance_list
198209
instance_types_in_file = set([x['type'] for x in instance_list])
199210
# Process the instances of each file

Diff for: sdk/diffgram/core/directory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def all_file_ids(self, query = None):
119119
page_num = page_num,
120120
file_view_mode = 'ids_only',
121121
query = query,
122-
with_children_files = True)
122+
with_children_files = False)
123123

124124
if diffgram_ids is False:
125125
raise Exception('Error Fetching Files: Please check you are providing a valid query.')

Diff for: sdk/diffgram/file/compound_file.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -109,31 +109,33 @@ class CompoundFile:
109109
child_files: List[CompoundChildFile]
110110
instance_list: List[dict]
111111

112-
def __init__(self, project: Project, name: str, directory_id: int, instance_list: List[dict] = []):
112+
def __init__(self, project: Project, name: str, directory_id: int, instance_list: List[dict] = [], file_type: str = 'compound'):
113113
self.project = project
114114
self.name = name
115115
self.directory_id = directory_id
116116
self.child_files = []
117117
self.instance_list = instance_list
118+
self.type = file_type
118119

119120
@staticmethod
120121
def from_dict(project: Project, dir_id: int, dict_data: dict):
121122
result = CompoundFile(project = project, name = dict_data.get('original_filename'), directory_id = dir_id)
122123
result.__refresh_compound_file_from_data_dict(data = dict_data)
123-
child_files = result.__fetch_child_files()
124+
child_files = result.fetch_child_files()
124125
result.child_files = child_files
125126
return result
126127

127-
def __fetch_child_files(self) -> List[CompoundChildFile]:
128+
def fetch_child_files(self, with_instances: bool = False) -> List[CompoundChildFile]:
128129
client = self.project
129130
endpoint = f"/api/v1/project/{self.project.project_string_id}/file/{self.id}/child-files"
130131

131-
response = client.session.get(client.host + endpoint)
132+
response = client.session.get(client.host + endpoint, params = {'with_instances': with_instances})
132133

133134
client.handle_errors(response)
134135

135136
data = response.json()
136137
child_files_data = data['child_files']
138+
print('child_files_data', child_files_data)
137139
result = []
138140
for elm in child_files_data:
139141
child_file = CompoundChildFile(root_file = self, child_file_type = elm.get('type'))
@@ -165,7 +167,8 @@ def __create_compound_parent_file(self):
165167
data = {
166168
'name': self.name,
167169
'directory_id': self.directory_id,
168-
'instance_list': self.instance_list
170+
'instance_list': self.instance_list,
171+
'type': self.type
169172
}
170173
response = self.project.session.post(url = self.project.host + url,
171174
json = data)

Diff for: sdk/diffgram/file/file.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from ..regular.regular import refresh_from_dict
22

3+
34
class File():
45
"""
56
file literal object
@@ -36,7 +37,7 @@ def new(
3637
3738
"""
3839

39-
file = File(client=client)
40+
file = File(client = client)
4041
refresh_from_dict(file, file_json)
4142
return file
4243

@@ -65,9 +66,9 @@ def update(
6566
if overwrite:
6667
packet['mode'] = "update_with_existing"
6768

68-
self.client.file.from_packet(packet=packet)
69+
self.client.file.from_packet(packet = packet)
6970

70-
def copy(self, destination_dir, copy_instances=False):
71+
def copy(self, destination_dir, copy_instances = False):
7172
payload = {
7273
'mode': 'TRANSFER',
7374
'file_list': [
@@ -88,17 +89,13 @@ def copy(self, destination_dir, copy_instances=False):
8889

8990
response = self.client.session.post(
9091
self.client.host + endpoint,
91-
json=payload)
92+
json = payload)
9293

9394
self.client.handle_errors(response)
9495

9596
data = response.json()
9697
new_file_data = data['log']['info']['new_file'][0]
9798

9899
return File.new(
99-
client=self.client,
100-
file_json=new_file_data)
101-
102-
103-
104-
100+
client = self.client,
101+
file_json = new_file_data)

0 commit comments

Comments
 (0)