Mercurial > libervia-backend
annotate libervia/cli/cmd_file.py @ 4238:b0c36f3d3e04
core: update `pygobject` version and replace deprecated `configparser.SafeConfigParser`
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 11 May 2024 13:16:13 +0200 |
parents | d01b8d002619 |
children | 79c8a70e1813 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
815 | 3 |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
4 # Libervia CLI |
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 |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
21 import asyncio |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
22 from functools import partial |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
23 import importlib |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
24 import logging |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
25 from typing import IO |
3028 | 26 from . import base |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
27 from . import xmlui_manager |
814 | 28 import sys |
29 import os | |
30 import os.path | |
31 import tarfile | |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4042
diff
changeset
|
32 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4042
diff
changeset
|
33 from libervia.backend.tools.common import data_format |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
34 from libervia.cli.constants import Const as C |
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
35 from libervia.cli import common |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
36 from libervia.frontends.tools import aio, jid |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4042
diff
changeset
|
37 from libervia.backend.tools.common.ansi import ANSI as A |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4042
diff
changeset
|
38 from libervia.backend.tools.common import utils |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
39 from urllib.parse import urlparse |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
40 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
|
41 import tempfile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
42 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
|
43 import json |
402
f03688bdb858
jp: use with statement to open fifo
Goffi <goffi@goffi.org>
parents:
401
diff
changeset
|
44 |
817 | 45 __commands__ = ["File"] |
3926
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
46 DEFAULT_DEST = "downloaded_file" |
0 | 47 |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
48 |
817 | 49 class Send(base.CommandBase): |
50 def __init__(self, host): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
51 super(Send, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
52 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
53 "send", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
54 use_progress=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
55 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
56 help=_("send a file to a contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
57 ) |
0 | 58 |
817 | 59 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
60 self.parser.add_argument( |
3028 | 61 "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
|
62 ) |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
63 self.parser.add_argument("jid", help=_("the destination jid")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
64 self.parser.add_argument( |
3028 | 65 "-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
|
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 "-d", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
69 "--path", |
3028 | 70 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
|
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 "--namespace", |
3028 | 75 help=("namespace of the file"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
76 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
77 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
78 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
79 "--name", |
3028 | 80 default="", |
81 help=("name to use (DEFAULT: use source file name)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
82 ) |
3970
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
83 self.parser.add_argument( |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
84 "-e", |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
85 "--encrypt", |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
86 action="store_true", |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
87 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
|
88 ) |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
89 self.parser.add_argument( |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
90 "--webrtc", |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
91 action="store_true", |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
92 help=_("Use WebRTC Data Channel transport.") |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
93 ) |
0 | 94 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
95 async def on_progress_started(self, metadata): |
3028 | 96 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
|
97 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
98 async def on_progress_finished(self, metadata): |
3028 | 99 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
|
100 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
101 async def on_progress_error(self, error_msg): |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
102 if error_msg == C.PROGRESS_ERROR_DECLINED: |
3028 | 103 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
|
104 else: |
3028 | 105 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
|
106 |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
107 async def got_id(self, data: dict): |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
108 """Called when a progress id has been received""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
109 # 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
|
110 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
|
111 try: |
3040 | 112 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
|
113 except KeyError: |
a17a91531fbe
jp (file): print a message and quit if progress_id is not received
Goffi <goffi@goffi.org>
parents:
1606
diff
changeset
|
114 # 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
|
115 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
|
116 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
|
117 |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
118 |
3040 | 119 async def start(self): |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
120 file_ = None |
817 | 121 for file_ in self.args.files: |
122 if not os.path.exists(file_): | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
123 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
124 _("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
|
125 ) |
3040 | 126 self.host.quit(C.EXIT_BAD_ARG) |
817 | 127 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
|
128 self.disp( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
129 _( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
130 "{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
|
131 ).format(file_=repr(file_)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
132 ) |
3040 | 133 self.host.quit(C.EXIT_BAD_ARG) |
817 | 134 |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
135 extra = {} |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
136 if self.args.path: |
3028 | 137 extra["path"] = self.args.path |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
138 if self.args.namespace: |
3028 | 139 extra["namespace"] = self.args.namespace |
3970
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
140 if self.args.encrypt: |
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
141 extra["encrypted"] = True |
817 | 142 |
143 if self.args.bz2: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
144 with tempfile.NamedTemporaryFile("wb", delete=False) as buf: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
145 self.host.add_on_quit_callback(os.unlink, buf.name) |
3028 | 146 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
|
147 # FIXME: check free space |
3028 | 148 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
|
149 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
|
150 bz2 = tarfile.open(mode="w:bz2", fileobj=buf) |
3028 | 151 archive_name = "{}.tar.bz2".format( |
152 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
|
153 ) |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
154 for file_ in self.args.files: |
3028 | 155 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
|
156 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
|
157 bz2.close() |
3028 | 158 self.disp(_("Done !"), 1) |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
159 self.args.files = [buf.name] |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
160 if not self.args.name: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
161 self.args.name = archive_name |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
162 |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
163 for file_ in self.args.files: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
164 file_path = Path(file_) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
165 if self.args.webrtc: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
166 root_logger = logging.getLogger() |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
167 # we don't want any formatting for messages from webrtc |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
168 for handler in root_logger.handlers: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
169 handler.setFormatter(None) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
170 if self.verbosity == 0: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
171 root_logger.setLevel(logging.ERROR) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
172 if self.verbosity >= 1: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
173 root_logger.setLevel(logging.WARNING) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
174 if self.verbosity >= 2: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
175 root_logger.setLevel(logging.DEBUG) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
176 from libervia.frontends.tools.webrtc_file import WebRTCFileSender |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
177 aio.install_glib_asyncio_iteration() |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
178 file_sender = WebRTCFileSender( |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
179 self.host.bridge, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
180 self.profile, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
181 on_call_start_cb=self.got_id, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
182 end_call_cb=self.host.a_quit |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
183 ) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
184 await file_sender.send_file_webrtc( |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
185 file_path, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
186 self.args.jid, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
187 self.args.name |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
188 ) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
189 else: |
3040 | 190 try: |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
191 send_data_raw = await self.host.bridge.file_send( |
3408
19bc03743aeb
jp (file/send): don't add main resource to bare jid anymore:
Goffi <goffi@goffi.org>
parents:
3325
diff
changeset
|
192 self.args.jid, |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
193 str(file_path.absolute()), |
3040 | 194 self.args.name, |
195 "", | |
3970
4c3361e2bf55
cli (file/send): add `--encrypt` argument to request encryption:
Goffi <goffi@goffi.org>
parents:
3926
diff
changeset
|
196 data_format.serialise(extra), |
3040 | 197 self.profile, |
198 ) | |
199 except Exception as e: | |
200 self.disp(f"can't send file {file_!r}: {e}", error=True) | |
201 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
202 else: | |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
203 send_data = data_format.deserialise(send_data_raw) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
204 await self.got_id(send_data) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
205 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
206 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
207 class Request(base.CommandBase): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
208 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
209 super(Request, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
210 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
211 "request", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
212 use_progress=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
213 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
214 help=_("request a file from a contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
215 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
216 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
217 @property |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
218 def filename(self): |
3028 | 219 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
|
220 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
221 def add_parser_options(self): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
222 self.parser.add_argument("jid", help=_("the destination jid")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
223 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
224 "-D", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
225 "--dest", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
226 help=_( |
3040 | 227 "destination path where the file will be saved (default: " |
228 "[current_dir]/[name|hash])" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
229 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
230 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
231 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
232 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
233 "--name", |
3028 | 234 default="", |
235 help=_("name 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 "-H", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
239 "--hash", |
3028 | 240 default="", |
241 help=_("hash of the file"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
242 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
243 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
244 "-a", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
245 "--hash-algo", |
3028 | 246 default="sha-256", |
247 help=_("hash algorithm use for --hash (default: sha-256)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
248 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
249 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
250 "-d", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
251 "--path", |
3028 | 252 help=("path to the directory containing the file"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
253 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
254 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
255 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
256 "--namespace", |
3028 | 257 help=("namespace of the file"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
258 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
259 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
260 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
261 "--force", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
262 action="store_true", |
3028 | 263 help=_("overwrite existing file without confirmation"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
264 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
265 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
266 async def on_progress_started(self, metadata): |
3028 | 267 self.disp(_("File copy started"), 2) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
268 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
269 async def on_progress_finished(self, metadata): |
3028 | 270 self.disp(_("File received successfully"), 2) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
271 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
272 async def on_progress_error(self, error_msg): |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
273 if error_msg == C.PROGRESS_ERROR_DECLINED: |
3028 | 274 self.disp(_("The file request has been refused")) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
275 else: |
3028 | 276 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
|
277 |
3040 | 278 async def start(self): |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
279 if not self.args.name and not self.args.hash: |
3028 | 280 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
|
281 if self.args.dest: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
282 path = os.path.abspath(os.path.expanduser(self.args.dest)) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
283 if os.path.isdir(path): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
284 path = os.path.join(path, self.filename) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
285 else: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
286 path = os.path.abspath(self.filename) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
287 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
288 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
|
289 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
|
290 path=path |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
291 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
292 await self.host.confirm_or_quit(message, _("file request cancelled")) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
293 |
3040 | 294 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
|
295 extra = {} |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
296 if self.args.path: |
3028 | 297 extra["path"] = self.args.path |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
298 if self.args.namespace: |
3028 | 299 extra["namespace"] = self.args.namespace |
3040 | 300 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
301 progress_id = await self.host.bridge.file_jingle_request( |
3040 | 302 self.full_dest_jid, |
303 path, | |
304 self.args.name, | |
305 self.args.hash, | |
306 self.args.hash_algo if self.args.hash else "", | |
307 extra, | |
308 self.profile, | |
309 ) | |
310 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
311 self.disp(msg=_("can't request file: {e}").format(e=e), error=True) |
3040 | 312 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
313 else: | |
314 await self.set_progress_id(progress_id) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
315 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
316 |
817 | 317 class Receive(base.CommandAnswering): |
318 def __init__(self, host): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
319 super(Receive, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
320 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
321 "receive", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
322 use_progress=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
323 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
324 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
|
325 ) |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
326 self._overwrite_refused = False # True when one overwrite has already been refused |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
327 self.action_callbacks = { |
4225
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
328 C.META_TYPE_CONFIRM: self.on_confirm_action, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
329 C.META_TYPE_FILE: self.on_file_action, |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
330 C.META_TYPE_OVERWRITE: self.on_overwrite_action, |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
331 C.META_TYPE_NOT_IN_ROSTER_LEAK: self.on_not_in_roster_action, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
332 } |
1606
de785fcf9a7b
jp (base, file): file command and progress fixes and adaptation to new API:
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
333 |
817 | 334 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
335 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
336 "jids", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
337 nargs="*", |
3028 | 338 help=_("jids accepted (accept everything if none is specified)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
339 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
340 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
341 "-m", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
342 "--multiple", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
343 action="store_true", |
3028 | 344 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
|
345 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
346 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
347 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
348 "--force", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
349 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
350 help=_( |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
351 "force overwriting of existing files (/!\\ name is choosed by sender)" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
352 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
353 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
354 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
355 "--path", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
356 default=".", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
357 metavar="DIR", |
3028 | 358 help=_("destination path (default: working directory)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
359 ) |
817 | 360 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
361 async def on_progress_started(self, metadata): |
3040 | 362 self.disp(_("File copy started"), 2) |
363 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
364 async def on_progress_finished(self, metadata): |
3040 | 365 self.disp(_("File received successfully"), 2) |
366 if metadata.get("hash_verified", False): | |
367 try: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
368 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
369 _("hash checked: {metadata['hash_algo']}:{metadata['hash']}"), 1 |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
370 ) |
3040 | 371 except KeyError: |
372 self.disp(_("hash is checked but hash value is missing", 1), error=True) | |
373 else: | |
374 self.disp(_("hash can't be verified"), 1) | |
375 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
376 async def on_progress_error(self, e): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
377 self.disp(_("Error while receiving file: {e}").format(e=e), error=True) |
3040 | 378 |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
379 async def _on_webrtc_close(self) -> None: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
380 if not self.args.multiple: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
381 await self.host.a_quit() |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
382 |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
383 async def on_webrtc_file( |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
384 self, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
385 from_jid: jid.JID, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
386 session_id: str, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
387 file_data: dict |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
388 ) -> None: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
389 from libervia.frontends.tools.webrtc_file import WebRTCFileReceiver |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
390 aio.install_glib_asyncio_iteration() |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
391 root_logger = logging.getLogger() |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
392 # we don't want any formatting for messages from webrtc |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
393 for handler in root_logger.handlers: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
394 handler.setFormatter(None) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
395 if self.verbosity == 0: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
396 root_logger.setLevel(logging.ERROR) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
397 if self.verbosity >= 1: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
398 root_logger.setLevel(logging.WARNING) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
399 if self.verbosity >= 2: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
400 root_logger.setLevel(logging.DEBUG) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
401 |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
402 dest_path = Path(self.path) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
403 |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
404 if dest_path.is_dir(): |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
405 filename = file_data.get("name", "unammed_file") |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
406 dest_path /= filename |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
407 if dest_path.exists() and not self.args.force: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
408 self.host.disp( |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
409 "Destination file already exists", |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
410 error=True |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
411 ) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
412 aio.run_from_thread( |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
413 self.host.a_quit, C.EXIT_ERROR, loop=self.host.loop.loop |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
414 ) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
415 return |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
416 |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
417 file_receiver = WebRTCFileReceiver( |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
418 self.host.bridge, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
419 self.profile, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
420 on_close_cb=self._on_webrtc_close |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
421 ) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
422 |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
423 await file_receiver.receive_file_webrtc( |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
424 from_jid, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
425 session_id, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
426 dest_path, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
427 file_data |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
428 ) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
429 |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
430 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
431 def get_xmlui_id(self, action_data): |
3040 | 432 # FIXME: we temporarily use ElementTree, but a real XMLUI managing module |
433 # should be available in the futur | |
434 # TODO: XMLUI module | |
435 try: | |
436 xml_ui = action_data["xmlui"] | |
437 except KeyError: | |
438 self.disp(_("Action has no XMLUI"), 1) | |
439 else: | |
440 ui = ET.fromstring(xml_ui.encode("utf-8")) | |
441 xmlui_id = ui.get("submit") | |
442 if not xmlui_id: | |
443 self.disp(_("Invalid XMLUI received"), error=True) | |
444 return xmlui_id | |
445 | |
4225
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
446 async def on_confirm_action(self, action_data, action_id, security_limit, profile): |
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
447 xmlui_id = self.get_xmlui_id(action_data) |
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
448 if xmlui_id is None: |
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
449 return self.host.quit_from_signal(1) |
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
450 if action_data.get("subtype") != C.META_TYPE_FILE: |
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
451 self.disp(_("Ignoring confirm dialog unrelated to file."), 1) |
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
452 return |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
453 try: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
454 from_jid = jid.JID(action_data["from_jid"]) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
455 except KeyError: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
456 self.disp(_("Ignoring action without from_jid data"), 1) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
457 return |
4225
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
458 |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
459 # We accept if no JID is specified (meaning "accept all") or if the sender is |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
460 # explicitly specified. |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
461 answer = not self.bare_jids or from_jid.bare in self.bare_jids |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
462 xmlui_data = {"answer": C.bool_const(answer)} |
4225
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
463 await self.host.bridge.action_launch( |
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
464 xmlui_id, data_format.serialise(xmlui_data), profile_key=profile |
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
465 ) |
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
466 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
467 async def on_file_action(self, action_data, action_id, security_limit, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
468 xmlui_id = self.get_xmlui_id(action_data) |
3040 | 469 if xmlui_id is None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
470 return self.host.quit_from_signal(1) |
3040 | 471 try: |
4042
877145b4ba01
core: don't use `meta_` prefix anymore for `action_extra` in `action_new` signal.
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
472 from_jid = jid.JID(action_data["from_jid"]) |
3040 | 473 except KeyError: |
474 self.disp(_("Ignoring action without from_jid data"), 1) | |
475 return | |
476 try: | |
4042
877145b4ba01
core: don't use `meta_` prefix anymore for `action_extra` in `action_new` signal.
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
477 progress_id = action_data["progress_id"] |
3040 | 478 except KeyError: |
479 self.disp(_("ignoring action without progress id"), 1) | |
480 return | |
481 | |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
482 webrtc = action_data.get("webrtc", False) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
483 file_accepted = action_data.get("file_accepted", False) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
484 |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
485 if file_accepted or not self.bare_jids or from_jid.bare in self.bare_jids: |
3040 | 486 if self._overwrite_refused: |
487 self.disp(_("File refused because overwrite is needed"), error=True) | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
488 await self.host.bridge.action_launch( |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
489 xmlui_id, data_format.serialise({"cancelled": C.BOOL_TRUE}), |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
490 profile_key=profile |
3040 | 491 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
492 return self.host.quit_from_signal(2) |
3040 | 493 await self.set_progress_id(progress_id) |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
494 if webrtc: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
495 xmlui_data = {"answer": C.BOOL_TRUE} |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
496 file_data = action_data.get("file_data") or {} |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
497 try: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
498 session_id = action_data["session_id"] |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
499 except KeyError: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
500 self.disp(_("ignoring action without session id"), 1) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
501 return |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
502 await self.on_webrtc_file( |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
503 from_jid, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
504 session_id, |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
505 file_data |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
506 ) |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
507 |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
508 else: |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
509 xmlui_data = {"path": self.path} |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
510 await self.host.bridge.action_launch( |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
511 xmlui_id, data_format.serialise(xmlui_data), profile_key=profile |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
512 ) |
3040 | 513 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
514 async def on_overwrite_action(self, action_data, action_id, security_limit, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
515 xmlui_id = self.get_xmlui_id(action_data) |
3040 | 516 if xmlui_id is None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
517 return self.host.quit_from_signal(1) |
3040 | 518 try: |
4042
877145b4ba01
core: don't use `meta_` prefix anymore for `action_extra` in `action_new` signal.
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
519 progress_id = action_data["progress_id"] |
3040 | 520 except KeyError: |
521 self.disp(_("ignoring action without progress id"), 1) | |
522 return | |
523 self.disp(_("Overwriting needed"), 1) | |
524 | |
525 if progress_id == self.progress_id: | |
526 if self.args.force: | |
527 self.disp(_("Overwrite accepted"), 2) | |
528 else: | |
529 self.disp(_("Refused to overwrite"), 2) | |
530 self._overwrite_refused = True | |
531 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
532 xmlui_data = {"answer": C.bool_const(self.args.force)} |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
533 await self.host.bridge.action_launch( |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
534 xmlui_id, data_format.serialise(xmlui_data), profile_key=profile |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
535 ) |
3040 | 536 |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
537 async def on_not_in_roster_action( |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
538 self, action_data, action_id, security_limit, profile |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
539 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
540 xmlui_id = self.get_xmlui_id(action_data) |
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
|
541 if xmlui_id is None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
542 return self.host.quit_from_signal(1) |
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
|
543 try: |
4042
877145b4ba01
core: don't use `meta_` prefix anymore for `action_extra` in `action_new` signal.
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
544 from_jid = jid.JID(action_data["from_jid"]) |
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
|
545 except ValueError: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
546 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
547 _('invalid "from_jid" value received, ignoring: {value}').format( |
4225
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
548 value=action_data["from_jid"] |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
549 ), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
550 error=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
551 ) |
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
|
552 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
|
553 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
|
554 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
|
555 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
|
556 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
|
557 |
55f9a38864af
jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:
Goffi <goffi@goffi.org>
parents:
3408
diff
changeset
|
558 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
|
559 # 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
|
560 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
|
561 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
|
562 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
|
563 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
|
564 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
|
565 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
566 xmlui_data = {"answer": C.bool_const(confirmed)} |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
567 await self.host.bridge.action_launch( |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
568 xmlui_id, data_format.serialise(xmlui_data), profile_key=profile |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
569 ) |
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
|
570 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
|
571 self.disp(_("Session refused for {from_jid}").format(from_jid=from_jid)) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
572 self.host.quit_from_signal(0) |
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
|
573 |
3040 | 574 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
|
575 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
|
576 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
|
577 if not os.path.isdir(self.path): |
4225
cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
578 self.disp(_("Given path is not a directory !"), error=True) |
3040 | 579 self.host.quit(C.EXIT_BAD_ARG) |
817 | 580 if self.args.multiple: |
581 self.host.quit_on_progress_end = False | |
3028 | 582 self.disp(_("waiting for incoming file request"), 2) |
3040 | 583 await self.start_answering() |
817 | 584 |
585 | |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
586 class Get(base.CommandBase): |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
587 def __init__(self, host): |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
588 super(Get, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
589 host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
590 "get", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
591 use_progress=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
592 use_verbose=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
593 help=_("download a file from URI"), |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
594 ) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
595 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
596 def add_parser_options(self): |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
597 self.parser.add_argument( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
598 "-o", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
599 "--dest-file", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
600 type=str, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
601 default="", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
602 help=_("destination file (DEFAULT: filename from URL)"), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
603 ) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
604 self.parser.add_argument( |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
605 "-f", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
606 "--force", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
607 action="store_true", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
608 help=_("overwrite existing file without confirmation"), |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
609 ) |
3926
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
610 self.parser.add_argument( |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
611 "attachment", type=str, |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
612 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
|
613 ) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
614 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
615 async def on_progress_started(self, metadata): |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
616 self.disp(_("File download started"), 2) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
617 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
618 async def on_progress_finished(self, metadata): |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
619 self.disp(_("File downloaded successfully"), 2) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
620 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
621 async def on_progress_error(self, error_msg): |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
622 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
|
623 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
624 async def got_id(self, data): |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
625 """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
|
626 try: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
627 await self.set_progress_id(data["progress"]) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
628 except KeyError: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
629 if "xmlui" in data: |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
630 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
|
631 await ui.show() |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
632 else: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
633 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
|
634 self.host.quit(C.EXIT_ERROR) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
635 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
636 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
|
637 try: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
638 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
|
639 except json.JSONDecodeError: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
640 attachment = {"uri": self.args.attachment} |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
641 dest_file = self.args.dest_file |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
642 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
|
643 try: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
644 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
|
645 except KeyError: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
646 try: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
647 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
|
648 except KeyError: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
649 pass |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
650 if not dest_file: |
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
651 dest_file = "downloaded_file" |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
652 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
653 dest_file = Path(dest_file).expanduser().resolve() |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
654 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
|
655 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
|
656 path=dest_file |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
657 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
658 await self.host.confirm_or_quit(message, _("file download cancelled")) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
659 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
660 options = {} |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
661 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
662 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
663 download_data_s = await self.host.bridge.file_download( |
3926
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
664 data_format.serialise(attachment), |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
665 str(dest_file), |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
666 data_format.serialise(options), |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
667 self.profile, |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
668 ) |
3926
1877c5c477ec
cli (file/get): handle full JSON attachment following change in backend:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
669 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
|
670 except Exception as e: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
671 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
|
672 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
673 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
674 await self.got_id(download_data) |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
675 |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
676 |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
677 class Upload(base.CommandBase): |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
678 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
679 super(Upload, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
680 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
|
681 ) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
682 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
683 def add_parser_options(self): |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
684 self.parser.add_argument( |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
685 "-e", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
686 "--encrypt", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
687 action="store_true", |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
688 help=_("encrypt file using AES-GCM"), |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
689 ) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
690 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
|
691 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
692 "jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
693 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
694 help=_("jid of upload component (nothing to autodetect)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
695 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
696 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
697 "--ignore-tls-errors", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
698 action="store_true", |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
699 help=_(r"ignore invalide TLS certificate (/!\ Dangerous /!\)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
700 ) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
701 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
702 async def on_progress_started(self, metadata): |
3028 | 703 self.disp(_("File upload started"), 2) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
704 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
705 async def on_progress_finished(self, metadata): |
3028 | 706 self.disp(_("File uploaded successfully"), 2) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
707 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
708 url = metadata["url"] |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
709 except KeyError: |
3028 | 710 self.disp("download URL not found in metadata") |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
711 else: |
3028 | 712 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
|
713 # 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
|
714 self.disp(url) |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
715 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
716 async def on_progress_error(self, error_msg): |
3028 | 717 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
|
718 |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
719 async def got_id(self, data): |
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
720 """Called when a progress id has been received""" |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
721 try: |
3040 | 722 await self.set_progress_id(data["progress"]) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
723 except KeyError: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
724 if "xmlui" in data: |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
725 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
|
726 await ui.show() |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
727 else: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
728 self.disp(_("Can't upload file"), error=True) |
3040 | 729 self.host.quit(C.EXIT_ERROR) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
730 |
3040 | 731 async def start(self): |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
732 file_ = self.args.file |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
733 if not os.path.exists(file_): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
734 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
735 _("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
|
736 ) |
3040 | 737 self.host.quit(C.EXIT_BAD_ARG) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
738 if os.path.isdir(file_): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
739 self.disp(_("{file_} is a dir! Can't upload a dir").format(file_=repr(file_))) |
3040 | 740 self.host.quit(C.EXIT_BAD_ARG) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
741 |
3040 | 742 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
|
743 self.full_dest_jid = "" |
3040 | 744 else: |
745 self.full_dest_jid = await self.host.get_full_jid(self.args.jid) | |
746 | |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
747 options = {} |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
748 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
|
749 options["ignore_tls_errors"] = True |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
750 if self.args.encrypt: |
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
751 options["encryption"] = C.ENC_AES_GCM |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
752 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
753 path = os.path.abspath(file_) |
3040 | 754 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
755 upload_data = await self.host.bridge.file_upload( |
3040 | 756 path, |
757 "", | |
758 self.full_dest_jid, | |
3089
e75024e41f81
plugin upload, XEP-0363: code modernisation + preparation for extension:
Goffi <goffi@goffi.org>
parents:
3068
diff
changeset
|
759 data_format.serialise(options), |
3040 | 760 self.profile, |
761 ) | |
762 except Exception as e: | |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
763 self.disp(f"error while trying to upload a file: {e}", error=True) |
3040 | 764 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
765 else: | |
4233
d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
Goffi <goffi@goffi.org>
parents:
4225
diff
changeset
|
766 await self.got_id(upload_data) |
1643
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
767 |
17f9b911899a
jp (file): new file/upload command
Goffi <goffi@goffi.org>
parents:
1627
diff
changeset
|
768 |
3325
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
769 class ShareAffiliationsSet(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
770 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
771 super(ShareAffiliationsSet, self).__init__( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
772 host, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
773 "set", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
774 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
|
775 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
|
776 ) |
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 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
|
779 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
780 "-N", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
781 "--namespace", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
782 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
783 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
|
784 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
785 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
786 "-P", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
787 "--path", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
788 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
789 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
|
790 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
791 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
792 "-a", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
793 "--affiliation", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
794 dest="affiliations", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
795 metavar=("JID", "AFFILIATION"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
796 required=True, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
797 action="append", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
798 nargs=2, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
799 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
|
800 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
801 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
802 "jid", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
803 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
|
804 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
805 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
806 async def start(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
807 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
|
808 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
809 affiliations = await self.host.bridge.fis_affiliations_set( |
3325
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
810 self.args.jid, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
811 self.args.namespace, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
812 self.args.path, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
813 affiliations, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
814 self.profile, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
815 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
816 except Exception as e: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
817 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
|
818 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
|
819 else: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
820 self.host.quit() |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
821 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
822 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
823 class ShareAffiliationsGet(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
824 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
825 super(ShareAffiliationsGet, self).__init__( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
826 host, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
827 "get", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
828 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
|
829 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
|
830 ) |
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 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
|
833 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
834 "-N", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
835 "--namespace", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
836 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
837 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
|
838 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
839 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
840 "-P", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
841 "--path", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
842 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
843 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
|
844 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
845 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
846 "jid", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
847 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
|
848 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
849 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
850 async def start(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
851 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
852 affiliations = await self.host.bridge.fis_affiliations_get( |
3325
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
853 self.args.jid, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
854 self.args.namespace, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
855 self.args.path, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
856 self.profile, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
857 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
858 except Exception as e: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
859 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
|
860 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
|
861 else: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
862 await self.output(affiliations) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
863 self.host.quit() |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
864 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
865 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
866 class ShareAffiliations(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
867 subcommands = (ShareAffiliationsGet, ShareAffiliationsSet) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
868 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
869 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
870 super(ShareAffiliations, self).__init__( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
871 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
|
872 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
873 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
874 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
875 class ShareConfigurationSet(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
876 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
877 super(ShareConfigurationSet, self).__init__( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
878 host, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
879 "set", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
880 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
|
881 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
|
882 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
883 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
884 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
|
885 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
886 "-N", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
887 "--namespace", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
888 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
889 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
|
890 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
891 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
892 "-P", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
893 "--path", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
894 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
895 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
|
896 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
897 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
898 "-f", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
899 "--field", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
900 action="append", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
901 nargs=2, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
902 dest="fields", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
903 required=True, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
904 metavar=("KEY", "VALUE"), |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
905 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
|
906 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
907 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
908 "jid", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
909 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
|
910 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
911 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
912 async def start(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
913 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
|
914 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
915 configuration = await self.host.bridge.fis_configuration_set( |
3325
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
916 self.args.jid, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
917 self.args.namespace, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
918 self.args.path, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
919 configuration, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
920 self.profile, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
921 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
922 except Exception as e: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
923 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
|
924 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
|
925 else: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
926 self.host.quit() |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
927 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
928 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
929 class ShareConfigurationGet(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
930 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
931 super(ShareConfigurationGet, self).__init__( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
932 host, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
933 "get", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
934 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
|
935 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
|
936 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
937 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
938 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
|
939 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
940 "-N", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
941 "--namespace", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
942 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
943 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
|
944 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
945 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
946 "-P", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
947 "--path", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
948 default="", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
949 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
|
950 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
951 self.parser.add_argument( |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
952 "jid", |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
953 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
|
954 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
955 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
956 async def start(self): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
957 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
958 configuration = await self.host.bridge.fis_configuration_get( |
3325
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
959 self.args.jid, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
960 self.args.namespace, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
961 self.args.path, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
962 self.profile, |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
963 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
964 except Exception as e: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
965 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
|
966 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
|
967 else: |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
968 await self.output(configuration) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
969 self.host.quit() |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
970 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
971 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
972 class ShareConfiguration(base.CommandBase): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
973 subcommands = (ShareConfigurationGet, ShareConfigurationSet) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
974 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
975 def __init__(self, host): |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
976 super(ShareConfiguration, self).__init__( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
977 host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
978 "configuration", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
979 use_profile=False, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
980 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
|
981 ) |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
982 |
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
983 |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
984 class ShareList(base.CommandBase): |
817 | 985 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
986 extra_outputs = {"default": self.default_output} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
987 super(ShareList, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
988 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
989 "list", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
990 use_output=C.OUTPUT_LIST_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
991 extra_outputs=extra_outputs, |
3028 | 992 help=_("retrieve files shared by an entity"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
993 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
994 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
995 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
996 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
997 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
998 "-d", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
999 "--path", |
3028 | 1000 default="", |
1001 help=_("path to the directory containing the files"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1002 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1003 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1004 "jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1005 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1006 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1007 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
|
1008 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1009 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1010 def _name_filter(self, name, row): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1011 if row.type == C.FILE_TYPE_DIRECTORY: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1012 return A.color(C.A_DIRECTORY, name) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1013 elif row.type == C.FILE_TYPE_FILE: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1014 return A.color(C.A_FILE, name) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1015 else: |
3028 | 1016 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
|
1017 return name |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1018 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1019 def _size_filter(self, size, row): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1020 if not size: |
3028 | 1021 return "" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
1022 return A.color(A.BOLD, utils.get_human_size(size)) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1023 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1024 def default_output(self, files_data): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1025 """display files a way similar to ls""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1026 files_data.sort(key=lambda d: d["name"].lower()) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1027 show_header = False |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1028 if self.verbosity == 0: |
3040 | 1029 keys = headers = ("name", "type") |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1030 elif self.verbosity == 1: |
3040 | 1031 keys = headers = ("name", "type", "size") |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1032 elif self.verbosity > 1: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1033 show_header = True |
3040 | 1034 keys = ("name", "type", "size", "file_hash") |
3028 | 1035 headers = ("name", "type", "size", "hash") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
1036 table = common.Table.from_list_dict( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1037 self.host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1038 files_data, |
3040 | 1039 keys=keys, |
1040 headers=headers, | |
3028 | 1041 filters={"name": self._name_filter, "size": self._size_filter}, |
3040 | 1042 defaults={"size": "", "file_hash": ""}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1043 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1044 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
|
1045 |
3040 | 1046 async def start(self): |
1047 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
1048 files_data = await self.host.bridge.fis_list( |
3040 | 1049 self.args.jid, |
1050 self.args.path, | |
1051 {}, | |
1052 self.profile, | |
1053 ) | |
1054 except Exception as e: | |
1055 self.disp(f"can't retrieve shared files: {e}", error=True) | |
1056 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1057 |
3040 | 1058 await self.output(files_data) |
1059 self.host.quit() | |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1060 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1061 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1062 class SharePath(base.CommandBase): |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1063 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1064 super(SharePath, self).__init__( |
3028 | 1065 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
|
1066 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1067 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1068 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1069 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1070 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1071 "--name", |
3028 | 1072 default="", |
1073 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
|
1074 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1075 perm_group = self.parser.add_mutually_exclusive_group() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1076 perm_group.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1077 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1078 "--jid", |
3040 | 1079 metavar="JID", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1080 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1081 dest="jids", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1082 default=[], |
3028 | 1083 help=_("jid of contacts allowed to retrieve the files"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1084 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1085 perm_group.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1086 "--public", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1087 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1088 help=_( |
3040 | 1089 r"share publicly the file(s) (/!\ *everybody* will be able to access " |
1090 r"them)" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1091 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1092 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1093 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1094 "path", |
3028 | 1095 help=_("path to a file or directory to share"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1096 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1097 |
3040 | 1098 async def start(self): |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1099 self.path = os.path.abspath(self.args.path) |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1100 if self.args.public: |
3028 | 1101 access = {"read": {"type": "public"}} |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1102 else: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1103 jids = self.args.jids |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1104 if jids: |
3028 | 1105 access = {"read": {"type": "whitelist", "jids": jids}} |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1106 else: |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1107 access = {} |
3040 | 1108 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
1109 name = await self.host.bridge.fis_share_path( |
3040 | 1110 self.args.name, |
1111 self.path, | |
1112 json.dumps(access, ensure_ascii=False), | |
1113 self.profile, | |
1114 ) | |
1115 except Exception as e: | |
1116 self.disp(f"can't share path: {e}", error=True) | |
1117 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1118 else: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1119 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1120 _('{path} shared under the name "{name}"').format( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1121 path=self.path, name=name |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1122 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1123 ) |
3040 | 1124 self.host.quit() |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1125 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1126 |
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
|
1127 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
|
1128 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
|
1129 super(ShareInvite, self).__init__( |
3028 | 1130 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
|
1131 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1132 |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1133 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
|
1134 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
|
1135 "-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
|
1136 "--name", |
3028 | 1137 default="", |
1138 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
|
1139 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1140 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
|
1141 "-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
|
1142 "--namespace", |
3028 | 1143 default="", |
1144 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
|
1145 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1146 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
|
1147 "-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
|
1148 "--path", |
3028 | 1149 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
|
1150 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1151 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
|
1152 "-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
|
1153 "--type", |
3028 | 1154 choices=["files", "photos"], |
1155 default="files", | |
1156 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
|
1157 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1158 self.parser.add_argument( |
2932
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1159 "-T", |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1160 "--thumbnail", |
3028 | 1161 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
|
1162 ) |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1163 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
|
1164 "service", |
3028 | 1165 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
|
1166 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1167 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
|
1168 "jid", |
3028 | 1169 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
|
1170 ) |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1171 |
3040 | 1172 async def start(self): |
3028 | 1173 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
|
1174 extra = {} |
472fadadefe6
jp (file/invite): added a --thumbnail argument
Goffi <goffi@goffi.org>
parents:
2916
diff
changeset
|
1175 if self.args.thumbnail is not None: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1176 if not self.args.thumbnail.startswith("http"): |
3028 | 1177 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
|
1178 else: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1179 extra["thumb_url"] = self.args.thumbnail |
3040 | 1180 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3970
diff
changeset
|
1181 await self.host.bridge.fis_invite( |
3040 | 1182 self.args.jid, |
1183 self.args.service, | |
1184 self.args.type, | |
1185 self.args.namespace, | |
1186 self.path, | |
1187 self.args.name, | |
1188 data_format.serialise(extra), | |
1189 self.profile, | |
1190 ) | |
1191 except Exception as e: | |
1192 self.disp(f"can't send invitation: {e}", error=True) | |
1193 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1194 else: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1195 self.disp(_("invitation sent to {jid}").format(jid=self.args.jid)) |
3040 | 1196 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
|
1197 |
0b9faea5cb58
jp (file/share): added invite command to invite an entity to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1198 |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1199 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
|
1200 subcommands = ( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1201 ShareList, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1202 SharePath, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1203 ShareInvite, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1204 ShareAffiliations, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1205 ShareConfiguration, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3524
diff
changeset
|
1206 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1207 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1208 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1209 super(Share, self).__init__( |
3028 | 1210 host, "share", use_profile=False, help=_("files sharing management") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1211 ) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1212 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1213 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1214 class File(base.CommandBase): |
3094
c3cb18236bdf
jp (file): new `get` command + encryption with upload:
Goffi <goffi@goffi.org>
parents:
3089
diff
changeset
|
1215 subcommands = (Send, Request, Receive, Get, Upload, Share) |
2505
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1216 |
8e770ac05b0c
jp (file): file sharing + improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1217 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2592
diff
changeset
|
1218 super(File, self).__init__( |
3028 | 1219 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
|
1220 ) |