Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • dariah-de/textgridrep/repdav
1 result
Show changes
Commits on Source (7)
## [1.1.2](https://gitlab.gwdg.de/dariah-de/textgridrep/repdav/compare/1.1.1...1.1.2) (2022-02-28)
### Bug Fixes
* **dav_provider:** reference correct class member ([a8f69ac](https://gitlab.gwdg.de/dariah-de/textgridrep/repdav/commit/a8f69ac73ca9e1421128a6fcb5896032a288cb6a))
## [1.1.1](https://gitlab.gwdg.de/dariah-de/textgridrep/repdav/compare/1.1.0...1.1.1) (2022-02-25)
......
......@@ -26,15 +26,15 @@ class TextgridRoot(DAVCollection):
def __init__(self, path, environ):
DAVCollection.__init__(self, path, environ)
self._sid = environ["wsgidav.auth.user_name"]
config = TextgridConfig()
self._auth = TextgridAuth(config)
def get_display_info(self):
return {"type": "Textgrid root collection"}
def get_member_names(self):
_logger.debug("Called TextgridRoot.get_member_names(self).")
config = TextgridConfig()
auth = TextgridAuth(config)
projects = tuple(auth.list_assigned_projects(self._sid))
projects = tuple(self._auth.list_assigned_projects(self._sid))
_logger.debug("MY PROJECTS: %s", projects)
return projects
......@@ -79,8 +79,9 @@ class TextgridProject(DAVCollection):
_logger.debug("Called TextgridProject.__init__(self, %s, environ).", path)
DAVCollection.__init__(self, path, environ)
self._sid = environ["wsgidav.auth.user_name"]
self._tgconfig = TextgridConfig()
self._tgsearch = TextgridSearch(self._tgconfig.search)
config = TextgridConfig()
self._tgsearch = TextgridSearch(config.search)
self._project_id = self.path.split("/")[-1]
def create_empty_resource(self, name):
pass
......@@ -100,7 +101,7 @@ class TextgridProject(DAVCollection):
# return names
#
# path resolution has to be rewritten before we can work with resource titles
response = self._tgsearch.list_project_root(self.path.split("/")[-1], self._sid)
response = self._tgsearch.list_project_root(self._project_id, self._sid)
names = []
for result in response.result:
names.append(result.object_value.generic.generated.textgrid_uri.value)
......@@ -170,8 +171,9 @@ class TextgridAggregation(DAVCollection):
DAVCollection.__init__(self, path, environ)
self._sid = environ["wsgidav.auth.user_name"]
self._info = info
self._tgconfig = TextgridConfig()
self._tgsearch = TextgridSearch(self._tgconfig.search)
config = TextgridConfig()
self._tgsearch = TextgridSearch(config.search)
self._tguri = self.path.split("/")[-1]
def create_empty_resource(self, name):
pass
......@@ -184,7 +186,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 +254,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 +270,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 +282,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)
......
import io
import logging
import threading
from pprint import pformat
from tgclients.config import TextgridConfig
from tgclients.crud import TextgridCRUD
from tgclients.metadata import TextgridMetadata
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,
......@@ -45,10 +39,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)
def get_member_names(self):
_logger.debug("Called TextgridNamedRoot.get_member_names(self).")
......@@ -70,19 +61,13 @@ class TextgridNamedProject(TextgridProject):
_logger.debug("Called TextgridNamedProject.__init__(self, %s, environ).", path)
super().__init__(path, environ)
self._tgmeta = TextgridMetadata()
name = self.path.split("/")[-1]
# the projectID is found between square brackets at the end of the name string
self._project_id = name[name.rfind("[") + 1 : name.rfind("]")]
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]
project_id = name[name.rfind("[") + 1 : name.rfind("]")]
response = self._tgsearch.list_project_root(project_id, self._sid)
response = self._tgsearch.list_project_root(self._project_id, self._sid)
names = []
for result in response.result:
names.append(self._tgmeta.filename_from_metadata(result))
......@@ -116,11 +101,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 +139,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])