Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_file.py @ 4015:2913313ca58f
component AP gateway (http): add verbose log when signature verification fails on POST request
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 18 Mar 2023 20:12:38 +0100 |
parents | 4c3361e2bf55 |
children | 524856bd7b19 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
815 | 3 |
4 # jp: a SAT command line tool | |
3479 | 5 # Copyright (C) 2009-2021 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 |
3028 | 21 from . import base |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
22 from . import xmlui_manager |
814 | 23 import sys |
24 import os | |
25 import os.path | |
26 import tarfile | |
771 | 27 from sat.core.i18n import _ |
2932
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
28 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
|
29 from sat_frontends.jp.constants import Const as C |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
30 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
|
31 from sat_frontends.tools import jid |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
32 from sat.tools.common.ansi import ANSI as A |
3524
584379473925
tools (common/utils): new methods to parse and generate file size with symbols:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
33 from sat.tools.common import utils |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
34 from urllib.parse import urlparse |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
35 from pathlib import Path |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
36 import tempfile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
37 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
|
38 import json |
402
f03688bdb858
jp: use with statement to open fifo
Goffi <goffi@goffi.org>
parents:
401
diff
changeset
|
39 |
817 | 40 __commands__ = ["File"] |
3926
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
41 DEFAULT_DEST = "downloaded_file" |
0 | 42 |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
43 |
817 | 44 class Send(base.CommandBase): |
45 def __init__(self, host): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
46 super(Send, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
47 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
48 "send", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
49 use_progress=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
50 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
51 help=_("send a file to a contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
52 ) |
0 | 53 |
817 | 54 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
55 self.parser.add_argument( |
3028 | 56 "files", type=str, nargs="+", metavar="file", help=_("a list of file") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
57 ) |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
58 self.parser.add_argument("jid", help=_("the destination jid")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
59 self.parser.add_argument( |
3028 | 60 "-b", "--bz2", action="store_true", help=_("make a bzip2 tarball") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
61 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
62 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
63 "-d", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
64 "--path", |
3028 | 65 help=("path to the directory where the file must be stored"), |
2624
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", |
3028 | 70 help=("namespace of the file"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
71 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
72 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
73 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
74 "--name", |
3028 | 75 default="", |
76 help=("name to use (DEFAULT: use source file name)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
77 ) |
3970
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
78 self.parser.add_argument( |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
79 "-e", |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
80 "--encrypt", |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
81 action="store_true", |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
82 help=_("end-to-end encrypt the file transfer") |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
83 ) |
0 | 84 |
3040 | 85 async def onProgressStarted(self, metadata): |
3028 | 86 self.disp(_("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 |
3040 | 88 async def onProgressFinished(self, metadata): |
3028 | 89 self.disp(_("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 |
3040 | 91 async 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: |
3028 | 93 self.disp(_("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: |
3028 | 95 self.disp(_("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 |
3040 | 97 async def gotId(self, data, file_): |
1606
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 |
3408
19bc03743aeb
jp (file/send): don't add main resource to bare jid anymore:
Goffi <goffi@goffi.org>
parents:
3325
diff
changeset
|
104 self.disp(_("File request sent to {jid}".format(jid=self.args.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: |
3040 | 106 await self.set_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 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
109 self.disp(_("Can't send file to {jid}".format(jid=self.args.jid)), error=True) |
1621
a17a91531fbe
jp (file): print a message and quit if progress_id is not received
Goffi <goffi@goffi.org>
parents:
1606
diff
changeset
|
110 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
|
111 |
3040 | 112 async def start(self): |
817 | 113 for file_ in self.args.files: |
114 if not os.path.exists(file_): | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
115 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
116 _("file {file_} doesn't exist!").format(file_=repr(file_)), error=True |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
117 ) |
3040 | 118 self.host.quit(C.EXIT_BAD_ARG) |
817 | 119 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
|
120 self.disp( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
121 _( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
122 "{file_} is a dir! Please send files inside or use compression" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
123 ).format(file_=repr(file_)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
124 ) |
3040 | 125 self.host.quit(C.EXIT_BAD_ARG) |
817 | 126 |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
127 extra = {} |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
128 if self.args.path: |
3028 | 129 extra["path"] = self.args.path |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
130 if self.args.namespace: |
3028 | 131 extra["namespace"] = self.args.namespace |
3970
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
132 if self.args.encrypt: |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
133 extra["encrypted"] = True |
817 | 134 |
135 if self.args.bz2: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
136 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
|
137 self.host.addOnQuitCallback(os.unlink, buf.name) |
3028 | 138 self.disp(_("bz2 is an experimental option, use with caution")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
139 # FIXME: check free space |
3028 | 140 self.disp(_("Starting compression, please wait...")) |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
141 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
|
142 bz2 = tarfile.open(mode="w:bz2", fileobj=buf) |
3028 | 143 archive_name = "{}.tar.bz2".format( |
144 os.path.basename(self.args.files[0]) or "compressed_files" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
145 ) |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
146 for file_ in self.args.files: |
3028 | 147 self.disp(_("Adding {}").format(file_), 1) |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
148 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
|
149 bz2.close() |
3028 | 150 self.disp(_("Done !"), 1) |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
151 |
3040 | 152 try: |
153 send_data = await self.host.bridge.fileSend( | |
3408
19bc03743aeb
jp (file/send): don't add main resource to bare jid anymore:
Goffi <goffi@goffi.org>
parents:
3325
diff
changeset
|
154 self.args.jid, |
3040 | 155 buf.name, |
156 self.args.name or archive_name, | |
157 "", | |
3970
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
158 data_format.serialise(extra), |
3040 | 159 self.profile, |
160 ) | |
161 except Exception as e: | |
162 self.disp(f"can't send file: {e}", error=True) | |
163 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
164 else: | |
165 await self.gotId(send_data, file_) | |
0 | 166 else: |
817 | 167 for file_ in self.args.files: |
168 path = os.path.abspath(file_) | |
3040 | 169 try: |
170 send_data = await self.host.bridge.fileSend( | |
3408
19bc03743aeb
jp (file/send): don't add main resource to bare jid anymore:
Goffi <goffi@goffi.org>
parents:
3325
diff
changeset
|
171 self.args.jid, |
3040 | 172 path, |
173 self.args.name, | |
174 "", | |
3970
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
175 data_format.serialise(extra), |
3040 | 176 self.profile, |
177 ) | |
178 except Exception as e: | |
179 self.disp(f"can't send file {file_!r}: {e}", error=True) | |
180 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
181 else: | |
182 await self.gotId(send_data, file_) | |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
183 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
184 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
185 class Request(base.CommandBase): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
186 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
187 super(Request, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
188 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
189 "request", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
190 use_progress=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
191 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
192 help=_("request a file from a contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
193 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
194 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
195 @property |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
196 def filename(self): |
3028 | 197 return self.args.name or self.args.hash or "output" |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
198 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
199 def add_parser_options(self): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
200 self.parser.add_argument("jid", help=_("the destination jid")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
201 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
202 "-D", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
203 "--dest", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
204 help=_( |
3040 | 205 "destination path where the file will be saved (default: " |
206 "[current_dir]/[name|hash])" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
207 ), |
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 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
210 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
211 "--name", |
3028 | 212 default="", |
213 help=_("name of the file"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
214 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
215 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
216 "-H", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
217 "--hash", |
3028 | 218 default="", |
219 help=_("hash of the file"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
220 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
221 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
222 "-a", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
223 "--hash-algo", |
3028 | 224 default="sha-256", |
225 help=_("hash algorithm use for --hash (default: sha-256)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
226 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
227 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
228 "-d", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
229 "--path", |
3028 | 230 help=("path to the directory containing the file"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
231 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
232 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
233 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
234 "--namespace", |
3028 | 235 help=("namespace of the file"), |
2624
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 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
239 "--force", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
240 action="store_true", |
3028 | 241 help=_("overwrite existing file without confirmation"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
242 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
243 |
3040 | 244 async def onProgressStarted(self, metadata): |
3028 | 245 self.disp(_("File copy started"), 2) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
246 |
3040 | 247 async def onProgressFinished(self, metadata): |
3028 | 248 self.disp(_("File received successfully"), 2) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
249 |
3040 | 250 async def onProgressError(self, error_msg): |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
251 if error_msg == C.PROGRESS_ERROR_DECLINED: |
3028 | 252 self.disp(_("The file request has been refused")) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
253 else: |
3028 | 254 self.disp(_("Error while requesting file: {}").format(error_msg), error=True) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
255 |
3040 | 256 async def start(self): |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
257 if not self.args.name and not self.args.hash: |
3028 | 258 self.parser.error(_("at least one of --name or --hash must be provided")) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
259 if self.args.dest: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
260 path = os.path.abspath(os.path.expanduser(self.args.dest)) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
261 if os.path.isdir(path): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
262 path = os.path.join(path, self.filename) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
263 else: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
264 path = os.path.abspath(self.filename) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
265 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
266 if os.path.exists(path) and not self.args.force: |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
267 message = _("File {path} already exists! Do you want to overwrite?").format( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
268 path=path |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
269 ) |
3040 | 270 await self.host.confirmOrQuit(message, _("file request cancelled")) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
271 |
3040 | 272 self.full_dest_jid = await self.host.get_full_jid(self.args.jid) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
273 extra = {} |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
274 if self.args.path: |
3028 | 275 extra["path"] = self.args.path |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
276 if self.args.namespace: |
3028 | 277 extra["namespace"] = self.args.namespace |
3040 | 278 try: |
279 progress_id = await self.host.bridge.fileJingleRequest( | |
280 self.full_dest_jid, | |
281 path, | |
282 self.args.name, | |
283 self.args.hash, | |
284 self.args.hash_algo if self.args.hash else "", | |
285 extra, | |
286 self.profile, | |
287 ) | |
288 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
289 self.disp(msg=_("can't request file: {e}").format(e=e), error=True) |
3040 | 290 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
291 else: | |
292 await self.set_progress_id(progress_id) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
293 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
294 |
817 | 295 class Receive(base.CommandAnswering): |
296 def __init__(self, host): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
297 super(Receive, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
298 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
299 "receive", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
300 use_progress=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
301 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
302 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
|
303 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
304 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
|
305 self.action_callbacks = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
306 C.META_TYPE_FILE: self.onFileAction, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
307 C.META_TYPE_OVERWRITE: self.onOverwriteAction, |
3410
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
308 C.META_TYPE_NOT_IN_ROSTER_LEAK: self.onNotInRosterAction, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
309 } |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
310 |
817 | 311 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
312 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
313 "jids", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
314 nargs="*", |
3028 | 315 help=_("jids accepted (accept everything if none is specified)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
316 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
317 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
318 "-m", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
319 "--multiple", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
320 action="store_true", |
3028 | 321 help=_("accept multiple files (you'll have to stop manually)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
322 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
323 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
324 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
325 "--force", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
326 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
327 help=_( |
3028 | 328 "force overwritting of existing files (/!\\ name is choosed by sender)" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
329 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
330 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
331 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
332 "--path", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
333 default=".", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
334 metavar="DIR", |
3028 | 335 help=_("destination path (default: working directory)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
336 ) |
817 | 337 |
3040 | 338 async def onProgressStarted(self, metadata): |
339 self.disp(_("File copy started"), 2) | |
340 | |
341 async def onProgressFinished(self, metadata): | |
342 self.disp(_("File received successfully"), 2) | |
343 if metadata.get("hash_verified", False): | |
344 try: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
345 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
346 _("hash checked: {metadata['hash_algo']}:{metadata['hash']}"), 1 |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
347 ) |
3040 | 348 except KeyError: |
349 self.disp(_("hash is checked but hash value is missing", 1), error=True) | |
350 else: | |
351 self.disp(_("hash can't be verified"), 1) | |
352 | |
353 async def onProgressError(self, e): | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
354 self.disp(_("Error while receiving file: {e}").format(e=e), error=True) |
3040 | 355 |
356 def getXmluiId(self, action_data): | |
357 # FIXME: we temporarily use ElementTree, but a real XMLUI managing module | |
358 # should be available in the futur | |
359 # TODO: XMLUI module | |
360 try: | |
361 xml_ui = action_data["xmlui"] | |
362 except KeyError: | |
363 self.disp(_("Action has no XMLUI"), 1) | |
364 else: | |
365 ui = ET.fromstring(xml_ui.encode("utf-8")) | |
366 xmlui_id = ui.get("submit") | |
367 if not xmlui_id: | |
368 self.disp(_("Invalid XMLUI received"), error=True) | |
369 return xmlui_id | |
370 | |
371 async def onFileAction(self, action_data, action_id, security_limit, profile): | |
372 xmlui_id = self.getXmluiId(action_data) | |
373 if xmlui_id is None: | |
374 return self.host.quitFromSignal(1) | |
375 try: | |
376 from_jid = jid.JID(action_data["meta_from_jid"]) | |
377 except KeyError: | |
378 self.disp(_("Ignoring action without from_jid data"), 1) | |
379 return | |
380 try: | |
381 progress_id = action_data["meta_progress_id"] | |
382 except KeyError: | |
383 self.disp(_("ignoring action without progress id"), 1) | |
384 return | |
385 | |
386 if not self.bare_jids or from_jid.bare in self.bare_jids: | |
387 if self._overwrite_refused: | |
388 self.disp(_("File refused because overwrite is needed"), error=True) | |
389 await self.host.bridge.launchAction( | |
390 xmlui_id, {"cancelled": C.BOOL_TRUE}, profile_key=profile | |
391 ) | |
392 return self.host.quitFromSignal(2) | |
393 await self.set_progress_id(progress_id) | |
394 xmlui_data = {"path": self.path} | |
395 await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) | |
396 | |
397 async def onOverwriteAction(self, action_data, action_id, security_limit, profile): | |
398 xmlui_id = self.getXmluiId(action_data) | |
399 if xmlui_id is None: | |
400 return self.host.quitFromSignal(1) | |
401 try: | |
402 progress_id = action_data["meta_progress_id"] | |
403 except KeyError: | |
404 self.disp(_("ignoring action without progress id"), 1) | |
405 return | |
406 self.disp(_("Overwriting needed"), 1) | |
407 | |
408 if progress_id == self.progress_id: | |
409 if self.args.force: | |
410 self.disp(_("Overwrite accepted"), 2) | |
411 else: | |
412 self.disp(_("Refused to overwrite"), 2) | |
413 self._overwrite_refused = True | |
414 | |
415 xmlui_data = {"answer": C.boolConst(self.args.force)} | |
416 await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) | |
417 | |
3410
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
418 async def onNotInRosterAction(self, action_data, action_id, security_limit, profile): |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
419 xmlui_id = self.getXmluiId(action_data) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
420 if xmlui_id is None: |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
421 return self.host.quitFromSignal(1) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
422 try: |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
423 from_jid = jid.JID(action_data["meta_from_jid"]) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
424 except ValueError: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
425 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
426 _('invalid "from_jid" value received, ignoring: {value}').format( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
427 value=from_jid |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
428 ), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
429 error=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
430 ) |
3410
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
431 return |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
432 except KeyError: |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
433 self.disp(_('ignoring action without "from_jid" value'), error=True) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
434 return |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
435 self.disp(_("Confirmation needed for request from an entity not in roster"), 1) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
436 |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
437 if from_jid.bare in self.bare_jids: |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
438 # if the sender is expected, we can confirm the session |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
439 confirmed = True |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
440 self.disp(_("Sender confirmed because she or he is explicitly expected"), 1) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
441 else: |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
442 xmlui = xmlui_manager.create(self.host, action_data["xmlui"]) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
443 confirmed = await self.host.confirm(xmlui.dlg.message) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
444 |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
445 xmlui_data = {"answer": C.boolConst(confirmed)} |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
446 await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
447 if not confirmed and not self.args.multiple: |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
448 self.disp(_("Session refused for {from_jid}").format(from_jid=from_jid)) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
449 self.host.quitFromSignal(0) |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
450 |
3040 | 451 async 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
|
452 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
|
453 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
|
454 if not os.path.isdir(self.path): |
3028 | 455 self.disp(_("Given path is not a directory !", error=True)) |
3040 | 456 self.host.quit(C.EXIT_BAD_ARG) |
817 | 457 if self.args.multiple: |
458 self.host.quit_on_progress_end = False | |
3028 | 459 self.disp(_("waiting for incoming file request"), 2) |
3040 | 460 await self.start_answering() |
817 | 461 |
462 | |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
463 class Get(base.CommandBase): |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
464 def __init__(self, host): |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
465 super(Get, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
466 host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
467 "get", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
468 use_progress=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
469 use_verbose=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
470 help=_("download a file from URI"), |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
471 ) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
472 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
473 def add_parser_options(self): |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
474 self.parser.add_argument( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
475 "-o", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
476 "--dest-file", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
477 type=str, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
478 default="", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
479 help=_("destination file (DEFAULT: filename from URL)"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
480 ) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
481 self.parser.add_argument( |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
482 "-f", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
483 "--force", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
484 action="store_true", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
485 help=_("overwrite existing file without confirmation"), |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
486 ) |
3926
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
487 self.parser.add_argument( |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
488 "attachment", type=str, |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
489 help=_("URI of the file to retrieve or JSON of the whole attachment") |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
490 ) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
491 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
492 async def onProgressStarted(self, metadata): |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
493 self.disp(_("File download started"), 2) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
494 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
495 async def onProgressFinished(self, metadata): |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
496 self.disp(_("File downloaded successfully"), 2) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
497 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
498 async def onProgressError(self, error_msg): |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
499 self.disp(_("Error while downloading file: {}").format(error_msg), error=True) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
500 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
501 async def gotId(self, data): |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
502 """Called when a progress id has been received""" |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
503 try: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
504 await self.set_progress_id(data["progress"]) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
505 except KeyError: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
506 if "xmlui" in data: |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
507 ui = xmlui_manager.create(self.host, data["xmlui"]) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
508 await ui.show() |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
509 else: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
510 self.disp(_("Can't download file"), error=True) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
511 self.host.quit(C.EXIT_ERROR) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
512 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
513 async def start(self): |
3926
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
514 try: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
515 attachment = json.loads(self.args.attachment) |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
516 except json.JSONDecodeError: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
517 attachment = {"uri": self.args.attachment} |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
518 dest_file = self.args.dest_file |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
519 if not dest_file: |
3926
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
520 try: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
521 dest_file = attachment["name"].replace("/", "-").strip() |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
522 except KeyError: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
523 try: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
524 dest_file = Path(urlparse(attachment["uri"]).path).name.strip() |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
525 except KeyError: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
526 pass |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
527 if not dest_file: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
528 dest_file = "downloaded_file" |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
529 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
530 dest_file = Path(dest_file).expanduser().resolve() |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
531 if dest_file.exists() and not self.args.force: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
532 message = _("File {path} already exists! Do you want to overwrite?").format( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
533 path=dest_file |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
534 ) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
535 await self.host.confirmOrQuit(message, _("file download cancelled")) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
536 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
537 options = {} |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
538 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
539 try: |
3926
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
540 download_data_s = await self.host.bridge.fileDownload( |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
541 data_format.serialise(attachment), |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
542 str(dest_file), |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
543 data_format.serialise(options), |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
544 self.profile, |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
545 ) |
3926
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
546 download_data = data_format.deserialise(download_data_s) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
547 except Exception as e: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
548 self.disp(f"error while trying to download a file: {e}", error=True) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
549 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
550 else: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
551 await self.gotId(download_data) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
552 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
553 |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
554 class Upload(base.CommandBase): |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
555 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
556 super(Upload, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
557 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
|
558 ) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
559 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
560 def add_parser_options(self): |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
561 self.parser.add_argument( |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
562 "-e", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
563 "--encrypt", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
564 action="store_true", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
565 help=_("encrypt file using AES-GCM"), |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
566 ) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
567 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
|
568 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
569 "jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
570 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
571 help=_("jid of upload component (nothing to autodetect)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
572 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
573 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
574 "--ignore-tls-errors", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
575 action="store_true", |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
576 help=_(r"ignore invalide TLS certificate (/!\ Dangerous /!\)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
577 ) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
578 |
3040 | 579 async def onProgressStarted(self, metadata): |
3028 | 580 self.disp(_("File upload started"), 2) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
581 |
3040 | 582 async def onProgressFinished(self, metadata): |
3028 | 583 self.disp(_("File uploaded successfully"), 2) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
584 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
585 url = metadata["url"] |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
586 except KeyError: |
3028 | 587 self.disp("download URL not found in metadata") |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
588 else: |
3028 | 589 self.disp(_("URL to retrieve the file:"), 1) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
590 # XXX: url is displayed alone on a line to make parsing easier |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
591 self.disp(url) |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
592 |
3040 | 593 async def onProgressError(self, error_msg): |
3028 | 594 self.disp(_("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
|
595 |
3040 | 596 async def gotId(self, data, file_): |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
597 """Called when a progress id has been received |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
598 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
599 @param pid(unicode): progress id |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
600 @param file_(str): file path |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
601 """ |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
602 try: |
3040 | 603 await self.set_progress_id(data["progress"]) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
604 except KeyError: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
605 if "xmlui" in data: |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
606 ui = xmlui_manager.create(self.host, data["xmlui"]) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
607 await ui.show() |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
608 else: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
609 self.disp(_("Can't upload file"), error=True) |
3040 | 610 self.host.quit(C.EXIT_ERROR) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
611 |
3040 | 612 async def start(self): |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
613 file_ = self.args.file |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
614 if not os.path.exists(file_): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
615 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
616 _("file {file_} doesn't exist !").format(file_=repr(file_)), error=True |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
617 ) |
3040 | 618 self.host.quit(C.EXIT_BAD_ARG) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
619 if os.path.isdir(file_): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
620 self.disp(_("{file_} is a dir! Can't upload a dir").format(file_=repr(file_))) |
3040 | 621 self.host.quit(C.EXIT_BAD_ARG) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
622 |
3040 | 623 if self.args.jid is None: |
3068
e189ceca7e8b
jp (file/upload): fixed exception when no jid is specified
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
624 self.full_dest_jid = "" |
3040 | 625 else: |
626 self.full_dest_jid = await self.host.get_full_jid(self.args.jid) | |
627 | |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
628 options = {} |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
629 if self.args.ignore_tls_errors: |
3089
e75024e41f81
plugin upload, XEP-0363: code modernisation + preparation for extension:
Goffi <goffi@goffi.org>
parents:
3068
diff
changeset
|
630 options["ignore_tls_errors"] = True |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
631 if self.args.encrypt: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
632 options["encryption"] = C.ENC_AES_GCM |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
633 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
634 path = os.path.abspath(file_) |
3040 | 635 try: |
636 upload_data = await self.host.bridge.fileUpload( | |
637 path, | |
638 "", | |
639 self.full_dest_jid, | |
3089
e75024e41f81
plugin upload, XEP-0363: code modernisation + preparation for extension:
Goffi <goffi@goffi.org>
parents:
3068
diff
changeset
|
640 data_format.serialise(options), |
3040 | 641 self.profile, |
642 ) | |
643 except Exception as e: | |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
644 self.disp(f"error while trying to upload a file: {e}", error=True) |
3040 | 645 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
646 else: | |
647 await self.gotId(upload_data, file_) | |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
648 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
649 |
3325
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
650 class ShareAffiliationsSet(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
651 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
652 super(ShareAffiliationsSet, self).__init__( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
653 host, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
654 "set", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
655 use_output=C.OUTPUT_DICT, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
656 help=_("set affiliations for a shared file/directory"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
657 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
658 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
659 def add_parser_options(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
660 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
661 "-N", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
662 "--namespace", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
663 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
664 help=_("namespace of the repository"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
665 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
666 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
667 "-P", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
668 "--path", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
669 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
670 help=_("path to the repository"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
671 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
672 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
673 "-a", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
674 "--affiliation", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
675 dest="affiliations", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
676 metavar=("JID", "AFFILIATION"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
677 required=True, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
678 action="append", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
679 nargs=2, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
680 help=_("entity/affiliation couple(s)"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
681 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
682 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
683 "jid", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
684 help=_("jid of file sharing entity"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
685 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
686 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
687 async def start(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
688 affiliations = dict(self.args.affiliations) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
689 try: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
690 affiliations = await self.host.bridge.FISAffiliationsSet( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
691 self.args.jid, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
692 self.args.namespace, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
693 self.args.path, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
694 affiliations, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
695 self.profile, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
696 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
697 except Exception as e: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
698 self.disp(f"can't set affiliations: {e}", error=True) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
699 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
700 else: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
701 self.host.quit() |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
702 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
703 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
704 class ShareAffiliationsGet(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
705 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
706 super(ShareAffiliationsGet, self).__init__( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
707 host, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
708 "get", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
709 use_output=C.OUTPUT_DICT, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
710 help=_("retrieve affiliations of a shared file/directory"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
711 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
712 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
713 def add_parser_options(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
714 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
715 "-N", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
716 "--namespace", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
717 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
718 help=_("namespace of the repository"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
719 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
720 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
721 "-P", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
722 "--path", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
723 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
724 help=_("path to the repository"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
725 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
726 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
727 "jid", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
728 help=_("jid of sharing entity"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
729 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
730 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
731 async def start(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
732 try: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
733 affiliations = await self.host.bridge.FISAffiliationsGet( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
734 self.args.jid, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
735 self.args.namespace, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
736 self.args.path, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
737 self.profile, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
738 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
739 except Exception as e: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
740 self.disp(f"can't get affiliations: {e}", error=True) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
741 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
742 else: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
743 await self.output(affiliations) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
744 self.host.quit() |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
745 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
746 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
747 class ShareAffiliations(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
748 subcommands = (ShareAffiliationsGet, ShareAffiliationsSet) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
749 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
750 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
751 super(ShareAffiliations, self).__init__( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
752 host, "affiliations", use_profile=False, help=_("affiliations management") |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
753 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
754 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
755 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
756 class ShareConfigurationSet(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
757 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
758 super(ShareConfigurationSet, self).__init__( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
759 host, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
760 "set", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
761 use_output=C.OUTPUT_DICT, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
762 help=_("set configuration for a shared file/directory"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
763 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
764 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
765 def add_parser_options(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
766 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
767 "-N", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
768 "--namespace", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
769 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
770 help=_("namespace of the repository"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
771 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
772 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
773 "-P", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
774 "--path", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
775 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
776 help=_("path to the repository"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
777 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
778 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
779 "-f", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
780 "--field", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
781 action="append", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
782 nargs=2, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
783 dest="fields", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
784 required=True, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
785 metavar=("KEY", "VALUE"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
786 help=_("configuration field to set (required)"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
787 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
788 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
789 "jid", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
790 help=_("jid of file sharing entity"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
791 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
792 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
793 async def start(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
794 configuration = dict(self.args.fields) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
795 try: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
796 configuration = await self.host.bridge.FISConfigurationSet( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
797 self.args.jid, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
798 self.args.namespace, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
799 self.args.path, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
800 configuration, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
801 self.profile, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
802 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
803 except Exception as e: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
804 self.disp(f"can't set configuration: {e}", error=True) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
805 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
806 else: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
807 self.host.quit() |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
808 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
809 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
810 class ShareConfigurationGet(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
811 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
812 super(ShareConfigurationGet, self).__init__( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
813 host, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
814 "get", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
815 use_output=C.OUTPUT_DICT, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
816 help=_("retrieve configuration of a shared file/directory"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
817 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
818 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
819 def add_parser_options(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
820 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
821 "-N", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
822 "--namespace", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
823 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
824 help=_("namespace of the repository"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
825 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
826 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
827 "-P", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
828 "--path", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
829 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
830 help=_("path to the repository"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
831 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
832 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
833 "jid", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
834 help=_("jid of sharing entity"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
835 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
836 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
837 async def start(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
838 try: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
839 configuration = await self.host.bridge.FISConfigurationGet( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
840 self.args.jid, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
841 self.args.namespace, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
842 self.args.path, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
843 self.profile, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
844 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
845 except Exception as e: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
846 self.disp(f"can't get configuration: {e}", error=True) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
847 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
848 else: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
849 await self.output(configuration) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
850 self.host.quit() |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
851 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
852 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
853 class ShareConfiguration(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
854 subcommands = (ShareConfigurationGet, ShareConfigurationSet) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
855 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
856 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
857 super(ShareConfiguration, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
858 host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
859 "configuration", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
860 use_profile=False, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
861 help=_("file sharing node configuration"), |
3325
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
862 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
863 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
864 |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
865 class ShareList(base.CommandBase): |
817 | 866 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
867 extra_outputs = {"default": self.default_output} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
868 super(ShareList, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
869 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
870 "list", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
871 use_output=C.OUTPUT_LIST_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
872 extra_outputs=extra_outputs, |
3028 | 873 help=_("retrieve files shared by an entity"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
874 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
875 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
876 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
877 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
878 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
879 "-d", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
880 "--path", |
3028 | 881 default="", |
882 help=_("path to the directory containing the files"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
883 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
884 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
885 "jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
886 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
887 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
888 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
|
889 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
890 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
891 def _name_filter(self, name, row): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
892 if row.type == C.FILE_TYPE_DIRECTORY: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
893 return A.color(C.A_DIRECTORY, name) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
894 elif row.type == C.FILE_TYPE_FILE: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
895 return A.color(C.A_FILE, name) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
896 else: |
3028 | 897 self.disp(_("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
|
898 return name |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
899 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
900 def _size_filter(self, size, row): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
901 if not size: |
3028 | 902 return "" |
3524
584379473925
tools (common/utils): new methods to parse and generate file size with symbols:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
903 return A.color(A.BOLD, utils.getHumanSize(size)) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
904 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
905 def default_output(self, files_data): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
906 """display files a way similar to ls""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
907 files_data.sort(key=lambda d: d["name"].lower()) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
908 show_header = False |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
909 if self.verbosity == 0: |
3040 | 910 keys = headers = ("name", "type") |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
911 elif self.verbosity == 1: |
3040 | 912 keys = headers = ("name", "type", "size") |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
913 elif self.verbosity > 1: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
914 show_header = True |
3040 | 915 keys = ("name", "type", "size", "file_hash") |
3028 | 916 headers = ("name", "type", "size", "hash") |
3121 | 917 table = common.Table.fromListDict( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
918 self.host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
919 files_data, |
3040 | 920 keys=keys, |
921 headers=headers, | |
3028 | 922 filters={"name": self._name_filter, "size": self._size_filter}, |
3040 | 923 defaults={"size": "", "file_hash": ""}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
924 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
925 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
|
926 |
3040 | 927 async def start(self): |
928 try: | |
929 files_data = await self.host.bridge.FISList( | |
930 self.args.jid, | |
931 self.args.path, | |
932 {}, | |
933 self.profile, | |
934 ) | |
935 except Exception as e: | |
936 self.disp(f"can't retrieve shared files: {e}", error=True) | |
937 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
938 |
3040 | 939 await self.output(files_data) |
940 self.host.quit() | |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
941 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
942 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
943 class SharePath(base.CommandBase): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
944 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
945 super(SharePath, self).__init__( |
3028 | 946 host, "path", help=_("share a file or directory"), use_verbose=True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
947 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
948 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
949 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
950 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
951 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
952 "--name", |
3028 | 953 default="", |
954 help=_("virtual name to use (default: use directory/file name)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
955 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
956 perm_group = self.parser.add_mutually_exclusive_group() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
957 perm_group.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
958 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
959 "--jid", |
3040 | 960 metavar="JID", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
961 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
962 dest="jids", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
963 default=[], |
3028 | 964 help=_("jid of contacts allowed to retrieve the files"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
965 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
966 perm_group.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
967 "--public", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
968 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
969 help=_( |
3040 | 970 r"share publicly the file(s) (/!\ *everybody* will be able to access " |
971 r"them)" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
972 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
973 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
974 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
975 "path", |
3028 | 976 help=_("path to a file or directory to share"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
977 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
978 |
3040 | 979 async def start(self): |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
980 self.path = os.path.abspath(self.args.path) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
981 if self.args.public: |
3028 | 982 access = {"read": {"type": "public"}} |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
983 else: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
984 jids = self.args.jids |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
985 if jids: |
3028 | 986 access = {"read": {"type": "whitelist", "jids": jids}} |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
987 else: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
988 access = {} |
3040 | 989 try: |
990 name = await self.host.bridge.FISSharePath( | |
991 self.args.name, | |
992 self.path, | |
993 json.dumps(access, ensure_ascii=False), | |
994 self.profile, | |
995 ) | |
996 except Exception as e: | |
997 self.disp(f"can't share path: {e}", error=True) | |
998 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
999 else: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1000 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1001 _('{path} shared under the name "{name}"').format( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1002 path=self.path, name=name |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1003 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1004 ) |
3040 | 1005 self.host.quit() |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1006 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1007 |
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
|
1008 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
|
1009 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
|
1010 super(ShareInvite, self).__init__( |
3028 | 1011 host, "invite", help=_("send invitation for a shared repository") |
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
|
1012 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1013 |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1014 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
|
1015 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
|
1016 "-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
|
1017 "--name", |
3028 | 1018 default="", |
1019 help=_("name of the repository"), | |
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
|
1020 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1021 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
|
1022 "-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
|
1023 "--namespace", |
3028 | 1024 default="", |
1025 help=_("namespace of the repository"), | |
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
|
1026 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1027 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
|
1028 "-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
|
1029 "--path", |
3028 | 1030 help=_("path to the repository"), |
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
|
1031 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1032 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
|
1033 "-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
|
1034 "--type", |
3028 | 1035 choices=["files", "photos"], |
1036 default="files", | |
1037 help=_("type of the repository"), | |
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
|
1038 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1039 self.parser.add_argument( |
2932
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1040 "-T", |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1041 "--thumbnail", |
3028 | 1042 help=_("https URL of a image to use as thumbnail"), |
2932
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1043 ) |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1044 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
|
1045 "service", |
3028 | 1046 help=_("jid of the file sharing service hosting the repository"), |
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
|
1047 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1048 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
|
1049 "jid", |
3028 | 1050 help=_("jid of the person to invite"), |
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
|
1051 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1052 |
3040 | 1053 async def start(self): |
3028 | 1054 self.path = os.path.normpath(self.args.path) if self.args.path else "" |
2932
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1055 extra = {} |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1056 if self.args.thumbnail is not None: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1057 if not self.args.thumbnail.startswith("http"): |
3028 | 1058 self.parser.error(_("only http(s) links are allowed with --thumbnail")) |
2932
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1059 else: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1060 extra["thumb_url"] = self.args.thumbnail |
3040 | 1061 try: |
1062 await self.host.bridge.FISInvite( | |
1063 self.args.jid, | |
1064 self.args.service, | |
1065 self.args.type, | |
1066 self.args.namespace, | |
1067 self.path, | |
1068 self.args.name, | |
1069 data_format.serialise(extra), | |
1070 self.profile, | |
1071 ) | |
1072 except Exception as e: | |
1073 self.disp(f"can't send invitation: {e}", error=True) | |
1074 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1075 else: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1076 self.disp(_("invitation sent to {jid}").format(jid=self.args.jid)) |
3040 | 1077 self.host.quit() |
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
|
1078 |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1079 |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1080 class Share(base.CommandBase): |
3325
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1081 subcommands = ( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1082 ShareList, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1083 SharePath, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1084 ShareInvite, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1085 ShareAffiliations, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1086 ShareConfiguration, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1087 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1088 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1089 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1090 super(Share, self).__init__( |
3028 | 1091 host, "share", use_profile=False, help=_("files sharing management") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1092 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1093 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1094 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1095 class File(base.CommandBase): |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
1096 subcommands = (Send, Request, Receive, Get, Upload, Share) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1097 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1098 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1099 super(File, self).__init__( |
3028 | 1100 host, "file", use_profile=False, help=_("files sending/receiving/management") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1101 ) |