annotate sat_frontends/jp/cmd_file.py @ 3735:04ecc8eeb81a

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