def get_label(self, name=None, name_list=None): """ name, str name_list, list, optional Name must be an exact match to label name. If a name_list is provided it will construct a list of objects that match that name. Returns None if not found. File object of type Label if found. List of File objects if a name_list is provided. """ if self.name_to_file_id is None: self.get_label_file_dict() if name_list: out = [] for name in name_list: out.append(self.get_label(name)) return out id = self.name_to_file_id.get(name) if id is None: return None file = File(id=id) return file
def list_files(self, limit=None): """ Get a list of files in directory (from Diffgram service). Assumes we are using the default directory. this can be changed ie by: project.set_directory_by_name(dir_name) We don't have a strong Directory concept in the SDK yet So for now assume that we need to call project.set_directory_by_name(dir_name) first if we want to change the directory WIP Feb 3, 2020 A lot of "hard coded" options here. Want to think a bit more about what we want to expose options here and what good contexts are. """ directory_id = self.client.directory_id #print("directory_id", directory_id) metadata = { 'metadata': { 'directory_id': directory_id, 'annotations_are_machine_made_setting': "All", 'annotation_status': "All", 'limit': limit, 'media_type': "All", 'request_next_page': False, 'request_previous_page': False, 'file_view_mode': "annotation" } } # User concept, in this context, is deprecated # 'sdk' is a placeholder value endpoint = "/api/project/" + \ self.client.project_string_id + \ "/user/sdk" + "/file/list" response = self.client.session.post(self.client.host + endpoint, json=metadata) self.client.handle_errors(response) # Success data = response.json() file_list_json = data.get('file_list') # TODO would like this to perhaps be a seperate function # ie part of File_Constructor perhaps file_list = [] for file_json in file_list_json: file = File.new(file_json=file_json) file_list.append(file) return file_list
def file_from_response(self, file_dict): """ file_dict, dict, file information from Project returns file, class File object """ file = File(id=file_dict['id']) return file
def __factory_create_object_from_json(task_in_json): """ In the current context a user doesn't create a new File directly, the system creates a file at import and/or when copying / operating on a file. """ task = Task() refresh_from_dict(task, task_in_json) if task.file: task.file = File.new( client = self.client, file_json = task.file) return task
def get_by_id(self, id: int): """ returns Diffgram File object """ endpoint = "/api/v1/file/view" spec_dict = { 'file_id': id, 'project_string_id': self.client.project_string_id } response = self.client.session.post(self.client.host + endpoint, json=spec_dict) self.client.handle_errors(response) response_json = response.json() return File.new(client=self.client, file_json=response_json.get('file'))