diff --git a/src/repdav/textgrid_dav_provider.py b/src/repdav/textgrid_dav_provider.py index 1c52069a1d41f52c7691cfc470414609ba7aa7a5..afe15bb5caeb7b874083864baebc47841a48d518 100644 --- a/src/repdav/textgrid_dav_provider.py +++ b/src/repdav/textgrid_dav_provider.py @@ -172,6 +172,7 @@ class TextgridAggregation(DAVCollection): self._info = info self._tgconfig = TextgridConfig() self._tgsearch = TextgridSearch(self._tgconfig.search) + self._tguri = self.path.split("/")[-1] def create_empty_resource(self, name): pass @@ -184,7 +185,7 @@ class TextgridAggregation(DAVCollection): def get_member_names(self): _logger.debug("Called TextgridAggregation.get_member_names(self).") - response = self._tgsearch.list_aggregation(self.path.split("/")[-1], self._sid) + response = self._tgsearch.list_aggregation(self._tguri, self._sid) names = [] for result in response.result: names.append(result.object_value.generic.generated.textgrid_uri.value) @@ -252,8 +253,11 @@ class TextgridResource(DAVNonCollection): DAVNonCollection.__init__(self, path, environ) self._size = environ.get("CONTENT_LENGTH") self._sid = environ["wsgidav.auth.user_name"] + self._tguri = self.path.split("/")[-1] self._info = info self.upload_thread = None + config = TextgridConfig() + self._crud = TextgridCRUD(config.crud) def get_content_length(self): _logger.debug("Called TextgridResource.get_content_length(self).") @@ -265,9 +269,7 @@ class TextgridResource(DAVNonCollection): def get_content(self): _logger.debug("Called TextgridResource.get_content(self) with path: %s", self.path) - config = TextgridConfig() - crud = TextgridCRUD(config.crud) - return io.BytesIO(crud.read_data(self.path.split("/")[-1], self._sid).content) + return io.BytesIO(self._crud.read_data(self._tguri, self._sid).content) def get_content_title(self): _logger.debug("Called TextgridResource.get_content_title(self).") @@ -279,13 +281,11 @@ class TextgridResource(DAVNonCollection): ) queue = FileLikeQueue(int(self._size)) - config = TextgridConfig() - crud = TextgridCRUD(config.crud) - metadata = crud.read_metadata(self.path.split("/")[-1], self._sid).content + metadata = self._crud.read_metadata(self._tguri, self._sid).content def worker(): _logger.debug("Called TextgridResource.begin_write.worker().") - crud.update_resource(self._sid, self.path.split("/")[-1], queue, metadata) + self._crud.update_resource(self._sid, self._tguri, queue, metadata) thread = threading.Thread(target=worker) thread.setDaemon(True) diff --git a/src/repdav/textgrid_named_dav_provider.py b/src/repdav/textgrid_named_dav_provider.py index dd03452ff274401ef922d927532849ae7c5ca63b..b1a1e4252b468e3727ace2556f7b6f74b033691d 100644 --- a/src/repdav/textgrid_named_dav_provider.py +++ b/src/repdav/textgrid_named_dav_provider.py @@ -1,6 +1,4 @@ -import io import logging -import threading from pprint import pformat from tgclients.config import TextgridConfig @@ -73,14 +71,8 @@ class TextgridNamedProject(TextgridProject): def get_member_names(self): _logger.debug("Called TextgridNamedProject.get_member_names(self).") - # names = [] - # the item keys are textgrid uris but we want the resource titles only - # for _, member_dict in self._resources.items(): - # names.append(member_dict.get("title")) - # return names - # - # path resolution has to be rewritten before we can work with resource titles name = self.path.split("/")[-1] + # the projectID is found between square brackets at the end of the name string project_id = name[name.rfind("[") + 1 : name.rfind("]")] response = self._tgsearch.list_project_root(project_id, self._sid) names = [] @@ -116,11 +108,11 @@ class TextgridNamedAggregation(TextgridAggregation): ) super().__init__(path, environ, info) self._tgmeta = tgmeta + self._tguri = "textgrid:" + self._tgmeta.id_from_filename(self.path.split("/")[-1]) def get_member_names(self): _logger.debug("Called TextgridNamedAggregation.get_member_names(self).") - tguri = "textgrid:" + self._tgmeta.id_from_filename(self.path.split("/")[-1]) - response = self._tgsearch.list_aggregation(tguri, self._sid) + response = self._tgsearch.list_aggregation(self._tguri, self._sid) names = [] for result in response.result: names.append(self._tgmeta.filename_from_metadata(result)) @@ -154,33 +146,4 @@ class TextgridNamedResource(TextgridResource): _logger.debug("Called TextgridNamedResource.__init__(self, %s, environ).", path) super().__init__(path, environ, info) self._tgmeta = tgmeta - config = TextgridConfig() - self._crud = TextgridCRUD(config.crud) - - def get_content(self): - _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]) - - return io.BytesIO(self._crud.read_data(tguri, self._sid).content) - - def begin_write(self, content_type=None): - _logger.debug( - "Called TextgridResource.begin_write(self, content_type=%s).", content_type - ) - - queue = FileLikeQueue(int(self._size)) - tguri = "textgrid:" + self._tgmeta.id_from_filename(self.path.split("/")[-1]) - metadata = self._crud.read_metadata(tguri, self._sid).content - - def worker(): - _logger.debug("Called TextgridResource.begin_write.worker().") - self._crud.update_resource(self._sid, tguri, queue, metadata) - - thread = threading.Thread(target=worker) - thread.setDaemon(True) - thread.start() - self.upload_thread = thread - return queue + self._tguri = "textgrid:" + self._tgmeta.id_from_filename(self.path.split("/")[-1])