diff --git a/FSNode.py b/FSNode.py index 273dec0..fccca15 100644 --- a/FSNode.py +++ b/FSNode.py @@ -170,7 +170,7 @@ class FSNode: f.children.append(r) return f elif isinstance(mo, File): - return FSNode.from_file(mo, parent, m) + FSNode.from_file(mo, parent, m) elif isinstance(mo, Label): FSNode.from_label(mo, parent, m) elif isinstance(mo, Url): @@ -179,10 +179,22 @@ class FSNode: @staticmethod def from_file(el: File, parent, m: Moodle): + subpaths = el.file_relative_path.split("/") + if subpaths[-1] == "": + subpaths = subpaths[:-1] + if subpaths[0] == "": + subpaths = subpaths[1:] + for path_component in subpaths: + path_component = slugify(path_component) + element = parent.find_child_by_name(path_component) + if element is None: + element = FSNode(path_component, parent, True) + parent.children.append(element) + parent = element f = FSNode(el.name, parent, False) f.size = el.filesize f.linkTo = FileLink(el.fileurl) - return f + parent.children.append(f) @staticmethod def hash_link_to(a: LinkTo): @@ -238,3 +250,8 @@ class FSNode: f.size = len(mo.url) f.linkTo = UrlLink(mo.url) return f + + def get_full_path(self) -> str: + if self.parent is None: + return "/" + return self.parent.get_full_path() + self.name + "/" diff --git a/README.md b/README.md index eac4b79..6386886 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,6 @@ This only works on Linux, as it uses FUSE. I have not tested it on Mac, but it c * Automatic html-to-markdown conversion for announcements ### Future enhancements -* Fix known file displaying errors, expecially in subfolders * Better memory handling (customizable), expecially for large files (chunking) * Forum viewing support * Persistent tree cache (currently it is built at every mount) diff --git a/moodle.py b/moodle.py index 94cc76c..1daa553 100644 --- a/moodle.py +++ b/moodle.py @@ -2,6 +2,7 @@ import re import requests + # a minimalistic moodle api wrapper, just for the purpose of this project # it's not meant to be complete # it's not meant to be efficient @@ -66,11 +67,15 @@ class Folder: class File: - def __init__(self, filename: str, filesize: int, fileurl: str): + def __init__(self, filename: str, filesize: int, fileurl: str, file_relative_path: str | None, created: int | None, + modified: int | None): self.filename = filename self.name = filename self.filesize = filesize self.fileurl = fileurl + self.file_relative_path = file_relative_path + self.created = created + self.modified = modified class Moodle: @@ -147,10 +152,10 @@ class Moodle: modules.append(Url(module["id"], module["name"], (module["description"] if "description" in module.keys() else ""), module["url"])) - elif module["modname"] == "folder": + elif module["modname"] == "folder" or module["modname"] == "resource": modules.append(self.__folder_rec_exploder(module)) elif module["modname"] == "file": - modules.append(File(module["fileurl"], module["filename"], module["filesize"], module["fileurl"])) + modules.append(File(module["filename"], module["filesize"], module["fileurl"], module["filepath"], module["timecreated"], module["timemodified"])) sections.append(Section(section["id"], section["name"], section["summary"], modules)) return sections @@ -159,7 +164,7 @@ class Moodle: f = Folder(folder_module["id"], folder_module["name"], []) for file in folder_module["contents"]: if file["type"] == "file": - f.files.append(File(file["filename"], file["filesize"], file["fileurl"])) + f.files.append(File(file["filename"], file["filesize"], file["fileurl"], file["filepath"], file["timecreated"], file["timemodified"])) else: f.files.append(self.__folder_rec_exploder(file)) return f diff --git a/moodlefs.py b/moodlefs.py index 48d4712..894bad5 100644 --- a/moodlefs.py +++ b/moodlefs.py @@ -49,7 +49,7 @@ class MoodleFS(LoggingMixIn, Operations): return ['.', '..'] + [child.name for child in dir_e.children] def readlink(self, path): - return self.data[path] + pass def removexattr(self, path, name): pass