annotate src/plugins/plugin_comp_file_sharing.py @ 2504:67cc54b01a12

plugin file sharing component: first draft: this component act as an endpoint where a user can store and retrieve its files using Jingle.
author Goffi <goffi@goffi.org>
date Wed, 28 Feb 2018 18:28:39 +0100
parents
children 4440ea7047bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2504
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for parrot mode (experimental)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.i18n import _
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.constants import Const as C
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core import exceptions
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.log import getLogger
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 log = getLogger(__name__)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.tools.common import regex
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.tools import stream
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.internet import defer
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import os
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import os.path
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 PLUGIN_INFO = {
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 C.PI_NAME: "File sharing component",
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 C.PI_IMPORT_NAME: "file_sharing",
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 C.PI_MODES: [C.PLUG_MODE_COMPONENT],
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_TYPE: C.PLUG_TYPE_ENTRY_POINT,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 C.PI_PROTOCOLS: [],
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_DEPENDENCIES: ["FILE", "XEP-0234", "XEP-0260", "XEP-0261", "XEP-0329"],
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_RECOMMENDATIONS: [],
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_MAIN: "FileSharing",
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_HANDLER: "no",
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_DESCRIPTION: _(u"""Component hosting and sharing files""")
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 }
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 PROGRESS_ID_KEY = 'progress_id'
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 HASH_ALGO = u'sha-256'
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 class FileSharing(object):
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 def __init__(self, host):
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 log.info(_(u"File Sharing initialization"))
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.host = host
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self._f = host.plugins['FILE']
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self._jf = host.plugins['XEP-0234']
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self._h = host.plugins['XEP-0300']
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 host.trigger.add("FILE_getDestDir", self._getDestDirTrigger)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 host.trigger.add("XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger, priority=1000)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.files_path = host.getLocalPath(None, C.FILES_DIR, profile=False)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 def profileConnected(self, client):
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 path = client.file_tmp_dir = os.path.join(
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 self.host.memory.getConfig('', 'local_dir'),
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 C.FILES_TMP_DIR,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 regex.pathEscape(client.profile))
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 if not os.path.exists(path):
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 os.makedirs(path)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 @defer.inlineCallbacks
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def _fileTransferedCb(self, dummy, client, peer_jid, file_data, file_path):
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 if file_data[u'hash_algo'] == HASH_ALGO:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 log.debug(_(u"Reusing already generated hash"))
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 file_hash = file_data[u'hash_hasher'].hexdigest()
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 else:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 hasher = self._h.getHasher(HASH_ALGO)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 with open('file_path') as f:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 file_hash = yield self._h.calculateHash(f, hasher)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 final_path = os.path.join(self.files_path, file_hash)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 if os.path.isfile(final_path):
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 log.debug(u"file [{file_hash}] already exists, we can remove temporary one".format(file_hash = file_hash))
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 os.unlink(file_path)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 else:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 os.rename(file_path, final_path)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 log.debug(u"file [{file_hash}] moved to {files_path}".format(file_hash=file_hash, files_path=self.files_path))
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self.host.memory.setFile(client,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 name=file_data[u'name'],
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 version=u'',
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 file_hash=file_hash,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 hash_algo=HASH_ALGO,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 size=file_data[u'size'],
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 path=file_data.get(u'path'),
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 namespace=file_data.get(u'namespace'),
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 owner=peer_jid)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
94
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def _getDestDirTrigger(self, client, peer_jid, transfer_data, file_data, stream_object):
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 if not client.is_component:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 return True, None
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 assert stream_object
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 assert 'stream_object' not in transfer_data
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 assert PROGRESS_ID_KEY in file_data
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 filename = file_data['name']
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 assert filename and not '/' in filename
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 file_tmp_dir = self.host.getLocalPath(client, C.FILES_TMP_DIR, peer_jid.userhost(), component=True, profile=False)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 file_tmp_path = file_data['file_path'] = os.path.join(file_tmp_dir, file_data['name'])
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 transfer_data['finished_d'].addCallback(self._fileTransferedCb, client, peer_jid, file_data, file_tmp_path)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
107
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self._f.openFileWrite(client, file_tmp_path, transfer_data, file_data, stream_object)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 return False, defer.succeed(True)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 @defer.inlineCallbacks
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 def _retrieveFiles(self, client, session, content_data, content_name, file_data, file_elt):
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 peer_jid = session[u'peer_jid']
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 try:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 found_files = yield self.host.memory.getFiles(client,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 peer_jid=peer_jid,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 name=file_data.get(u'name'),
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 file_hash=file_data.get(u'hash'),
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 hash_algo=file_data.get(u'hash_algo'),
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 path=file_data.get(u'path'),
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 namespace=file_data.get(u'namespace'))
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 except exceptions.NotFound:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 found_files = None
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 except exceptions.PermissionError:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 log.warning(_(u"{peer_jid} is trying to access an unauthorized file: {name}").format(
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 peer_jid=peer_jid, name=file_data.get(u'name')))
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 defer.returnValue(False)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 if not found_files:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 log.warning(_(u"no matching file found ({file_data})").format(file_data=file_data))
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 defer.returnValue(False)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 # we only use the first found file
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 found_file = found_files[0]
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 file_hash = found_file[u'hash']
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 file_path = os.path.join(self.files_path, file_hash)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 file_data[u'hash_hasher'] = hasher = self._h.getHasher(found_file[u'hash_algo'])
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 size = file_data[u'size'] = found_file[u'size']
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 file_data[u'file_hash'] = file_hash
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 file_data[u'hash_algo'] = found_file[u'hash_algo']
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 # we complete file_elt so peer can have some details on the file
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 if u'name' not in file_data:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 file_elt.addElement(u'name', content=found_file[u'name'])
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 file_elt.addElement(u'size', content=unicode(size))
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 content_data['stream_object'] = stream.FileStreamObject(
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 self.host,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 client,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 file_path,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 uid=self._jf.getProgressId(session, content_name),
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 size=size,
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 data_cb=lambda data: hasher.update(data),
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 )
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 defer.returnValue(True)
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
155
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 def _fileSendingRequestTrigger(self, client, session, content_data, content_name, file_data, file_elt):
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 if not client.is_component:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 return True, None
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 else:
67cc54b01a12 plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 return False, self._retrieveFiles(client, session, content_data, content_name, file_data, file_elt)