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

feat(textgrid_dav_provider): initialize textgrid config with "tg_host" from wsgidav environ

this allows for configuration of the textgrid host from the environment
parent ba1132fb
No related branches found
No related tags found
1 merge request!24Resolve "make host, port, dsn and textgrid host configurable"
...@@ -21,6 +21,16 @@ from repdav.stream_tools import FileLikeQueue ...@@ -21,6 +21,16 @@ from repdav.stream_tools import FileLikeQueue
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
def tg_config(environ):
"""Initialize Textgrid configuration either with or without host setting. This
works around an [issue with tgclients](https://gitlab.gwdg.de/dariah-de/textgridrep/textgrid-python-clients/-/issues/59).
"""
tg_host = environ["wsgidav.config"]["tg_host"]
if tg_host:
return TextgridConfig(tg_host)
return TextgridConfig()
class TextgridRoot(DAVCollection): class TextgridRoot(DAVCollection):
"""Top level collection that incorporates Textgrid projects. """Top level collection that incorporates Textgrid projects.
...@@ -30,8 +40,9 @@ class TextgridRoot(DAVCollection): ...@@ -30,8 +40,9 @@ class TextgridRoot(DAVCollection):
def __init__(self, path, environ): def __init__(self, path, environ):
DAVCollection.__init__(self, path, environ) DAVCollection.__init__(self, path, environ)
self._sid = environ["wsgidav.auth.user_name"] self._sid = environ["wsgidav.auth.user_name"]
config = TextgridConfig() config = tg_config(environ)
self._auth = TextgridAuth(config) self._auth = TextgridAuth(config)
self.projects = ()
def get_display_info(self): def get_display_info(self):
return {"type": "Textgrid root collection"} return {"type": "Textgrid root collection"}
...@@ -83,7 +94,7 @@ class TextgridProject(DAVCollection): ...@@ -83,7 +94,7 @@ class TextgridProject(DAVCollection):
_logger.debug("Called TextgridProject.__init__(self, %s, environ).", path) _logger.debug("Called TextgridProject.__init__(self, %s, environ).", path)
DAVCollection.__init__(self, path, environ) DAVCollection.__init__(self, path, environ)
self._sid = environ["wsgidav.auth.user_name"] self._sid = environ["wsgidav.auth.user_name"]
config = TextgridConfig() config = tg_config(environ)
self._tgsearch = TextgridSearch(config.search) self._tgsearch = TextgridSearch(config.search)
self._project_id = self.path.split("/")[-1] self._project_id = self.path.split("/")[-1]
...@@ -175,7 +186,7 @@ class TextgridAggregation(DAVCollection): ...@@ -175,7 +186,7 @@ class TextgridAggregation(DAVCollection):
DAVCollection.__init__(self, path, environ) DAVCollection.__init__(self, path, environ)
self._sid = environ["wsgidav.auth.user_name"] self._sid = environ["wsgidav.auth.user_name"]
self._info = info self._info = info
config = TextgridConfig() config = tg_config(environ)
self._tgsearch = TextgridSearch(config.search) self._tgsearch = TextgridSearch(config.search)
self._tguri = self.path.split("/")[-1] self._tguri = self.path.split("/")[-1]
...@@ -261,7 +272,7 @@ class TextgridResource(DAVNonCollection): ...@@ -261,7 +272,7 @@ class TextgridResource(DAVNonCollection):
self._tguri = self.path.split("/")[-1] self._tguri = self.path.split("/")[-1]
self._info = info self._info = info
self.upload_thread = None self.upload_thread = None
config = TextgridConfig() config = tg_config(environ)
self._crud = TextgridCRUD(config.crud) self._crud = TextgridCRUD(config.crud)
def get_content_length(self): def get_content_length(self):
...@@ -273,7 +284,9 @@ class TextgridResource(DAVNonCollection): ...@@ -273,7 +284,9 @@ class TextgridResource(DAVNonCollection):
return self._info[self.name]["format"] return self._info[self.name]["format"]
def get_content(self): def get_content(self):
_logger.debug("Called TextgridResource.get_content(self) with path: %s", self.path) _logger.debug(
"Called TextgridResource.get_content(self) with path: %s", self.path
)
return io.BytesIO(self._crud.read_data(self._tguri, self._sid).content) return io.BytesIO(self._crud.read_data(self._tguri, self._sid).content)
def get_content_title(self): def get_content_title(self):
......
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