markup/webdav.py: cleanup
This commit is contained in:
@ -62,10 +62,6 @@ def is_markup_catalog(path):
|
||||
|
||||
class MarkupDavResource(MetaEtagMixIn, BaseDavResource):
|
||||
|
||||
# def __init__(self, path=None, user=None):
|
||||
# super().__init__(path)
|
||||
# self.user = user
|
||||
|
||||
def __str__(self):
|
||||
return f"<{type(self).__name__} '{self.user}' '{self.path}'>"
|
||||
|
||||
@ -78,10 +74,6 @@ class RootFolderResource(MarkupDavResource):
|
||||
NAME = ''
|
||||
PATH = '/'
|
||||
|
||||
# def get_parent_path(self):
|
||||
# path = self.path[:-1]
|
||||
# return "/" + "/".join(path) + "/" if path else ""
|
||||
|
||||
def get_parent(self):
|
||||
return None
|
||||
|
||||
@ -160,9 +152,9 @@ class CatalogResource(MarkupDavResource):
|
||||
def get_parent(self):
|
||||
return CatalogFolderResource(path=CatalogFolderResource.PATH, user=self.user)
|
||||
|
||||
# def get_children(self):
|
||||
# return
|
||||
# yield
|
||||
def get_children(self):
|
||||
return
|
||||
yield
|
||||
|
||||
@cached_property
|
||||
def catalog(self):
|
||||
@ -199,47 +191,14 @@ class CatalogResource(MarkupDavResource):
|
||||
|
||||
@property
|
||||
def exists(self):
|
||||
log.info(f'exists? {self.catalog.pdf_exists()}')
|
||||
return self.catalog.pdf_exists()
|
||||
|
||||
# def delete(self):
|
||||
# """Delete the resource, recursive is implied."""
|
||||
# if self.is_collection:
|
||||
# for child in self.get_children():
|
||||
# child.delete()
|
||||
# os.rmdir(self.get_abs_path())
|
||||
# elif self.is_object:
|
||||
# os.remove(self.get_abs_path())
|
||||
|
||||
# def create_collection(self):
|
||||
# """Create a directory in the location of this resource."""
|
||||
# os.mkdir(self.get_abs_path())
|
||||
|
||||
# def copy_object(self, destination, depth=0):
|
||||
# shutil.copy(self.get_abs_path(), destination.get_abs_path())
|
||||
|
||||
# def move_object(self, destination):
|
||||
# os.rename(self.get_abs_path(), destination.get_abs_path())
|
||||
|
||||
def read(self):
|
||||
if self.catalog.pdf_exists():
|
||||
return open(self.catalog.pdf_file(), 'rb')
|
||||
else:
|
||||
return None
|
||||
|
||||
# def write(self, request, temp_file=None, range_start=None):
|
||||
# if temp_file:
|
||||
# # move temp file (e.g., coming from nginx)
|
||||
# shutil.move(temp_file, self.get_abs_path())
|
||||
# elif range_start == None:
|
||||
# # open binary file and write to disk
|
||||
# with open(self.get_abs_path(), 'wb') as dst:
|
||||
# shutil.copyfileobj(request, dst)
|
||||
# else:
|
||||
# # open binary file and write to disk
|
||||
# with open(self.get_abs_path(), 'r+b') as dst:
|
||||
# dst.seek(range_start)
|
||||
# shutil.copyfileobj(request, dst)
|
||||
|
||||
|
||||
class MarkupResource(MarkupDavResource, DummyFSDAVResource):
|
||||
@ -249,15 +208,12 @@ class MarkupResource(MarkupDavResource, DummyFSDAVResource):
|
||||
def get_parent(self):
|
||||
parent_path = self.path[:-1]
|
||||
if len(parent_path):
|
||||
log.info(f"markup folder get parent for {self.user} / {self.path}: {parent_path} - PARENT")
|
||||
return MarkupResource(path=self.construct_path(parent_path, True), user=self.user)
|
||||
else:
|
||||
log.info(f"markup folder get parent for {self.user} / {self.path}: {parent_path} - ROOT")
|
||||
return RootFolderResource(user=self.user)
|
||||
|
||||
def get_children(self):
|
||||
path = self.get_abs_path()
|
||||
log.info(f"markup folder get_children '{path}' user: {self.user}")
|
||||
if os.path.isdir(path):
|
||||
for child in os.listdir(path):
|
||||
is_unicode = isinstance(child, str)
|
||||
@ -270,14 +226,7 @@ class MarkupResource(MarkupDavResource, DummyFSDAVResource):
|
||||
# log.debug(f'markup folder user is {self.user} and path {self.path}: {path}')
|
||||
return path
|
||||
|
||||
def get_markup_user_path(self):
|
||||
log.debug(f'get_markup_user_path for {self} has user {self.user}')
|
||||
return os.path.join(f'{ASSET_DIR}/webdav/', 'markup', self.user.username)
|
||||
|
||||
def write(self, request, temp_file=None, range_start=None):
|
||||
# make sure dest dir exists first
|
||||
dest_dir = dirname(self.get_abs_path())
|
||||
Path(dest_dir).mkdir(parents=True, exist_ok=True)
|
||||
super().write(request, temp_file=temp_file, range_start=range_start)
|
||||
|
||||
def get_acl(self):
|
||||
|
||||
Reference in New Issue
Block a user