Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_file.py @ 3013:860c550028d6
memory (sqlite): properly wait for messages to be writen in database:
the deferreds of the queries writing message to databases where not gathered and returned,
so the caller was not waiting for them to continue its workflow. This was resulting in
messages not always written when database was read just after the write (a case common
with MUC implementation), and message was appearing empty when sent to bridge.
fix 328
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 18 Jul 2019 21:58:34 +0200 |
parents | 18a98a541f7a |
children | ab2696e34d29 |
rev | line source |
---|---|
1960 | 1 #!/usr/bin/env python2 |
815 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # jp: a SAT command line tool | |
2771 | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
815 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
0 | 20 |
814 | 21 import base |
22 import sys | |
23 import os | |
24 import os.path | |
25 import tarfile | |
771 | 26 from sat.core.i18n import _ |
2932
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
27 from sat.tools.common import data_format |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
28 from sat_frontends.jp.constants import Const as C |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
29 from sat_frontends.jp import common |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
30 from sat_frontends.tools import jid |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
31 from sat.tools.common.ansi import ANSI as A |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
32 import tempfile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
33 import xml.etree.ElementTree as ET # FIXME: used temporarily to manage XMLUI |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
34 from functools import partial |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
35 import json |
402
f03688bdb858
jp: use with statement to open fifo
Goffi <goffi@goffi.org>
parents:
401
diff
changeset
|
36 |
817 | 37 __commands__ = ["File"] |
0 | 38 |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
39 |
817 | 40 class Send(base.CommandBase): |
41 def __init__(self, host): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
42 super(Send, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
43 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
44 "send", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
45 use_progress=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
46 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
47 help=_("send a file to a contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
48 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
49 self.need_loop = True |
0 | 50 |
817 | 51 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
52 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
53 "files", type=str, nargs="+", metavar="file", help=_(u"a list of file") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
54 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
55 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
56 "jid", type=base.unicode_decoder, help=_(u"the destination jid") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
57 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
58 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
59 "-b", "--bz2", action="store_true", help=_(u"make a bzip2 tarball") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
60 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
61 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
62 "-d", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
63 "--path", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
64 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
65 help=(u"path to the directory where the file must be stored"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
66 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
67 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
68 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
69 "--namespace", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
70 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
71 help=(u"namespace of the file"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
72 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
73 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
74 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
75 "--name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
76 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
77 default=u"", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
78 help=(u"name to use (DEFAULT: use source file name)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
79 ) |
0 | 80 |
1864
96ba685162f6
jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents:
1824
diff
changeset
|
81 def start(self): |
817 | 82 """Send files to jabber contact""" |
83 self.send_files() | |
401
b2caa2615c4c
jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
393
diff
changeset
|
84 |
1627
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
85 def onProgressStarted(self, metadata): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
86 self.disp(_(u"File copy started"), 2) |
1627
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
87 |
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
88 def onProgressFinished(self, metadata): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
89 self.disp(_(u"File sent successfully"), 2) |
1627
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
90 |
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
91 def onProgressError(self, error_msg): |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
92 if error_msg == C.PROGRESS_ERROR_DECLINED: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
93 self.disp(_(u"The file has been refused by your contact")) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
94 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
95 self.disp(_(u"Error while sending file: {}").format(error_msg), error=True) |
1627
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
96 |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
97 def gotId(self, data, file_): |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
98 """Called when a progress id has been received |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
99 |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
100 @param pid(unicode): progress id |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
101 @param file_(str): file path |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
102 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
103 # FIXME: this show progress only for last progress_id |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
104 self.disp(_(u"File request sent to {jid}".format(jid=self.full_dest_jid)), 1) |
1621
a17a91531fbe
jp (file): print a message and quit if progress_id is not received
Goffi <goffi@goffi.org>
parents:
1606
diff
changeset
|
105 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
106 self.progress_id = data["progress"] |
1621
a17a91531fbe
jp (file): print a message and quit if progress_id is not received
Goffi <goffi@goffi.org>
parents:
1606
diff
changeset
|
107 except KeyError: |
a17a91531fbe
jp (file): print a message and quit if progress_id is not received
Goffi <goffi@goffi.org>
parents:
1606
diff
changeset
|
108 # TODO: if 'xmlui' key is present, manage xmlui message display |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
109 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
110 _(u"Can't send file to {jid}".format(jid=self.full_dest_jid)), error=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
111 ) |
1621
a17a91531fbe
jp (file): print a message and quit if progress_id is not received
Goffi <goffi@goffi.org>
parents:
1606
diff
changeset
|
112 self.host.quit(2) |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
113 |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
114 def error(self, failure): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
115 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
116 _("Error while trying to send a file: {reason}").format(reason=failure), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
117 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
118 ) |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
119 self.host.quit(1) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
120 |
0 | 121 def send_files(self): |
817 | 122 for file_ in self.args.files: |
123 if not os.path.exists(file_): | |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
124 self.disp(_(u"file [{}] doesn't exist !").format(file_), error=True) |
817 | 125 self.host.quit(1) |
126 if not self.args.bz2 and os.path.isdir(file_): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
127 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
128 _( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
129 u"[{}] is a dir ! Please send files inside or use compression" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
130 ).format(file_) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
131 ) |
817 | 132 self.host.quit(1) |
133 | |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
134 self.full_dest_jid = self.host.get_full_jid(self.args.jid) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
135 extra = {} |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
136 if self.args.path: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
137 extra[u"path"] = self.args.path |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
138 if self.args.namespace: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
139 extra[u"namespace"] = self.args.namespace |
817 | 140 |
141 if self.args.bz2: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
142 with tempfile.NamedTemporaryFile("wb", delete=False) as buf: |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
143 self.host.addOnQuitCallback(os.unlink, buf.name) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
144 self.disp(_(u"bz2 is an experimental option, use with caution")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
145 # FIXME: check free space |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
146 self.disp(_(u"Starting compression, please wait...")) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
147 sys.stdout.flush() |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
148 bz2 = tarfile.open(mode="w:bz2", fileobj=buf) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
149 archive_name = u"{}.tar.bz2".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
150 os.path.basename(self.args.files[0]) or u"compressed_files" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
151 ) |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
152 for file_ in self.args.files: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
153 self.disp(_(u"Adding {}").format(file_), 1) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
154 bz2.add(file_) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
155 bz2.close() |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
156 self.disp(_(u"Done !"), 1) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
157 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
158 self.host.bridge.fileSend( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
159 self.full_dest_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
160 buf.name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
161 self.args.name or archive_name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
162 "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
163 extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
164 self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
165 callback=lambda pid, file_=buf.name: self.gotId(pid, file_), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
166 errback=self.error, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
167 ) |
0 | 168 else: |
817 | 169 for file_ in self.args.files: |
170 path = os.path.abspath(file_) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
171 self.host.bridge.fileSend( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
172 self.full_dest_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
173 path, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
174 self.args.name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
175 "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
176 extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
177 self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
178 callback=lambda pid, file_=file_: self.gotId(pid, file_), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
179 errback=self.error, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
180 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
181 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
182 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
183 class Request(base.CommandBase): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
184 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
185 super(Request, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
186 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
187 "request", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
188 use_progress=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
189 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
190 help=_("request a file from a contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
191 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
192 self.need_loop = True |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
193 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
194 @property |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
195 def filename(self): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
196 return self.args.name or self.args.hash or u"output" |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
197 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
198 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
199 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
200 "jid", type=base.unicode_decoder, help=_(u"the destination jid") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
201 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
202 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
203 "-D", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
204 "--dest", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
205 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
206 help=_( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
207 u"destination path where the file will be saved (default: [current_dir]/[name|hash])" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
208 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
209 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
210 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
211 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
212 "--name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
213 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
214 default=u"", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
215 help=_(u"name of the file"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
216 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
217 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
218 "-H", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
219 "--hash", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
220 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
221 default=u"", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
222 help=_(u"hash of the file"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
223 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
224 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
225 "-a", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
226 "--hash-algo", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
227 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
228 default=u"sha-256", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
229 help=_(u"hash algorithm use for --hash (default: sha-256)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
230 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
231 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
232 "-d", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
233 "--path", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
234 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
235 help=(u"path to the directory containing the file"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
236 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
237 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
238 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
239 "--namespace", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
240 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
241 help=(u"namespace of the file"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
242 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
243 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
244 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
245 "--force", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
246 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
247 help=_(u"overwrite existing file without confirmation"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
248 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
249 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
250 def onProgressStarted(self, metadata): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
251 self.disp(_(u"File copy started"), 2) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
252 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
253 def onProgressFinished(self, metadata): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
254 self.disp(_(u"File received successfully"), 2) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
255 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
256 def onProgressError(self, error_msg): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
257 if error_msg == C.PROGRESS_ERROR_DECLINED: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
258 self.disp(_(u"The file request has been refused")) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
259 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
260 self.disp(_(u"Error while requesting file: {}").format(error_msg), error=True) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
261 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
262 def gotId(self, progress_id): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
263 """Called when a progress id has been received |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
264 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
265 @param progress_id(unicode): progress id |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
266 """ |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
267 self.progress_id = progress_id |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
268 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
269 def error(self, failure): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
270 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
271 _("Error while trying to send a file: {reason}").format(reason=failure), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
272 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
273 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
274 self.host.quit(1) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
275 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
276 def start(self): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
277 if not self.args.name and not self.args.hash: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
278 self.parser.error(_(u"at least one of --name or --hash must be provided")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
279 # extra = dict(self.args.extra) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
280 if self.args.dest: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
281 path = os.path.abspath(os.path.expanduser(self.args.dest)) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
282 if os.path.isdir(path): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
283 path = os.path.join(path, self.filename) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
284 else: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
285 path = os.path.abspath(self.filename) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
286 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
287 if os.path.exists(path) and not self.args.force: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
288 message = _(u"File {path} already exists! Do you want to overwrite?").format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
289 path=path |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
290 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
291 confirm = raw_input(u"{} (y/N) ".format(message).encode("utf-8")) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
292 if confirm not in (u"y", u"Y"): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
293 self.disp(_(u"file request cancelled")) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
294 self.host.quit(2) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
295 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
296 self.full_dest_jid = self.host.get_full_jid(self.args.jid) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
297 extra = {} |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
298 if self.args.path: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
299 extra[u"path"] = self.args.path |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
300 if self.args.namespace: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
301 extra[u"namespace"] = self.args.namespace |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
302 self.host.bridge.fileJingleRequest( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
303 self.full_dest_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
304 path, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
305 self.args.name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
306 self.args.hash, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
307 self.args.hash_algo if self.args.hash else u"", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
308 extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
309 self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
310 callback=self.gotId, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
311 errback=partial( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
312 self.errback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
313 msg=_(u"can't request file: {}"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
314 exit_code=C.EXIT_BRIDGE_ERRBACK, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
315 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
316 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
317 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
318 |
817 | 319 class Receive(base.CommandAnswering): |
320 def __init__(self, host): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
321 super(Receive, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
322 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
323 "receive", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
324 use_progress=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
325 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
326 help=_("wait for a file to be sent by a contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
327 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
328 self._overwrite_refused = False # True when one overwrite as already been refused |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
329 self.action_callbacks = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
330 C.META_TYPE_FILE: self.onFileAction, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
331 C.META_TYPE_OVERWRITE: self.onOverwriteAction, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
332 } |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
333 |
1627
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
334 def onProgressStarted(self, metadata): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
335 self.disp(_(u"File copy started"), 2) |
1627
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
336 |
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
337 def onProgressFinished(self, metadata): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
338 self.disp(_(u"File received successfully"), 2) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
339 if metadata.get("hash_verified", False): |
1627
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
340 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
341 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
342 _(u"hash checked: {algo}:{checksum}").format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
343 algo=metadata["hash_algo"], checksum=metadata["hash"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
344 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
345 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
346 ) |
1627
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
347 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
348 self.disp(_(u"hash is checked but hash value is missing", 1), error=True) |
1627
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
349 else: |
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
350 self.disp(_(u"hash can't be verified"), 1) |
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
351 |
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
352 def onProgressError(self, error_msg): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
353 self.disp(_(u"Error while receiving file: {}").format(error_msg), error=True) |
1627
5a641e7b858a
jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
Goffi <goffi@goffi.org>
parents:
1621
diff
changeset
|
354 |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
355 def getXmluiId(self, action_data): |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
356 # FIXME: we temporarily use ElementTree, but a real XMLUI managing module |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
357 # should be available in the futur |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
358 # TODO: XMLUI module |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
359 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
360 xml_ui = action_data["xmlui"] |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
361 except KeyError: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
362 self.disp(_(u"Action has no XMLUI"), 1) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
363 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
364 ui = ET.fromstring(xml_ui.encode("utf-8")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
365 xmlui_id = ui.get("submit") |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
366 if not xmlui_id: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
367 self.disp(_(u"Invalid XMLUI received"), error=True) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
368 return xmlui_id |
0 | 369 |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
370 def onFileAction(self, action_data, action_id, security_limit, profile): |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
371 xmlui_id = self.getXmluiId(action_data) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
372 if xmlui_id is None: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
373 return self.host.quitFromSignal(1) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
374 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
375 from_jid = jid.JID(action_data["meta_from_jid"]) |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
376 except KeyError: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
377 self.disp(_(u"Ignoring action without from_jid data"), 1) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
378 return |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
379 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
380 progress_id = action_data["meta_progress_id"] |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
381 except KeyError: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
382 self.disp(_(u"ignoring action without progress id"), 1) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
383 return |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
384 |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
385 if not self.bare_jids or from_jid.bare in self.bare_jids: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
386 if self._overwrite_refused: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
387 self.disp(_(u"File refused because overwrite is needed"), error=True) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
388 self.host.bridge.launchAction( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
389 xmlui_id, {"cancelled": C.BOOL_TRUE}, profile_key=profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
390 ) |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
391 return self.host.quitFromSignal(2) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
392 self.progress_id = progress_id |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
393 xmlui_data = {"path": self.path} |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
394 self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
395 |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
396 def onOverwriteAction(self, action_data, action_id, security_limit, profile): |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
397 xmlui_id = self.getXmluiId(action_data) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
398 if xmlui_id is None: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
399 return self.host.quitFromSignal(1) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
400 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
401 progress_id = action_data["meta_progress_id"] |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
402 except KeyError: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
403 self.disp(_(u"ignoring action without progress id"), 1) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
404 return |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
405 self.disp(_(u"Overwriting needed"), 1) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
406 |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
407 if progress_id == self.progress_id: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
408 if self.args.force: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
409 self.disp(_(u"Overwrite accepted"), 2) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
410 else: |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
411 self.disp(_(u"Refused to overwrite"), 2) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
412 self._overwrite_refused = True |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
413 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
414 xmlui_data = {"answer": C.boolConst(self.args.force)} |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
415 self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) |
393 | 416 |
817 | 417 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
418 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
419 "jids", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
420 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
421 nargs="*", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
422 help=_(u"jids accepted (accept everything if none is specified)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
423 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
424 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
425 "-m", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
426 "--multiple", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
427 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
428 help=_(u"accept multiple files (you'll have to stop manually)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
429 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
430 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
431 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
432 "--force", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
433 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
434 help=_( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
435 u"force overwritting of existing files (/!\\ name is choosed by sender)" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
436 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
437 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
438 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
439 "--path", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
440 default=".", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
441 metavar="DIR", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
442 help=_(u"destination path (default: working directory)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
443 ) |
817 | 444 |
1864
96ba685162f6
jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents:
1824
diff
changeset
|
445 def start(self): |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
446 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids] |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
447 self.path = os.path.abspath(self.args.path) |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
448 if not os.path.isdir(self.path): |
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
449 self.disp(_(u"Given path is not a directory !", error=True)) |
1880 | 450 self.host.quit(2) |
817 | 451 if self.args.multiple: |
452 self.host.quit_on_progress_end = False | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
453 self.disp(_(u"waiting for incoming file request"), 2) |
817 | 454 |
455 | |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
456 class Upload(base.CommandBase): |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
457 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
458 super(Upload, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
459 host, "upload", use_progress=True, use_verbose=True, help=_("upload a file") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
460 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
461 self.need_loop = True |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
462 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
463 def add_parser_options(self): |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
464 self.parser.add_argument("file", type=str, help=_("file to upload")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
465 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
466 "jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
467 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
468 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
469 help=_("jid of upload component (nothing to autodetect)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
470 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
471 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
472 "--ignore-tls-errors", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
473 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
474 help=_("ignore invalide TLS certificate"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
475 ) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
476 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
477 def onProgressStarted(self, metadata): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
478 self.disp(_(u"File upload started"), 2) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
479 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
480 def onProgressFinished(self, metadata): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
481 self.disp(_(u"File uploaded successfully"), 2) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
482 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
483 url = metadata["url"] |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
484 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
485 self.disp(u"download URL not found in metadata") |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
486 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
487 self.disp(_(u"URL to retrieve the file:"), 1) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
488 # XXX: url is display alone on a line to make parsing easier |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
489 self.disp(url) |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
490 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
491 def onProgressError(self, error_msg): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
492 self.disp(_(u"Error while uploading file: {}").format(error_msg), error=True) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
493 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
494 def gotId(self, data, file_): |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
495 """Called when a progress id has been received |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
496 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
497 @param pid(unicode): progress id |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
498 @param file_(str): file path |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
499 """ |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
500 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
501 self.progress_id = data["progress"] |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
502 except KeyError: |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
503 # TODO: if 'xmlui' key is present, manage xmlui message display |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
504 self.disp(_(u"Can't upload file"), error=True) |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
505 self.host.quit(2) |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
506 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
507 def error(self, failure): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
508 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
509 _("Error while trying to upload a file: {reason}").format(reason=failure), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
510 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
511 ) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
512 self.host.quit(1) |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
513 |
1864
96ba685162f6
jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents:
1824
diff
changeset
|
514 def start(self): |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
515 file_ = self.args.file |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
516 if not os.path.exists(file_): |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
517 self.disp(_(u"file [{}] doesn't exist !").format(file_), error=True) |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
518 self.host.quit(1) |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
519 if os.path.isdir(file_): |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
520 self.disp(_(u"[{}] is a dir! Can't upload a dir").format(file_)) |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
521 self.host.quit(1) |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
522 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
523 self.full_dest_jid = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
524 self.host.get_full_jid(self.args.jid) if self.args.jid is not None else "" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
525 ) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
526 options = {} |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
527 if self.args.ignore_tls_errors: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
528 options["ignore_tls_errors"] = C.BOOL_TRUE |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
529 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
530 path = os.path.abspath(file_) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
531 self.host.bridge.fileUpload( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
532 path, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
533 "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
534 self.full_dest_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
535 options, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
536 self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
537 callback=lambda pid, file_=file_: self.gotId(pid, file_), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
538 errback=self.error, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
539 ) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
540 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
541 |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
542 class ShareList(base.CommandBase): |
817 | 543 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
544 extra_outputs = {"default": self.default_output} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
545 super(ShareList, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
546 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
547 "list", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
548 use_output=C.OUTPUT_LIST_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
549 extra_outputs=extra_outputs, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
550 help=_(u"retrieve files shared by an entity"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
551 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
552 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
553 self.need_loop = True |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
554 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
555 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
556 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
557 "-d", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
558 "--path", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
559 default=u"", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
560 help=_(u"path to the directory containing the files"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
561 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
562 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
563 "jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
564 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
565 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
566 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
567 help=_("jid of sharing entity (nothing to check our own jid)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
568 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
569 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
570 def file_gen(self, files_data): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
571 for file_data in files_data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
572 yield file_data[u"name"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
573 yield file_data.get(u"size", "") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
574 yield file_data.get(u"hash", "") |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
575 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
576 def _name_filter(self, name, row): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
577 if row.type == C.FILE_TYPE_DIRECTORY: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
578 return A.color(C.A_DIRECTORY, name) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
579 elif row.type == C.FILE_TYPE_FILE: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
580 return A.color(C.A_FILE, name) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
581 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
582 self.disp(_(u"unknown file type: {type}").format(type=row.type), error=True) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
583 return name |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
584 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
585 def _size_filter(self, size, row): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
586 if not size: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
587 return u"" |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
588 size = int(size) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
589 # cf. https://stackoverflow.com/a/1094933 (thanks) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
590 suffix = u"o" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
591 for unit in [u"", u"Ki", u"Mi", u"Gi", u"Ti", u"Pi", u"Ei", u"Zi"]: |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
592 if abs(size) < 1024.0: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
593 return A.color(A.BOLD, u"{:.2f}".format(size), unit, suffix) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
594 size /= 1024.0 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
595 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
596 return A.color(A.BOLD, u"{:.2f}".format(size), u"Yi", suffix) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
597 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
598 def default_output(self, files_data): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
599 """display files a way similar to ls""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
600 files_data.sort(key=lambda d: d["name"].lower()) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
601 show_header = False |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
602 if self.verbosity == 0: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
603 headers = (u"name", u"type") |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
604 elif self.verbosity == 1: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
605 headers = (u"name", u"type", u"size") |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
606 elif self.verbosity > 1: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
607 show_header = True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
608 headers = (u"name", u"type", u"size", u"hash") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
609 table = common.Table.fromDict( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
610 self.host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
611 files_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
612 headers, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
613 filters={u"name": self._name_filter, u"size": self._size_filter}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
614 defaults={u"size": u"", u"hash": u""}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
615 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
616 table.display_blank(show_header=show_header, hide_cols=["type"]) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
617 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
618 def _FISListCb(self, files_data): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
619 self.output(files_data) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
620 self.host.quit() |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
621 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
622 def start(self): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
623 self.host.bridge.FISList( |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
624 self.args.jid, |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
625 self.args.path, |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
626 {}, |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
627 self.profile, |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
628 callback=self._FISListCb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
629 errback=partial( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
630 self.errback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
631 msg=_(u"can't retrieve shared files: {}"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
632 exit_code=C.EXIT_BRIDGE_ERRBACK, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
633 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
634 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
635 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
636 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
637 class SharePath(base.CommandBase): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
638 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
639 super(SharePath, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
640 host, "path", help=_(u"share a file or directory"), use_verbose=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
641 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
642 self.need_loop = True |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
643 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
644 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
645 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
646 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
647 "--name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
648 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
649 default=u"", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
650 help=_(u"virtual name to use (default: use directory/file name)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
651 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
652 perm_group = self.parser.add_mutually_exclusive_group() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
653 perm_group.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
654 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
655 "--jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
656 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
657 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
658 dest="jids", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
659 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
660 help=_(u"jid of contacts allowed to retrieve the files"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
661 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
662 perm_group.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
663 "--public", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
664 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
665 help=_( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
666 u"share publicly the file(s) (/!\\ *everybody* will be able to access them)" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
667 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
668 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
669 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
670 "path", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
671 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
672 help=_(u"path to a file or directory to share"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
673 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
674 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
675 def _FISSharePathCb(self, name): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
676 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
677 _(u'{path} shared under the name "{name}"').format(path=self.path, name=name) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
678 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
679 self.host.quit() |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
680 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
681 def start(self): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
682 self.path = os.path.abspath(self.args.path) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
683 if self.args.public: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
684 access = {u"read": {u"type": u"public"}} |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
685 else: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
686 jids = self.args.jids |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
687 if jids: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
688 access = {u"read": {u"type": "whitelist", u"jids": jids}} |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
689 else: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
690 access = {} |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
691 self.host.bridge.FISSharePath( |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
692 self.args.name, |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
693 self.path, |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
694 json.dumps(access, ensure_ascii=False), |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
695 self.profile, |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
696 callback=self._FISSharePathCb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
697 errback=partial( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
698 self.errback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
699 msg=_(u"can't share path: {}"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
700 exit_code=C.EXIT_BRIDGE_ERRBACK, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
701 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
702 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
703 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
704 |
2916
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
705 class ShareInvite(base.CommandBase): |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
706 def __init__(self, host): |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
707 super(ShareInvite, self).__init__( |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
708 host, "invite", help=_(u"send invitation for a shared repository") |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
709 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
710 self.need_loop = True |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
711 |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
712 def add_parser_options(self): |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
713 self.parser.add_argument( |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
714 "-n", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
715 "--name", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
716 type=base.unicode_decoder, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
717 default=u"", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
718 help=_(u"name of the repository"), |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
719 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
720 self.parser.add_argument( |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
721 "-N", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
722 "--namespace", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
723 type=base.unicode_decoder, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
724 default=u"", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
725 help=_(u"namespace of the repository"), |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
726 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
727 self.parser.add_argument( |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
728 "-P", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
729 "--path", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
730 type=base.unicode_decoder, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
731 help=_(u"path to the repository"), |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
732 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
733 self.parser.add_argument( |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
734 "-t", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
735 "--type", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
736 choices=[u"files", u"photos"], |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
737 default=u"files", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
738 help=_(u"type of the repository"), |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
739 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
740 self.parser.add_argument( |
2932
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
741 "-T", |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
742 "--thumbnail", |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
743 type=base.unicode_decoder, |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
744 help=_(u"https URL of a image to use as thumbnail"), |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
745 ) |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
746 self.parser.add_argument( |
2916
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
747 "service", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
748 type=base.unicode_decoder, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
749 help=_(u"jid of the file sharing service hosting the repository"), |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
750 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
751 self.parser.add_argument( |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
752 "jid", |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
753 type=base.unicode_decoder, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
754 help=_(u"jid of the person to invite"), |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
755 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
756 |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
757 def _FISInviteCb(self): |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
758 self.disp( |
2939
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2932
diff
changeset
|
759 _(u'invitation sent to {entity}').format(entity=self.args.jid) |
2916
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
760 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
761 self.host.quit() |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
762 |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
763 def start(self): |
2932
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
764 self.path = os.path.normpath(self.args.path) if self.args.path else u"" |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
765 extra = {} |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
766 if self.args.thumbnail is not None: |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
767 if not self.args.thumbnail.startswith(u'http'): |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
768 self.parser.error(_(u"only http(s) links are allowed with --thumbnail")) |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
769 else: |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
770 extra[u'thumb_url'] = self.args.thumbnail |
2916
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
771 self.host.bridge.FISInvite( |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
772 self.args.jid, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
773 self.args.service, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
774 self.args.type, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
775 self.args.namespace, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
776 self.path, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
777 self.args.name, |
2932
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
778 data_format.serialise(extra), |
2916
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
779 self.profile, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
780 callback=self._FISInviteCb, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
781 errback=partial( |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
782 self.errback, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
783 msg=_(u"can't send invitation: {}"), |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
784 exit_code=C.EXIT_BRIDGE_ERRBACK, |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
785 ), |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
786 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
787 |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
788 |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
789 class Share(base.CommandBase): |
2916
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
790 subcommands = (ShareList, SharePath, ShareInvite) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
791 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
792 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
793 super(Share, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
794 host, "share", use_profile=False, help=_(u"files sharing management") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
795 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
796 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
797 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
798 class File(base.CommandBase): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
799 subcommands = (Send, Request, Receive, Upload, Share) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
800 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
801 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
802 super(File, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
803 host, "file", use_profile=False, help=_(u"files sending/receiving/management") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
804 ) |