cli (message/send): new --attach argument to send an attachment:
rel 379
This commit is contained in:
parent
0f20af88f1
commit
d557e06fbd
1 changed files with 29 additions and 6 deletions
|
|
@ -17,14 +17,19 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from twisted.python import filepath
|
||||||
|
|
||||||
|
from sat.core.i18n import _
|
||||||
|
from sat.tools.common import data_format
|
||||||
|
from sat.tools.common.ansi import ANSI as A
|
||||||
|
from sat.tools.utils import clean_ustr
|
||||||
from sat_frontends.jp import base
|
from sat_frontends.jp import base
|
||||||
from sat_frontends.jp.constants import Const as C
|
from sat_frontends.jp.constants import Const as C
|
||||||
from sat_frontends.tools import jid
|
from sat_frontends.tools import jid
|
||||||
from sat.core.i18n import _
|
|
||||||
from sat.tools.utils import clean_ustr
|
|
||||||
from sat.tools.common import data_format
|
|
||||||
from sat.tools.common.ansi import ANSI as A
|
|
||||||
|
|
||||||
__commands__ = ["Message"]
|
__commands__ = ["Message"]
|
||||||
|
|
||||||
|
|
@ -51,7 +56,7 @@ class Send(base.CommandBase):
|
||||||
"--new-line",
|
"--new-line",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help=_(
|
help=_(
|
||||||
"add a new line at the beginning of the input (usefull for ascii art ;))"
|
"add a new line at the beginning of the input"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
self.parser.add_argument(
|
self.parser.add_argument(
|
||||||
|
|
@ -75,6 +80,10 @@ class Send(base.CommandBase):
|
||||||
"--encrypt-noreplace",
|
"--encrypt-noreplace",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help=_("don't replace encryption algorithm if an other one is already used"))
|
help=_("don't replace encryption algorithm if an other one is already used"))
|
||||||
|
self.parser.add_argument(
|
||||||
|
"-a", "--attach", dest="attachments", action="append", metavar="FILE_PATH",
|
||||||
|
help=_("add a file as an attachment")
|
||||||
|
)
|
||||||
syntax = self.parser.add_mutually_exclusive_group()
|
syntax = self.parser.add_mutually_exclusive_group()
|
||||||
syntax.add_argument("-x", "--xhtml", action="store_true", help=_("XHTML body"))
|
syntax.add_argument("-x", "--xhtml", action="store_true", help=_("XHTML body"))
|
||||||
syntax.add_argument("-r", "--rich", action="store_true", help=_("rich body"))
|
syntax.add_argument("-r", "--rich", action="store_true", help=_("rich body"))
|
||||||
|
|
@ -135,7 +144,21 @@ class Send(base.CommandBase):
|
||||||
msg = {}
|
msg = {}
|
||||||
to_send.append(msg)
|
to_send.append(msg)
|
||||||
|
|
||||||
for msg in to_send:
|
if self.args.attachments:
|
||||||
|
attachments = extra[C.MESS_KEY_ATTACHMENTS] = []
|
||||||
|
for attachment in self.args.attachments:
|
||||||
|
try:
|
||||||
|
file_path = str(Path(attachment).resolve(strict=True))
|
||||||
|
except FileNotFoundError:
|
||||||
|
self.disp("file {attachment} doesn't exists, ignoring", error=True)
|
||||||
|
else:
|
||||||
|
attachments.append({"path": file_path})
|
||||||
|
|
||||||
|
for idx, msg in enumerate(to_send):
|
||||||
|
if idx > 0 and C.MESS_KEY_ATTACHMENTS in extra:
|
||||||
|
# if we send several messages, we only want to send attachments with the
|
||||||
|
# first one
|
||||||
|
del extra[C.MESS_KEY_ATTACHMENTS]
|
||||||
try:
|
try:
|
||||||
await self.host.bridge.messageSend(
|
await self.host.bridge.messageSend(
|
||||||
dest_jid,
|
dest_jid,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue