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

fix(dav-provider): use TextgridSearch from tgclients lib instead of own tgapi module

refactor TextgridProject, TextgridAggregation accordingly

close #20
parent 61644a05
No related branches found
No related tags found
1 merge request!11Resolve "use tgsearch from tgclients lib"
...@@ -8,13 +8,12 @@ from pprint import pformat ...@@ -8,13 +8,12 @@ from pprint import pformat
from tgclients.auth import TextgridAuth from tgclients.auth import TextgridAuth
from tgclients.config import TextgridConfig from tgclients.config import TextgridConfig
from tgclients.crud import TextgridCRUD from tgclients.crud import TextgridCRUD
from tgclients.search import TextgridSearch
from wsgidav.dav_provider import DAVCollection, DAVNonCollection, DAVProvider from wsgidav.dav_provider import DAVCollection, DAVNonCollection, DAVProvider
from wsgidav.util import join_uri, pop_path from wsgidav.util import join_uri, pop_path
from repdav.stream_tools import FileLikeQueue from repdav.stream_tools import FileLikeQueue
from .tgapi import TextgridSearch
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
...@@ -80,6 +79,8 @@ class TextgridProject(DAVCollection): ...@@ -80,6 +79,8 @@ 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"]
self._tgconfig = TextgridConfig()
self._tgsearch = TextgridSearch(self._tgconfig.search)
def create_empty_resource(self, name): def create_empty_resource(self, name):
pass pass
...@@ -99,14 +100,22 @@ class TextgridProject(DAVCollection): ...@@ -99,14 +100,22 @@ class TextgridProject(DAVCollection):
# return names # return names
# #
# path resolution has to be rewritten before we can work with resource titles # path resolution has to be rewritten before we can work with resource titles
resources = TextgridSearch().get_project_contents( response = self._tgsearch.list_project_root(self.path.split("/")[-1], self._sid)
self._sid, self.path.split("/")[-1] names = []
) for result in response.result:
return resources.keys() names.append(result.object_value.generic.generated.textgrid_uri.value)
return names
def get_member(self, name): def get_member(self, name):
_logger.debug("Called TextgridProject.get_member(self, %s).", name) _logger.debug("Called TextgridProject.get_member(self, %s).", name)
info = TextgridSearch().info(self._sid, name) response = self._tgsearch.info(name, self._sid)
info = {
name: {
"title": response.result[0].object_value.generic.provided.title,
"format": response.result[0].object_value.generic.provided.format,
"extent": response.result[0].object_value.generic.generated.extent,
}
}
_logger.info("INFO: %s", info) _logger.info("INFO: %s", info)
if "aggregation" in info[name]["format"]: if "aggregation" in info[name]["format"]:
return TextgridAggregation(join_uri(self.path, name), self.environ, info) return TextgridAggregation(join_uri(self.path, name), self.environ, info)
...@@ -161,6 +170,8 @@ class TextgridAggregation(DAVCollection): ...@@ -161,6 +170,8 @@ 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
self._tgconfig = TextgridConfig()
self._tgsearch = TextgridSearch(self._tgconfig.search)
def create_empty_resource(self, name): def create_empty_resource(self, name):
pass pass
...@@ -173,15 +184,22 @@ class TextgridAggregation(DAVCollection): ...@@ -173,15 +184,22 @@ class TextgridAggregation(DAVCollection):
def get_member_names(self): def get_member_names(self):
_logger.debug("Called TextgridAggregation.get_member_names(self).") _logger.debug("Called TextgridAggregation.get_member_names(self).")
resources = TextgridSearch().get_aggregation_contents( response = self._tgsearch.list_aggregation(self.path.split("/")[-1], self._sid)
self._sid, self.path.split("/")[-1] names = []
) for result in response.result:
# _logger.debug("RESOURCES: %s", resources) names.append(result.object_value.generic.generated.textgrid_uri.value)
return resources.keys() return names
def get_member(self, name): def get_member(self, name):
_logger.debug("Called TextgridAggregation.get_member(self, %s).", name) _logger.debug("Called TextgridAggregation.get_member(self, %s).", name)
info = TextgridSearch().info(self._sid, name) response = self._tgsearch.info(name, self._sid)
info = {
name: {
"title": response.result[0].object_value.generic.provided.title,
"format": response.result[0].object_value.generic.provided.format,
"extent": response.result[0].object_value.generic.generated.extent,
}
}
_logger.info("INFO: %s", info) _logger.info("INFO: %s", info)
if "aggregation" in info[name]["format"]: if "aggregation" in info[name]["format"]:
return TextgridAggregation(join_uri(self.path, name), self.environ, info) return TextgridAggregation(join_uri(self.path, name), self.environ, info)
...@@ -260,7 +278,7 @@ class TextgridResource(DAVNonCollection): ...@@ -260,7 +278,7 @@ class TextgridResource(DAVNonCollection):
) )
queue = FileLikeQueue(int(self._size)) queue = FileLikeQueue(int(self._size))
config = TextgridConfig("http://textgridlab.org/") config = TextgridConfig()
crud = TextgridCRUD(config.crud) crud = TextgridCRUD(config.crud)
metadata = crud.read_metadata(self.path.split("/")[-1], self._sid).content metadata = crud.read_metadata(self.path.split("/")[-1], self._sid).content
......
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