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