Пример #1
0
    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
Пример #2
0
 def list_recursive(self, path, full_path, first_non_empty):
     paths = []
     folders = self.client.get_folders(full_path)
     for folder in loop_sharepoint_items(folders):
         paths.extend(
             self.list_recursive(
                 get_lnt_path(os.path.join(path, get_name(folder))),
                 get_lnt_path(os.path.join(full_path, get_name(folder))),
                 first_non_empty))
     files = self.client.get_files(full_path)
     for file in loop_sharepoint_items(files):
         paths.append({
             DSSConstants.PATH:
             get_lnt_path(os.path.join(path, get_name(file))),
             DSSConstants.LAST_MODIFIED:
             get_last_modified(file),
             DSSConstants.SIZE:
             get_size(file)
         })
         if first_non_empty:
             return paths
     return paths
Пример #3
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