diff libervia/pages/files/list/page_meta.py @ 1290:ee984eefc787

pages (files/list): return empty list of files when `item-not-found` is received
author Goffi <goffi@goffi.org>
date Fri, 19 Jun 2020 16:47:51 +0200
parents c14ac2502011
children 12aa95eeb409
line wrap: on
line diff
--- a/libervia/pages/files/list/page_meta.py	Fri Jun 19 16:47:51 2020 +0200
+++ b/libervia/pages/files/list/page_meta.py	Fri Jun 19 16:47:51 2020 +0200
@@ -1,15 +1,16 @@
 #!/usr/bin/env python3
 
-
+import json
+import os
+from twisted.internet import defer
+from sat.core.i18n import _
+from sat.core.log import getLogger
+from sat.tools.common import uri
+from sat.tools.common import utils
+from sat_frontends.bridge.bridge_frontend import BridgeException
 from libervia.server.constants import Const as C
-from sat.core.i18n import _
-from twisted.internet import defer
 from libervia.server import session_iface
 from libervia.server import pages_tools
-from sat.core.log import getLogger
-from sat.tools.common import uri
-import json
-import os
 
 log = getLogger(__name__)
 """files handling pages"""
@@ -23,8 +24,7 @@
     self.getPathArgs(request, ["service", "*path"], min_args=1, service="jid", path="")
 
 
-@defer.inlineCallbacks
-def prepare_render(self, request):
+async def prepare_render(self, request):
     data = self.getRData(request)
     thumb_limit = data.get("thumb_limit", 300)
     template_data = request.template_data
@@ -32,7 +32,16 @@
     path = "/".join(path_elts)
     profile = self.getProfile(request) or C.SERVICE_PROFILE
 
-    files_data = yield self.host.bridgeCall("FISList", service.full(), path, {}, profile)
+    try:
+        files_data = await self.host.bridgeCall("FISList", service.full(), path, {}, profile)
+    except BridgeException as e:
+        if e.condition == 'item-not-found':
+            log.debug(
+                f'"item-not-found" received for {path} at {service}, this may indicate '
+                f'that the location is new')
+            files_data = []
+        else:
+            raise e
     for file_data in files_data:
         try:
             extra_raw = file_data["extra"]
@@ -64,7 +73,7 @@
                     file_data["thumb_url"] = thumb["url"]
                 elif "id" in thumb:
                     try:
-                        thumb_path = yield self.host.bridgeCall(
+                        thumb_path = await self.host.bridgeCall(
                             "bobGetFile", service.full(), thumb["id"], profile
                         )
                     except Exception as e:
@@ -98,7 +107,7 @@
             except KeyError:
                 comments_count = None
             if comments_count and data.get("retrieve_comments", False):
-                file_data["comments"] = yield pages_tools.retrieveComments(
+                file_data["comments"] = await pages_tools.retrieveComments(
                     self, comments_service, comments_node, profile=profile
                 )