def delete(self, user, path): vfs = "/" + path.split("/")[1] if vfs in self.filesystems: return self.filesystems[vfs].delete(user, "/" + remove_prefix(path, vfs)) else: raise Exception()
def set_content(self, user, path, content, start=-1): vfs = "/" + path.split("/")[1] if vfs in self.filesystems: return self.filesystems[vfs].set_content( user, "/" + remove_prefix(path, vfs), content, start) else: raise Exception()
def get_content(self, user, path, start=-1, end=-1): vfs = "/" + path.split("/")[1] if vfs in self.filesystems: return self.filesystems[vfs].get_content( user, "/" + remove_prefix(path, vfs), start, end) else: raise FileNotFoundError()
def create(self, user, path, dir=True): vfs = "/" + path.split("/")[1] if vfs in self.filesystems: return self.filesystems[vfs].create(user, "/" + remove_prefix(path, vfs), dir) else: raise Exception()
def get_uid(self, user, path): if path == "/": return "root" else: vfs = "/" + path.split("/")[1] if vfs in self.filesystems: return self.filesystems[vfs].get_uid( user, "/" + remove_prefix(path, vfs)) else: raise Exception()
def get_children(self, user, path): if path == "/": children = [] for cpath, fs in self.filesystems.items(): children.append(cpath) return children else: vfs = "/" + path.split("/")[1] if vfs in self.filesystems: children = [] vfschildren = self.filesystems[vfs].get_children( user, "/" + remove_prefix(path, vfs)) #self.log.debug("\tMultiplex children from %s" % (str(vfschildren))) for cpath in vfschildren: children.append(path_join(vfs, cpath)) #self.log.debug("\tMultiplex children to %s" % (str(children))) return children else: return []
def get_props(self, user, path, props=STDPROP): if path == "/": # Root path, need to construct virtual folder return { "D:status": "200 OK", "D:name": "/", "D:creationdate": unixdate2httpdate(0), "D:lastaccessed": unixdate2httpdate(0), "D:lastmodified": unixdate2httpdate(0), "D:getlastmodified": unixdate2httpdate(0), "D:getcontentlength": 4096, "D:resourcetype": "<D:collection/>", "D:iscollection": True } else: vfs = "/" + path.split("/")[1] if vfs in self.filesystems: return self.filesystems[vfs].get_props( user, "/" + remove_prefix(path, vfs), props, path) else: raise FileNotFoundError()
def get_children(self, user, path): lock.acquire() self.operator.begin(user) try: rpath = self.convert_local_to_real(path) #self.log.debug("get_children(%s)" % path) try: if os.path.isdir(rpath): l = [] for sub in os.listdir(rpath): l.append( path_join(path, remove_prefix(sub, self.basepath))) return l else: return [] except PermissionError: raise PermissionError() finally: self.operator.end(user) lock.release()
def do_GET(self): request = GETRequest(self) if self.require_auth(request): return self.log.info(request) try: props = self.server.fs.get_props(self.user, request.path, ["D:iscollection"]) if props["D:iscollection"]: children = self.server.fs.get_children(self.user, request.path) data = [] for c in children: cdata = {} cdata["path"] = c cdata["name"] = remove_prefix(c, request.path) cdata["directory"] = self.server.fs.get_props( self.user, c, ["D:iscollection"])["D:iscollection"] cdata["hidden"] = self.server.fs.get_props( self.user, c, ["D:ishidden"])["D:ishidden"] data.append(cdata) if request.path != "/": data.append({ "path": os.path.split(request.path)[0], "name": "..", "hidden": False, "directory": True }) sort = sorted(data, key=lambda k: (not k["directory"], k["path"].lower())) b = WriteBuffer(self.wfile) b.write(self.server.templates["directory"].render( path=request.path, children=sort)) self.log.debug("200 OK") self.send_response(200, "OK") self.send_header("Content-Length", str(b.getSize())) self.send_header("Content-Type", "text/html; charset=utf-8") self.end_headers() b.flush() else: filedata = self.server.fs.get_content(self.user, request.path) ctype = props = self.server.fs.get_props( self.user, request.path, ["D:getcontenttype"])["D:getcontenttype"] b = WriteBuffer(self.wfile) b.write(filedata) self.log.debug("200 OK") self.send_response(200, "OK") self.send_header("Content-Length", str(b.getSize())) self.send_header("Content-Type", ctype + "; charset=utf-8") self.end_headers() b.flush() except FileNotFoundError: self.log.debug("404 Not Found") self.send_response(404, "Not Found") self.end_headers() except PermissionError: self.log.debug("403 Forbidden") self.send_response(403, "Forbidden") self.end_headers()