comparison frontends/src/jp/cmd_pipe.py @ 1864:96ba685162f6

jp: all commands now use the new start method and set need_loop in __init__ when needed
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 16:52:51 +0100
parents d17772b0fe22
children 3e168cde7a7d
comparison
equal deleted inserted replaced
1863:b2ddd7f5dcdf 1864:96ba685162f6
34 34
35 class PipeOut(base.CommandBase): 35 class PipeOut(base.CommandBase):
36 36
37 def __init__(self, host): 37 def __init__(self, host):
38 super(PipeOut, self).__init__(host, 'out', help=_('send a pipe a stream')) 38 super(PipeOut, self).__init__(host, 'out', help=_('send a pipe a stream'))
39 self.need_loop = True
39 40
40 def add_parser_options(self): 41 def add_parser_options(self):
41 self.parser.add_argument("jid", type=base.unicode_decoder, help=_("the destination jid")) 42 self.parser.add_argument("jid", type=base.unicode_decoder, help=_("the destination jid"))
42 43
43 def pipe_out(self): 44 def start(self):
44 """ Create named pipe, and send stdin to it """ 45 """ Create named pipe, and send stdin to it """
46 # TODO: check_jids
45 tmp_dir = tempfile.mkdtemp() 47 tmp_dir = tempfile.mkdtemp()
46 fifopath = os.path.join(tmp_dir,"pipe_out") 48 fifopath = os.path.join(tmp_dir,"pipe_out")
47 os.mkfifo(fifopath) 49 os.mkfifo(fifopath)
48 self.host.bridge.pipeOut(self.host.get_full_jid(self.args.jid), fifopath, self.profile) 50 self.host.bridge.pipeOut(self.host.get_full_jid(self.args.jid), fifopath, self.profile)
49 with open(fifopath, 'w') as f: 51 with open(fifopath, 'w') as f:
50 shutil.copyfileobj(sys.stdin, f) 52 shutil.copyfileobj(sys.stdin, f)
51 shutil.rmtree(tmp_dir) 53 shutil.rmtree(tmp_dir)
52 self.host.quit() 54 self.host.quit()
53
54 def connected(self):
55 # TODO: check_jids
56 self.need_loop = True
57 super(PipeOut, self).connected()
58 self.pipe_out()
59 55
60 56
61 class PipeIn(base.CommandAnswering): 57 class PipeIn(base.CommandAnswering):
62 58
63 def __init__(self, host): 59 def __init__(self, host):
102 with open(fifopath, 'r') as f: 98 with open(fifopath, 'r') as f:
103 shutil.copyfileobj(f, sys.stdout) 99 shutil.copyfileobj(f, sys.stdout)
104 shutil.rmtree(tmp_dir) 100 shutil.rmtree(tmp_dir)
105 self.host.quit() 101 self.host.quit()
106 102
107 def run(self): 103 def start(self):
108 super(PipeIn, self).run()
109 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids] 104 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids]
110 105
111 106
112 class Pipe(base.CommandBase): 107 class Pipe(base.CommandBase):
113 subcommands = (PipeOut, PipeIn) 108 subcommands = (PipeOut, PipeIn)