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