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

fix(get_member): add missing tguri declaration

also, remove empty conditional branches from `TextgridCachedObjectsMixin`’s methods; replace deprecated `threading.Thread.setDaemon` with `.daemon`
parent 1e8392a6
No related branches found
No related tags found
1 merge request!33Resolve "Add caching"
Pipeline #413192 passed
......@@ -20,24 +20,22 @@ _logger = logging.getLogger(__name__)
class TextgridCachedObjectsMixin:
"""Metadata caching methods for listing projects and aggregations.
Needs a `self._cache = {}` to be present in the class
Requires `self._cache: dict` and `self._tgsearch` to be implemented in the
target class.
"""
def _get_tgobject_metadata(self, tguri, sid):
if tguri not in self._cache:
_logger.debug(f"no cache hit for {tguri}")
_logger.debug("no cache hit for %s", tguri)
response = self._tgsearch.info(tguri, sid)
self._cache_tgobject_metadata(response.result[0])
else:
_logger.debug(f"cache hit for {tguri}")
return self._cache[tguri]
def _cache_tgobject_metadata(self, metadata):
tguri = metadata.object_value.generic.generated.textgrid_uri.value
if tguri in self._cache:
_logger.debug(f"already cached: {tguri}")
else:
_logger.debug(f"storing metadata for {tguri}")
if tguri not in self._cache:
_logger.debug("storing metadata for %s", tguri)
self._cache[tguri] = metadata
......@@ -130,13 +128,6 @@ class TextgridProject(DAVCollection, TextgridCachedObjectsMixin):
def get_member_names(self):
_logger.debug("Called TextgridProject.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
response = self._tgsearch.list_project_root(self._project_id, self._sid)
names = []
for result in response.result:
......@@ -146,9 +137,10 @@ class TextgridProject(DAVCollection, TextgridCachedObjectsMixin):
def get_member(self, name):
_logger.debug("Called TextgridProject.get_member(self, %s).", name)
tguri = name
meta = self._get_tgobject_metadata(tguri, self._sid)
if meta.authorized is False:
_logger.debug(f"unauthorized: {tguri}")
_logger.debug("unauthorized: %s", tguri)
info = {
name: {
"title": "Restricted TextGrid Object",
......@@ -172,7 +164,9 @@ class TextgridProject(DAVCollection, TextgridCachedObjectsMixin):
def delete(self):
pass
def copy_move_single(self, dest_path, is_move):
def copy_move_single(
self, dest_path, is_move
): # pylint: disable=W0221:arguments-differ
pass
def support_etag(self):
......@@ -243,9 +237,10 @@ class TextgridAggregation(DAVCollection, TextgridCachedObjectsMixin):
def get_member(self, name):
_logger.debug("Called TextgridAggregation.get_member(self, %s).", name)
tguri = name
meta = self._get_tgobject_metadata(tguri, self._sid)
if meta.authorized is False:
_logger.debug(f"unauthorized: {tguri}")
_logger.debug("unauthorized: %s", tguri)
info = {
name: {
"title": "Restricted TextGrid Object",
......@@ -269,7 +264,10 @@ class TextgridAggregation(DAVCollection, TextgridCachedObjectsMixin):
def delete(self):
pass
def copy_move_single(self, dest_path, is_move):
# See [Issue](https://github.com/pylint-dev/pylint/issues/5793) why this disabled from linting.
def copy_move_single(
self, dest_path, is_move
): # pylint: disable=W0221:arguments-differ
pass
def support_etag(self):
......@@ -337,7 +335,7 @@ class TextgridResource(DAVNonCollection):
_logger.debug("Called TextgridResource.get_content_title(self).")
return self._info[self.name]["title"]
def begin_write(self, content_type=None):
def begin_write(self, content_type=None): # pylint: disable=W0221:arguments-differ
_logger.debug(
"Called TextgridResource.begin_write(self, content_type=%s).", content_type
)
......@@ -350,12 +348,12 @@ class TextgridResource(DAVNonCollection):
self._crud.update_resource(self._sid, self._tguri, queue, metadata)
thread = threading.Thread(target=worker)
thread.setDaemon(True)
thread.daemon = True
thread.start()
self.upload_thread = thread
return queue
def end_write(self, with_errors):
def end_write(self, with_errors): # pylint: disable=W0221:arguments-differ
_logger.debug(
"Called TextgridResource.end_write(self, with_errors=%s)", with_errors
)
......
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