def stat(self, path): full_path = get_lnt_path(self.get_full_path(path)) logger.info('stat:path="{}", full_path="{}"'.format(path, full_path)) files = self.client.get_files(full_path) folders = self.client.get_folders(full_path) if has_sharepoint_items(files) or has_sharepoint_items(folders): return { DSSConstants.PATH: get_lnt_path(path), DSSConstants.SIZE: 0, DSSConstants.IS_DIRECTORY: True } path_to_item, item_name = os.path.split(full_path) files = self.client.get_files(path_to_item) folders = self.client.get_folders(path_to_item) file = extract_item_from(item_name, files) folder = extract_item_from(item_name, folders) if folder is not None: return { DSSConstants.PATH: get_lnt_path(path), DSSConstants.SIZE: 0, DSSConstants.LAST_MODIFIED: get_last_modified(folder), DSSConstants.IS_DIRECTORY: True } if file is not None: return { DSSConstants.PATH: get_lnt_path(path), DSSConstants.SIZE: get_size(file), DSSConstants.LAST_MODIFIED: get_last_modified(file), DSSConstants.IS_DIRECTORY: False } return None
def delete_recursive(self, path): full_path = self.get_full_path(path) logger.info('delete_recursive:path={},fullpath={}'.format( path, full_path)) assert_path_is_not_root(full_path) path_to_item, item_name = os.path.split(full_path.rstrip("/")) files = self.client.get_files(path_to_item) folders = self.client.get_folders(path_to_item) file = extract_item_from(item_name, files) folder = extract_item_from(item_name, folders) if file is not None and folder is not None: raise Exception( "Ambiguous naming with file / folder {}".format(item_name)) if file is not None: self.client.delete_file(get_lnt_path(full_path)) return 1 if folder is not None: self.client.delete_folder(get_lnt_path(full_path)) return 1 return 0
def browse(self, path): path = get_rel_path(path) full_path = get_lnt_path(self.get_full_path(path)) logger.info('browse:path="{}", full_path="{}"'.format(path, full_path)) folders = self.client.get_folders(full_path) files = self.client.get_files(full_path) children = [] for file in loop_sharepoint_items(files): children.append({ DSSConstants.FULL_PATH: get_lnt_path(os.path.join(path, get_name(file))), DSSConstants.EXISTS: True, DSSConstants.DIRECTORY: False, DSSConstants.SIZE: get_size(file), DSSConstants.LAST_MODIFIED: get_last_modified(file) }) for folder in loop_sharepoint_items(folders): children.append({ DSSConstants.FULL_PATH: get_lnt_path(os.path.join(path, get_name(folder))), DSSConstants.EXISTS: True, DSSConstants.DIRECTORY: True, DSSConstants.SIZE: 0, DSSConstants.LAST_MODIFIED: get_last_modified(folder) }) if len(children) > 0: return { DSSConstants.FULL_PATH: get_lnt_path(path), DSSConstants.EXISTS: True, DSSConstants.DIRECTORY: True, DSSConstants.CHILDREN: children } path_to_file, file_name = os.path.split(full_path) files = self.client.get_files(path_to_file) for file in loop_sharepoint_items(files): if get_name(file) == file_name: return { DSSConstants.FULL_PATH: get_lnt_path(path), DSSConstants.EXISTS: True, DSSConstants.SIZE: get_size(file), DSSConstants.LAST_MODIFIED: get_last_modified(file), DSSConstants.DIRECTORY: False } parent_path, item_name = os.path.split(full_path) folders = self.client.get_folders(parent_path) folder = extract_item_from(item_name, folders) if folder is None: ret = {DSSConstants.FULL_PATH: None, DSSConstants.EXISTS: False} else: ret = { DSSConstants.FULL_PATH: get_lnt_path(path), DSSConstants.EXISTS: True, DSSConstants.DIRECTORY: True, DSSConstants.SIZE: 0 } return ret