Subpath handling, file creation metadata
This commit is contained in:
parent
126d6158db
commit
6930e8a25e
21
FSNode.py
21
FSNode.py
|
@ -170,7 +170,7 @@ class FSNode:
|
||||||
f.children.append(r)
|
f.children.append(r)
|
||||||
return f
|
return f
|
||||||
elif isinstance(mo, File):
|
elif isinstance(mo, File):
|
||||||
return FSNode.from_file(mo, parent, m)
|
FSNode.from_file(mo, parent, m)
|
||||||
elif isinstance(mo, Label):
|
elif isinstance(mo, Label):
|
||||||
FSNode.from_label(mo, parent, m)
|
FSNode.from_label(mo, parent, m)
|
||||||
elif isinstance(mo, Url):
|
elif isinstance(mo, Url):
|
||||||
|
@ -179,10 +179,22 @@ class FSNode:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_file(el: File, parent, m: Moodle):
|
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 = FSNode(el.name, parent, False)
|
||||||
f.size = el.filesize
|
f.size = el.filesize
|
||||||
f.linkTo = FileLink(el.fileurl)
|
f.linkTo = FileLink(el.fileurl)
|
||||||
return f
|
parent.children.append(f)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def hash_link_to(a: LinkTo):
|
def hash_link_to(a: LinkTo):
|
||||||
|
@ -238,3 +250,8 @@ class FSNode:
|
||||||
f.size = len(mo.url)
|
f.size = len(mo.url)
|
||||||
f.linkTo = UrlLink(mo.url)
|
f.linkTo = UrlLink(mo.url)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
def get_full_path(self) -> str:
|
||||||
|
if self.parent is None:
|
||||||
|
return "/"
|
||||||
|
return self.parent.get_full_path() + self.name + "/"
|
||||||
|
|
|
@ -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
|
* Automatic html-to-markdown conversion for announcements
|
||||||
|
|
||||||
### Future enhancements
|
### Future enhancements
|
||||||
* Fix known file displaying errors, expecially in subfolders
|
|
||||||
* Better memory handling (customizable), expecially for large files (chunking)
|
* Better memory handling (customizable), expecially for large files (chunking)
|
||||||
* Forum viewing support
|
* Forum viewing support
|
||||||
* Persistent tree cache (currently it is built at every mount)
|
* Persistent tree cache (currently it is built at every mount)
|
||||||
|
|
13
moodle.py
13
moodle.py
|
@ -2,6 +2,7 @@ import re
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
# a minimalistic moodle api wrapper, just for the purpose of this project
|
# 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 complete
|
||||||
# it's not meant to be efficient
|
# it's not meant to be efficient
|
||||||
|
@ -66,11 +67,15 @@ class Folder:
|
||||||
|
|
||||||
|
|
||||||
class File:
|
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.filename = filename
|
||||||
self.name = filename
|
self.name = filename
|
||||||
self.filesize = filesize
|
self.filesize = filesize
|
||||||
self.fileurl = fileurl
|
self.fileurl = fileurl
|
||||||
|
self.file_relative_path = file_relative_path
|
||||||
|
self.created = created
|
||||||
|
self.modified = modified
|
||||||
|
|
||||||
|
|
||||||
class Moodle:
|
class Moodle:
|
||||||
|
@ -147,10 +152,10 @@ class Moodle:
|
||||||
modules.append(Url(module["id"], module["name"],
|
modules.append(Url(module["id"], module["name"],
|
||||||
(module["description"] if "description" in module.keys() else ""),
|
(module["description"] if "description" in module.keys() else ""),
|
||||||
module["url"]))
|
module["url"]))
|
||||||
elif module["modname"] == "folder":
|
elif module["modname"] == "folder" or module["modname"] == "resource":
|
||||||
modules.append(self.__folder_rec_exploder(module))
|
modules.append(self.__folder_rec_exploder(module))
|
||||||
elif module["modname"] == "file":
|
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))
|
sections.append(Section(section["id"], section["name"], section["summary"], modules))
|
||||||
return sections
|
return sections
|
||||||
|
@ -159,7 +164,7 @@ class Moodle:
|
||||||
f = Folder(folder_module["id"], folder_module["name"], [])
|
f = Folder(folder_module["id"], folder_module["name"], [])
|
||||||
for file in folder_module["contents"]:
|
for file in folder_module["contents"]:
|
||||||
if file["type"] == "file":
|
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:
|
else:
|
||||||
f.files.append(self.__folder_rec_exploder(file))
|
f.files.append(self.__folder_rec_exploder(file))
|
||||||
return f
|
return f
|
||||||
|
|
|
@ -49,7 +49,7 @@ class MoodleFS(LoggingMixIn, Operations):
|
||||||
return ['.', '..'] + [child.name for child in dir_e.children]
|
return ['.', '..'] + [child.name for child in dir_e.children]
|
||||||
|
|
||||||
def readlink(self, path):
|
def readlink(self, path):
|
||||||
return self.data[path]
|
pass
|
||||||
|
|
||||||
def removexattr(self, path, name):
|
def removexattr(self, path, name):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user