Mercurial > libervia-backend
comparison frontends/src/jp/jp @ 402:f03688bdb858
jp: use with statement to open fifo
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 07 Oct 2011 11:19:15 +0200 |
parents | b2caa2615c4c |
children | cf005701624b |
comparison
equal
deleted
inserted
replaced
401:b2caa2615c4c | 402:f03688bdb858 |
---|---|
16 GNU General Public License for more details. | 16 GNU General Public License for more details. |
17 | 17 |
18 You should have received a copy of the GNU General Public License | 18 You should have received a copy of the GNU General Public License |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | 20 """ |
21 | |
22 from __future__ import with_statement | |
21 | 23 |
22 #consts | 24 #consts |
23 name = u"jp" | 25 name = u"jp" |
24 about = name+u""" v%s (c) Jérôme Poisson (aka Goffi) 2009, 2010, 2011 | 26 about = name+u""" v%s (c) Jérôme Poisson (aka Goffi) 2009, 2010, 2011 |
25 | 27 |
208 """Create named pipe, and send stdin to it""" | 210 """Create named pipe, and send stdin to it""" |
209 tmp_dir = tempfile.mkdtemp() | 211 tmp_dir = tempfile.mkdtemp() |
210 fifopath = os.path.join(tmp_dir,"pipe_out") | 212 fifopath = os.path.join(tmp_dir,"pipe_out") |
211 os.mkfifo(fifopath) | 213 os.mkfifo(fifopath) |
212 self.bridge.pipeOut(self._getFullJid(self.dest_jid), fifopath, {}, profile_key=self.profile) | 214 self.bridge.pipeOut(self._getFullJid(self.dest_jid), fifopath, {}, profile_key=self.profile) |
213 f = open(fifopath, 'w+') | 215 with open(fifopath, 'w') as f: |
214 shutil.copyfileobj(sys.stdin, f) | 216 shutil.copyfileobj(sys.stdin, f) |
215 f.close() | |
216 shutil.rmtree(tmp_dir) | 217 shutil.rmtree(tmp_dir) |
217 | 218 |
218 | 219 |
219 def send_files(self): | 220 def send_files(self): |
220 """Send files to jabber contact""" | 221 """Send files to jabber contact""" |
294 tmp_dir = tempfile.mkdtemp() | 295 tmp_dir = tempfile.mkdtemp() |
295 fifopath = os.path.join(tmp_dir,"pipe_in") | 296 fifopath = os.path.join(tmp_dir,"pipe_in") |
296 answer_data["dest_path"] = fifopath | 297 answer_data["dest_path"] = fifopath |
297 os.mkfifo(fifopath) | 298 os.mkfifo(fifopath) |
298 self.bridge.confirmationAnswer(id, True, answer_data) | 299 self.bridge.confirmationAnswer(id, True, answer_data) |
299 f = open(fifopath, 'r') | 300 with open(fifopath, 'r') as f: |
300 shutil.copyfileobj(f, sys.stdout) | 301 shutil.copyfileobj(f, sys.stdout) |
301 f.close() | |
302 shutil.rmtree(tmp_dir) | 302 shutil.rmtree(tmp_dir) |
303 self.loop.quit() | 303 self.loop.quit() |
304 | 304 |
305 | 305 |
306 def actionResult(self, type, id, data): | 306 def actionResult(self, type, id, data): |