comparison libervia/pages/files/view/page_meta.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/pages/files/view/page_meta.py@cdd389ef97bc
children 29eb15062416
comparison
equal deleted inserted replaced
1123:63a4b8fe9782 1124:28e3eb3bb217
1 #!/usr/bin/env python2.7
2 # -*- coding: utf-8 -*-
3
4 from libervia.server.constants import Const as C
5 from sat.core.i18n import _
6 from twisted.internet import defer
7 from twisted.web import static
8 from libervia.server.utils import ProgressHandler
9 import tempfile
10 import os
11 import os.path
12 from sat.core.log import getLogger
13
14 log = getLogger("pages/files/view")
15 """files handling pages"""
16
17 name = u"files_view"
18 access = C.PAGES_ACCESS_PROFILE
19
20
21 def parse_url(self, request):
22 self.getPathArgs(request, ["service", "*path"], min_args=2, service="jid", path="")
23
24
25 def cleanup(dummy, tmp_dir, dest_path):
26 try:
27 os.unlink(dest_path)
28 except OSError:
29 log.warning(_(u"Can't remove temporary file {path}").format(path=dest_path))
30 try:
31 os.rmdir(tmp_dir)
32 except OSError:
33 log.warning(_(u"Can't remove temporary directory {path}").format(path=tmp_dir))
34
35
36 @defer.inlineCallbacks
37 def render(self, request):
38 data = self.getRData(request)
39 profile = self.getProfile(request)
40 service, path_elts = data[u"service"], data[u"path"]
41 basename = path_elts[-1]
42 dir_elts = path_elts[:-1]
43 dir_path = u"/".join(dir_elts)
44 tmp_dir = tempfile.mkdtemp()
45 dest_path = os.path.join(tmp_dir, basename)
46 request.notifyFinish().addCallback(cleanup, tmp_dir, dest_path)
47 progress_id = yield self.host.bridgeCall(
48 "fileJingleRequest",
49 service.full(),
50 dest_path,
51 basename,
52 u"",
53 u"",
54 {u"path": dir_path},
55 profile,
56 )
57 log.debug(u"file requested")
58 yield ProgressHandler(self.host, progress_id, profile).register()
59 log.debug(u"file downloaded")
60 self.delegateToResource(request, static.File(dest_path))