Skip to content
Snippets Groups Projects
Verified Commit 44cf94a2 authored by Stefan Hynek's avatar Stefan Hynek :drooling_face:
Browse files

refactor(named_dav_provider): format, lint, add comments

parent 005abd2e
No related branches found
No related tags found
1 merge request!14Resolve "Show titles and format in repdav listing"
Pipeline #278346 passed
......@@ -10,10 +10,13 @@ from tgclients.auth import TextgridAuth
from wsgidav.util import join_uri
from repdav.stream_tools import FileLikeQueue
from repdav.textgrid_dav_provider import (TextgridAggregation, TextgridProject,
TextgridResource,
TextgridResourceProvider,
TextgridRoot)
from repdav.textgrid_dav_provider import (
TextgridAggregation,
TextgridProject,
TextgridResource,
TextgridResourceProvider,
TextgridRoot,
)
_logger = logging.getLogger(__name__)
......@@ -42,6 +45,7 @@ class TextgridNamedRoot(TextgridRoot):
"""
def __init__(self, path, environ):
# TODO: do not overwrite but move to parent class
super().__init__(path, environ)
config = TextgridConfig()
self._auth = TextgridAuth(config)
......@@ -50,7 +54,9 @@ class TextgridNamedRoot(TextgridRoot):
_logger.debug("Called TextgridNamedRoot.get_member_names(self).")
projects = []
for project in tuple(self._auth.list_assigned_projects(self._sid)):
projects.append(self._auth.get_project_description(project).name + ' [' + project + ']')
projects.append(
self._auth.get_project_description(project).name + " [" + project + "]"
)
_logger.debug("MY PROJECTS: %s", projects)
return projects
......@@ -58,6 +64,7 @@ class TextgridNamedRoot(TextgridRoot):
_logger.debug("Called TextgridRoot.get_member(self, %s).", name)
return TextgridNamedProject(join_uri(self.path, name), self.environ)
class TextgridNamedProject(TextgridProject):
def __init__(self, path, environ):
_logger.debug("Called TextgridNamedProject.__init__(self, %s, environ).", path)
......@@ -74,7 +81,7 @@ class TextgridNamedProject(TextgridProject):
#
# path resolution has to be rewritten before we can work with resource titles
name = self.path.split("/")[-1]
project_id = name[name.rfind('[')+1:name.rfind(']')]
project_id = name[name.rfind("[") + 1 : name.rfind("]")]
response = self._tgsearch.list_project_root(project_id, self._sid)
names = []
for result in response.result:
......@@ -83,7 +90,7 @@ class TextgridNamedProject(TextgridProject):
def get_member(self, name):
_logger.debug("Called TextgridNamedProject.get_member(self, %s).", name)
tguri = 'textgrid:' + self._tgmeta.id_from_filename(name)
tguri = "textgrid:" + self._tgmeta.id_from_filename(name)
response = self._tgsearch.info(tguri, self._sid)
info = {
name: {
......@@ -94,8 +101,13 @@ class TextgridNamedProject(TextgridProject):
}
_logger.info("INFO: %s", info)
if "aggregation" in info[name]["format"]:
return TextgridNamedAggregation(join_uri(self.path, name), self.environ, info, self._tgmeta)
return TextgridNamedResource(join_uri(self.path, name), self.environ, info, self._tgmeta)
return TextgridNamedAggregation(
join_uri(self.path, name), self.environ, info, self._tgmeta
)
return TextgridNamedResource(
join_uri(self.path, name), self.environ, info, self._tgmeta
)
class TextgridNamedAggregation(TextgridAggregation):
def __init__(self, path, environ, info, tgmeta):
......@@ -107,7 +119,7 @@ class TextgridNamedAggregation(TextgridAggregation):
def get_member_names(self):
_logger.debug("Called TextgridNamedAggregation.get_member_names(self).")
tguri = 'textgrid:' + self._tgmeta.id_from_filename(self.path.split("/")[-1])
tguri = "textgrid:" + self._tgmeta.id_from_filename(self.path.split("/")[-1])
response = self._tgsearch.list_aggregation(tguri, self._sid)
names = []
for result in response.result:
......@@ -116,7 +128,7 @@ class TextgridNamedAggregation(TextgridAggregation):
def get_member(self, name):
_logger.debug("Called TextgridNamedAggregation.get_member(self, %s).", name)
tguri = 'textgrid:' + self._tgmeta.id_from_filename(name)
tguri = "textgrid:" + self._tgmeta.id_from_filename(name)
response = self._tgsearch.info(tguri, self._sid)
info = {
name: {
......@@ -127,8 +139,13 @@ class TextgridNamedAggregation(TextgridAggregation):
}
_logger.info("INFO: %s", info)
if "aggregation" in info[name]["format"]:
return TextgridNamedAggregation(join_uri(self.path, name), self.environ, info, self._tgmeta)
return TextgridNamedResource(join_uri(self.path, name), self.environ, info, self._tgmeta)
return TextgridNamedAggregation(
join_uri(self.path, name), self.environ, info, self._tgmeta
)
return TextgridNamedResource(
join_uri(self.path, name), self.environ, info, self._tgmeta
)
class TextgridNamedResource(TextgridResource):
"""Non-Aggregation resources."""
......@@ -141,10 +158,12 @@ class TextgridNamedResource(TextgridResource):
self._crud = TextgridCRUD(config.crud)
def get_content(self):
_logger.debug("Called TextgridNamedResource.get_content(self) with path:", self.path)
tguri = 'textgrid:' + self._tgmeta.id_from_filename(self.path.split("/")[-1])
_logger.debug(
"Called TextgridNamedResource.get_content(self) with path: %s", self.path
)
# TODO: make tguri (super!) class member
tguri = "textgrid:" + self._tgmeta.id_from_filename(self.path.split("/")[-1])
_logger.debug("crud-read: " + tguri)
return io.BytesIO(self._crud.read_data(tguri, self._sid).content)
def begin_write(self, content_type=None):
......@@ -153,7 +172,7 @@ class TextgridNamedResource(TextgridResource):
)
queue = FileLikeQueue(int(self._size))
tguri = 'textgrid:' + self._tgmeta.id_from_filename(self.path.split("/")[-1])
tguri = "textgrid:" + self._tgmeta.id_from_filename(self.path.split("/")[-1])
metadata = self._crud.read_metadata(tguri, self._sid).content
def worker():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment