annotate sat/plugins/plugin_misc_file.py @ 2908:695fc440c3b8

plugins: removed useless execute permission
author Goffi <goffi@goffi.org>
date Sun, 14 Apr 2019 08:21:51 +0200
parents 003b8b4b56a7
children ab2696e34d29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for file tansfer
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
20 from sat.core.i18n import _, D_
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.constants import Const as C
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
23
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 log = getLogger(__name__)
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
25 from sat.core import exceptions
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
26 from sat.tools import xml_tools
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
27 from sat.tools import stream
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
28 from twisted.internet import defer
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
29 from twisted.words.protocols.jabber import jid
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 import os
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
31 import os.path
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
35 C.PI_NAME: "File Tansfer",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
36 C.PI_IMPORT_NAME: "FILE",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
37 C.PI_TYPE: C.PLUG_TYPE_MISC,
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
38 C.PI_MODES: C.PLUG_MODE_BOTH,
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
39 C.PI_MAIN: "FilePlugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
40 C.PI_HANDLER: "no",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 C.PI_DESCRIPTION: _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42 """File Tansfer Management:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 This plugin manage the various ways of sending a file, and choose the best one."""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
44 ),
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 }
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 SENDING = D_(u"Please select a file to send to {peer}")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 SENDING_TITLE = D_(u"File sending")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 CONFIRM = D_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 u'{peer} wants to send the file "{name}" to you:\n{desc}\n\nThe file has a size of {size_human}\n\nDo you accept ?'
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 CONFIRM_TITLE = D_(u"Confirm file transfer")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 CONFIRM_OVERWRITE = D_(u"File {} already exists, are you sure you want to overwrite ?")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 CONFIRM_OVERWRITE_TITLE = D_(u"File exists")
1647
31b96ac3eec2 core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents: 1646
diff changeset
56 SECURITY_LIMIT = 30
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
57
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 PROGRESS_ID_KEY = "progress_id"
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
59
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
60
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 class FilePlugin(object):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 File = stream.SatFile
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 def __init__(self, host):
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 log.info(_("plugin File initialization"))
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.host = host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 "fileSend",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 in_sign="ssssa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 out_sign="a{ss}",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 method=self._fileSend,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 )
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
75 self._file_callbacks = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 host.importMenu(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 (D_("Action"), D_("send file")),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 self._fileSendMenu,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 security_limit=10,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 help_string=D_("Send a file"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 type_=C.MENU_SINGLE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 )
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
83
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 def _fileSend(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 peer_jid_s,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 filepath,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 name="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 file_desc="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 extra=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 profile=C.PROF_KEY_NONE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 ):
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
93 client = self.host.getClient(profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 return self.fileSend(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 client, jid.JID(peer_jid_s), filepath, name or None, file_desc or None, extra
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 )
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
97
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
98 @defer.inlineCallbacks
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 def fileSend(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 self, client, peer_jid, filepath, filename=None, file_desc=None, extra=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 ):
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
102 """Send a file using best available method
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
103
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
104 @param peer_jid(jid.JID): jid of the destinee
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
105 @param filepath(str): absolute path to the file
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
106 @param filename(unicode, None): name to use, or None to find it from filepath
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
107 @param file_desc(unicode, None): description of the file
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
108 @param profile: %(doc_profile)s
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
109 @return (dict): action dictionary, with progress id in case of success, else xmlui message
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
110 """
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
111 if not os.path.isfile(filepath):
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
112 raise exceptions.DataError(u"The given path doesn't link to a file")
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
113 if not filename:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 filename = os.path.basename(filepath) or "_"
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
115 for namespace, callback, priority, method_name in self._file_callbacks:
2148
a543eda2c923 core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
116 has_feature = yield self.host.hasFeature(client, namespace, peer_jid)
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
117 if has_feature:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
119 u"{name} method will be used to send the file".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 name=method_name
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 progress_id = yield callback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 client, peer_jid, filepath, filename, file_desc, extra
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 defer.returnValue({"progress": progress_id})
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
127 msg = u"Can't find any method to send file to {jid}".format(jid=peer_jid.full())
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
128 log.warning(msg)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 defer.returnValue(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 "xmlui": xml_tools.note(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 u"Can't transfer file", msg, C.XMLUI_DATA_LVL_WARNING
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
133 ).toXml()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 )
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
136
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
137 def _onFileChoosed(self, client, peer_jid, data):
1635
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
138 cancelled = C.bool(data.get("cancelled", C.BOOL_FALSE))
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
139 if cancelled:
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
140 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 path = data["path"]
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
142 return self.fileSend(client, peer_jid, path)
1635
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
143
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
144 def _fileSendMenu(self, data, profile):
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
145 """ XMLUI activated by menu: return file sending UI
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
146
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
147 @param profile: %(doc_profile)s
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
148 """
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
149 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 jid_ = jid.JID(data["jid"])
1635
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
151 except RuntimeError:
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
152 raise exceptions.DataError(_("Invalid JID"))
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
153
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
154 file_choosed_id = self.host.registerCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
155 lambda data, profile: self._onFileChoosed(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 self.host.getClient(profile), jid_, data
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
157 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 with_data=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 one_shot=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 )
1635
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
161 xml_ui = xml_tools.XMLUI(
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
162 C.XMLUI_DIALOG,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 dialog_opt={
1635
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
164 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_FILE,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
165 C.XMLUI_DATA_MESS: _(SENDING).format(peer=jid_.full()),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
166 },
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 title=_(SENDING_TITLE),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 submit_id=file_choosed_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 )
1635
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
170
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 return {"xmlui": xml_ui.toXml()}
1635
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
172
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
173 def register(self, namespace, callback, priority=0, method_name=None):
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
174 """Register a fileSending method
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
175
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
176 @param namespace(unicode): XEP namespace
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
177 @param callback(callable): method to call (must have the same signature as [fileSend])
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
178 @param priority(int): pririoty of this method, the higher available will be used
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
179 @param method_name(unicode): short name for the method, namespace will be used if None
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
180 """
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
181 for data in self._file_callbacks:
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
182 if namespace == data[0]:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
183 raise exceptions.ConflictError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 u"A method with this namespace is already registered"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
185 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
186 self._file_callbacks.append(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 (namespace, callback, priority, method_name or namespace)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
188 )
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
189 self._file_callbacks.sort(key=lambda data: data[2], reverse=True)
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
190
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
191 def unregister(self, namespace):
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
192 for idx, data in enumerate(self._file_callbacks):
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
193 if data[0] == namespace:
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
194 del [idx]
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
195 return
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
196 raise exceptions.NotFound(u"The namespace to unregister doesn't exist")
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
197
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
198 # Dialogs with user
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
199 # the overwrite check is done here
1525
49d33cb48207 plugin file: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
200
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
201 def openFileWrite(self, client, file_path, transfer_data, file_data, stream_object):
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
202 """create SatFile or FileStremaObject for the requested file and fill suitable data
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
203 """
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
204 if stream_object:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
205 assert "stream_object" not in transfer_data
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
206 transfer_data["stream_object"] = stream.FileStreamObject(
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
207 self.host,
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
208 client,
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
209 file_path,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 mode="wb",
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
211 uid=file_data[PROGRESS_ID_KEY],
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 size=file_data["size"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
213 data_cb=file_data.get("data_cb"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
214 )
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
215 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
216 assert "file_obj" not in transfer_data
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
217 transfer_data["file_obj"] = stream.SatFile(
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
218 self.host,
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
219 client,
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
220 file_path,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
221 mode="wb",
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
222 uid=file_data[PROGRESS_ID_KEY],
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
223 size=file_data["size"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
224 data_cb=file_data.get("data_cb"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
225 )
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
226
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
227 def _gotConfirmation(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 self, data, client, peer_jid, transfer_data, file_data, stream_object
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
229 ):
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
230 """Called when the permission and dest path have been received
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
231
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
232 @param peer_jid(jid.JID): jid of the file sender
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
233 @param transfer_data(dict): same as for [self.getDestDir]
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
234 @param file_data(dict): same as for [self.getDestDir]
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
235 @param stream_object(bool): same as for [self.getDestDir]
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
236 return (bool): True if copy is wanted and OK
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
237 False if user wants to cancel
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
238 if file exists ask confirmation and call again self._getDestDir if needed
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
239 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
240 if data.get("cancelled", False):
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
241 return False
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
242 path = data["path"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
243 file_data["file_path"] = file_path = os.path.join(path, file_data["name"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
244 log.debug(u"destination file path set to {}".format(file_path))
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
245
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
246 # we manage case where file already exists
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
247 if os.path.exists(file_path):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
248
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
249 def check_overwrite(overwrite):
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
250 if overwrite:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
251 self.openFileWrite(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
252 client, file_path, transfer_data, file_data, stream_object
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
253 )
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
254 return True
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
255 else:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
256 return self.getDestDir(client, peer_jid, transfer_data, file_data)
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
257
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
258 exists_d = xml_tools.deferConfirm(
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
259 self.host,
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
260 _(CONFIRM_OVERWRITE).format(file_path),
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
261 _(CONFIRM_OVERWRITE_TITLE),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
262 action_extra={
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
263 "meta_from_jid": peer_jid.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
264 "meta_type": C.META_TYPE_OVERWRITE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
265 "meta_progress_id": file_data[PROGRESS_ID_KEY],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
266 },
1646
7f0c8856e4e1 plugin file: deferred XMLUI now use security limit
Goffi <goffi@goffi.org>
parents: 1639
diff changeset
267 security_limit=SECURITY_LIMIT,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
268 profile=client.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
269 )
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
270 exists_d.addCallback(check_overwrite)
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
271 return exists_d
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
272
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
273 self.openFileWrite(client, file_path, transfer_data, file_data, stream_object)
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
274 return True
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
275
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
276 def getDestDir(self, client, peer_jid, transfer_data, file_data, stream_object=False):
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
277 """Request confirmation and destination dir to user
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
278
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
279 Overwrite confirmation is managed.
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
280 if transfer is confirmed, 'file_obj' is added to transfer_data
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
281 @param peer_jid(jid.JID): jid of the file sender
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
282 @param filename(unicode): name of the file
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
283 @param transfer_data(dict): data of the transfer session,
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
284 it will be only used to store the file_obj.
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
285 "file_obj" (or "stream_object") key *MUST NOT* exist before using getDestDir
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
286 @param file_data(dict): information about the file to be transfered
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
287 It MUST contain the following keys:
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
288 - peer_jid (jid.JID): other peer jid
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
289 - name (unicode): name of the file to trasnsfer
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
290 the name must not be empty or contain a "/" character
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
291 - size (int): size of the file
1619
3ec7511dbf28 plugin file: 'data_cb' key can be used in file_data to specified a callback used on each read/write
Goffi <goffi@goffi.org>
parents: 1607
diff changeset
292 - desc (unicode): description of the file
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
293 - progress_id (unicode): id to use for progression
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
294 It *MUST NOT* contain the "peer" key
1619
3ec7511dbf28 plugin file: 'data_cb' key can be used in file_data to specified a callback used on each read/write
Goffi <goffi@goffi.org>
parents: 1607
diff changeset
295 It may contain:
3ec7511dbf28 plugin file: 'data_cb' key can be used in file_data to specified a callback used on each read/write
Goffi <goffi@goffi.org>
parents: 1607
diff changeset
296 - data_cb (callable): method called on each data read/write
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
297 "file_path" will be added to this dict once destination selected
1575
833bdb227b16 plugins XEP-0234, file: moved human file size conversion to file plugi
Goffi <goffi@goffi.org>
parents: 1574
diff changeset
298 "size_human" will also be added with human readable file size
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
299 @param stream_object(bool): if True, a stream_object will be used instead of file_obj
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
300 a stream.FileStreamObject will be used
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
301 return (defer.Deferred): True if transfer is accepted
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
302 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 cont, ret_value = self.host.trigger.returnPoint(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 "FILE_getDestDir", client, peer_jid, transfer_data, file_data, stream_object
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
305 )
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
306 if not cont:
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
307 return ret_value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
308 filename = file_data["name"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
309 assert filename and not "/" in filename
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1575
diff changeset
310 assert PROGRESS_ID_KEY in file_data
1575
833bdb227b16 plugins XEP-0234, file: moved human file size conversion to file plugi
Goffi <goffi@goffi.org>
parents: 1574
diff changeset
311 # human readable size
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
312 file_data["size_human"] = u"{:.6n} Mio".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
313 float(file_data["size"]) / (1024 ** 2)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
314 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
315 d = xml_tools.deferDialog(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
316 self.host,
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
317 _(CONFIRM).format(peer=peer_jid.full(), **file_data),
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
318 _(CONFIRM_TITLE),
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
319 type_=C.XMLUI_DIALOG_FILE,
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
320 options={C.XMLUI_DATA_FILETYPE: C.XMLUI_DATA_FILETYPE_DIR},
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
321 action_extra={
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
322 "meta_from_jid": peer_jid.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
323 "meta_type": C.META_TYPE_FILE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
324 "meta_progress_id": file_data[PROGRESS_ID_KEY],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
325 },
1646
7f0c8856e4e1 plugin file: deferred XMLUI now use security limit
Goffi <goffi@goffi.org>
parents: 1639
diff changeset
326 security_limit=SECURITY_LIMIT,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
327 profile=client.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
328 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
329 d.addCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
330 self._gotConfirmation,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
331 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
332 peer_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
333 transfer_data,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
334 file_data,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
335 stream_object,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
336 )
1574
babd97d80049 plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents: 1568
diff changeset
337 return d