comparison libervia/pages/files/view/page_meta.py @ 1421:e065c8886b81

pages (files/list): set empty affiliations when they can't be retrieved
author Goffi <goffi@goffi.org>
date Sat, 01 May 2021 19:04:25 +0200
parents f511f8fbbf8a
children 106bae41f5c8
comparison
equal deleted inserted replaced
1420:925a7c498cda 1421:e065c8886b81
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 3
4 from libervia.server.constants import Const as C 4 from libervia.server.constants import Const as C
5 from sat.core.i18n import _ 5 from sat.core.i18n import _
6 from twisted.internet import defer
7 from twisted.web import static 6 from twisted.web import static
8 from libervia.server.utils import ProgressHandler 7 from libervia.server.utils import ProgressHandler
9 import tempfile 8 import tempfile
10 import os 9 import os
11 import os.path 10 import os.path
31 os.rmdir(tmp_dir) 30 os.rmdir(tmp_dir)
32 except OSError: 31 except OSError:
33 log.warning(_("Can't remove temporary directory {path}").format(path=tmp_dir)) 32 log.warning(_("Can't remove temporary directory {path}").format(path=tmp_dir))
34 33
35 34
36 @defer.inlineCallbacks 35 async def render(self, request):
37 def render(self, request):
38 data = self.getRData(request) 36 data = self.getRData(request)
39 profile = self.getProfile(request) 37 profile = self.getProfile(request)
40 service, path_elts = data["service"], data["path"] 38 service, path_elts = data["service"], data["path"]
41 basename = path_elts[-1] 39 basename = path_elts[-1]
42 dir_elts = path_elts[:-1] 40 dir_elts = path_elts[:-1]
43 dir_path = "/".join(dir_elts) 41 dir_path = "/".join(dir_elts)
44 tmp_dir = tempfile.mkdtemp() 42 tmp_dir = tempfile.mkdtemp()
45 dest_path = os.path.join(tmp_dir, basename) 43 dest_path = os.path.join(tmp_dir, basename)
46 request.notifyFinish().addCallback(cleanup, tmp_dir, dest_path) 44 request.notifyFinish().addCallback(cleanup, tmp_dir, dest_path)
47 progress_id = yield self.host.bridgeCall( 45 progress_id = await self.host.bridgeCall(
48 "fileJingleRequest", 46 "fileJingleRequest",
49 service.full(), 47 service.full(),
50 dest_path, 48 dest_path,
51 basename, 49 basename,
52 "", 50 "",
53 "", 51 "",
54 {"path": dir_path}, 52 {"path": dir_path},
55 profile, 53 profile,
56 ) 54 )
57 log.debug("file requested") 55 log.debug("file requested")
58 yield ProgressHandler(self.host, progress_id, profile).register() 56 await ProgressHandler(self.host, progress_id, profile).register()
59 log.debug("file downloaded") 57 log.debug("file downloaded")
60 self.delegateToResource(request, static.File(dest_path)) 58 self.delegateToResource(request, static.File(dest_path))