annotate libervia/cli/cmd_file.py @ 4306:94e0968987cd

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