diff --git a/sdk/diffgram/core/diffgram_dataset_iterator.py b/sdk/diffgram/core/diffgram_dataset_iterator.py index 73f797b..b702e5e 100644 --- a/sdk/diffgram/core/diffgram_dataset_iterator.py +++ b/sdk/diffgram/core/diffgram_dataset_iterator.py @@ -187,13 +187,24 @@ def gen_tag_instances(self, instance_list): result.append(elm) return result - def get_file_instances(self, diffgram_file): - sample = {'diffgram_file': diffgram_file} + def get_file_instances(self, diffgram_file) -> dict: + if not diffgram_file: + return + sample = {'diffgram_file': diffgram_file, 'type': diffgram_file.type} if diffgram_file.type not in ['image', 'frame', 'compound']: logging.warning('File type "{}" is not supported yet'.format(diffgram_file.type)) return sample if diffgram_file.type in ['image', 'frame']: sample['image'] = self.get_image_data(diffgram_file) + elif diffgram_file.type is not None and diffgram_file.type.startswith('compound'): + from diffgram.file.compound_file import CompoundFile + compound_file: CompoundFile = diffgram_file + sample['children'] = [] + child_files = compound_file.fetch_child_files(with_instances = True) + print('chsad', child_files) + for child in child_files: + result = self.get_file_instances(child) + sample['children'].append(result) instance_list = diffgram_file.instance_list instance_types_in_file = set([x['type'] for x in instance_list]) # Process the instances of each file diff --git a/sdk/diffgram/core/directory.py b/sdk/diffgram/core/directory.py index 615d5d8..702a4ee 100644 --- a/sdk/diffgram/core/directory.py +++ b/sdk/diffgram/core/directory.py @@ -119,7 +119,7 @@ def all_file_ids(self, query = None): page_num = page_num, file_view_mode = 'ids_only', query = query, - with_children_files = True) + with_children_files = False) if diffgram_ids is False: raise Exception('Error Fetching Files: Please check you are providing a valid query.') diff --git a/sdk/diffgram/file/compound_file.py b/sdk/diffgram/file/compound_file.py index c94524c..6818e5d 100644 --- a/sdk/diffgram/file/compound_file.py +++ b/sdk/diffgram/file/compound_file.py @@ -120,20 +120,21 @@ def __init__(self, project: Project, name: str, directory_id: int, instance_list def from_dict(project: Project, dir_id: int, dict_data: dict): result = CompoundFile(project = project, name = dict_data.get('original_filename'), directory_id = dir_id) result.__refresh_compound_file_from_data_dict(data = dict_data) - child_files = result.__fetch_child_files() + child_files = result.fetch_child_files() result.child_files = child_files return result - def __fetch_child_files(self) -> List[CompoundChildFile]: + def fetch_child_files(self, with_instances: bool = False) -> List[CompoundChildFile]: client = self.project endpoint = f"/api/v1/project/{self.project.project_string_id}/file/{self.id}/child-files" - response = client.session.get(client.host + endpoint) + response = client.session.get(client.host + endpoint, params = {'with_instances': with_instances}) client.handle_errors(response) data = response.json() child_files_data = data['child_files'] + print('child_files_data', child_files_data) result = [] for elm in child_files_data: child_file = CompoundChildFile(root_file = self, child_file_type = elm.get('type')) diff --git a/sdk/diffgram/file/file.py b/sdk/diffgram/file/file.py index 4fedf11..fee5ed3 100644 --- a/sdk/diffgram/file/file.py +++ b/sdk/diffgram/file/file.py @@ -1,5 +1,6 @@ from ..regular.regular import refresh_from_dict + class File(): """ file literal object @@ -36,7 +37,7 @@ def new( """ - file = File(client=client) + file = File(client = client) refresh_from_dict(file, file_json) return file @@ -65,9 +66,9 @@ def update( if overwrite: packet['mode'] = "update_with_existing" - self.client.file.from_packet(packet=packet) + self.client.file.from_packet(packet = packet) - def copy(self, destination_dir, copy_instances=False): + def copy(self, destination_dir, copy_instances = False): payload = { 'mode': 'TRANSFER', 'file_list': [ @@ -88,7 +89,7 @@ def copy(self, destination_dir, copy_instances=False): response = self.client.session.post( self.client.host + endpoint, - json=payload) + json = payload) self.client.handle_errors(response) @@ -96,9 +97,5 @@ def copy(self, destination_dir, copy_instances=False): new_file_data = data['log']['info']['new_file'][0] return File.new( - client=self.client, - file_json=new_file_data) - - - - + client = self.client, + file_json = new_file_data)