comparison frontends/src/jp/cmd_message.py @ 1828:cb4be663a4a7

jp (message): message is now a subcommand, and the sending command is moved to message/send
author Goffi <goffi@goffi.org>
date Fri, 22 Jan 2016 21:06:41 +0100
parents d17772b0fe22
children 96ba685162f6
comparison
equal deleted inserted replaced
1827:74014a9cc203 1828:cb4be663a4a7
23 from sat.tools.utils import clean_ustr 23 from sat.tools.utils import clean_ustr
24 24
25 __commands__ = ["Message"] 25 __commands__ = ["Message"]
26 26
27 27
28 class Message(base.CommandBase): 28 class Send(base.CommandBase):
29 29
30 def __init__(self, host): 30 def __init__(self, host):
31 super(Message, self).__init__(host, 'message', help=_('Send a message to a contact')) 31 super(Send, self).__init__(host, 'send', help=_('send a message to a contact'))
32 32
33 def add_parser_options(self): 33 def add_parser_options(self):
34 self.parser.add_argument("-s", "--separate", action="store_true", help=_("Separate xmpp messages: send one message per line instead of one message alone.")) 34 self.parser.add_argument("-s", "--separate", action="store_true", help=_("separate xmpp messages: send one message per line instead of one message alone."))
35 self.parser.add_argument("-n", "--new-line", action="store_true", help=_("Add a new line at the beginning of the input (usefull for ascii art ;))")) 35 self.parser.add_argument("-n", "--new-line", action="store_true", help=_("add a new line at the beginning of the input (usefull for ascii art ;))"))
36 self.parser.add_argument("jid", type=str, help=_("The destination jid")) 36 self.parser.add_argument("jid", type=str, help=_("the destination jid"))
37 37
38 def connected(self): 38 def connected(self):
39 super(Message, self).connected() 39 super(Send, self).connected()
40 jids = self.host.check_jids([self.args.jid]) 40 jids = self.host.check_jids([self.args.jid])
41 jid = jids[0] 41 jid = jids[0]
42 self.send_stdin(jid) 42 self.sendStdin(jid)
43 43
44 def send_stdin(self, dest_jid): 44 def sendStdin(self, dest_jid):
45 """Send incomming data on stdin to jabber contact 45 """Send incomming data on stdin to jabber contact
46 @param dest_jid: destination jid""" 46
47 @param dest_jid: destination jid
48 """
47 header = "\n" if self.args.new_line else "" 49 header = "\n" if self.args.new_line else ""
48 50
49 if self.args.separate: #we send stdin in several messages 51 if self.args.separate: #we send stdin in several messages
50 52
51 if header: 53 if header:
56 if not line: 58 if not line:
57 break 59 break
58 self.host.bridge.sendMessage(dest_jid, line.replace("\n",""), profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore) 60 self.host.bridge.sendMessage(dest_jid, line.replace("\n",""), profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore)
59 61
60 else: 62 else:
61 self.host.bridge.sendMessage(dest_jid, header + clean_ustr(u"".join([stream.decode('utf-8','ignore') for stream in sys.stdin.readlines()])), profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore) 63 msg = header + clean_ustr(u"".join([stream.decode('utf-8','ignore') for stream in sys.stdin.readlines()]))
64 self.host.bridge.sendMessage(dest_jid, msg, profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore)
65
66
67 class Message(base.CommandBase):
68 subcommands = (Send, )
69
70 def __init__(self, host):
71 super(Message, self).__init__(host, 'message', use_profile=False, help=_('messages handling'))