From d608ccbd6d8d1d3dbbe8660d22b6a329df71da63 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sat, 29 Oct 2011 16:55:46 +0200 Subject: [PATCH 1/3] Remove the information() call in the link plugin --- plugins/link.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/link.py b/plugins/link.py index 0cd1a0f1..34f0a441 100644 --- a/plugins/link.py +++ b/plugins/link.py @@ -21,7 +21,6 @@ class Plugin(BasePlugin): for message in messages[::-1]: match = url_pattern.search(clean_text(message.txt)) if match: - self.core.information('[%s]' % (match.groups(),)) for url in list(match.groups())[::-1]: if nb == 1: return url From db1e84d34e910812d494673a1d78d85f38e2b725 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sat, 29 Oct 2011 16:58:36 +0200 Subject: [PATCH 2/3] Daemon now reads from a pipe and not in the fifo directly --- src/daemon.py | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/daemon.py b/src/daemon.py index a9d888f1..f23d6b5f 100755 --- a/src/daemon.py +++ b/src/daemon.py @@ -1,3 +1,4 @@ +#/usr/bin/env python3 # Copyright 2011 Florent Le Coz # # This file is part of Poezio. @@ -6,15 +7,13 @@ # it under the terms of the zlib license. See the COPYING file. """ -This file is a standalone program that creates a fifo file (if it doesn’t exist -yet), opens it for reading, reads commands from it and executes them (each line -should be a command). +This file is a standalone program that reads commands on +stdin and executes them (each line should be a command). -Usage: ./daemon.py +Usage: cat some_fifo | ./daemon.py -That fifo should be in a directory, shared through sshfs, with the remote -machine running poezio. Poezio then writes command in it, and this daemon -executes them on the local machine. +Poezio writes commands in the fifo, and this daemon executes them on the +local machine. Note that you should not start this daemon if you do not trust the remote machine that is running poezio, since this could make it run any (dangerous) command on your local machine. @@ -24,8 +23,6 @@ import sys import threading import subprocess -from fifo import Fifo - class Executor(threading.Thread): """ Just a class to execute commands in a thread. @@ -38,26 +35,16 @@ class Executor(threading.Thread): self.command = command def run(self): - print('executing %s' % (self.command,)) + print('executing %s' % (self.command.strip(),)) subprocess.call(self.command.split()) -def main(path): +def main(): while True: - fifo = Fifo(path, 'r') - while True: - line = fifo.readline() - if line == '': - del fifo - break - e = Executor(line) - e.start() - -def usage(): - print('Usage: %s ' % (sys.argv[0],)) + line = sys.stdin.readline() + if line == '': + break + e = Executor(line) + e.start() if __name__ == '__main__': - argc = len(sys.argv) - if argc != 2: - usage() - else: - main(sys.argv[1]) + main() From 21f0c8f3f348ca515b81208c73704d5fd7b10328 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sat, 29 Oct 2011 17:20:18 +0200 Subject: [PATCH 3/3] Fix the url matching in the link plugin --- plugins/link.py | 6 +++--- src/core.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/link.py b/plugins/link.py index 34f0a441..8ef52982 100644 --- a/plugins/link.py +++ b/plugins/link.py @@ -19,9 +19,9 @@ class Plugin(BasePlugin): if not messages: return None for message in messages[::-1]: - match = url_pattern.search(clean_text(message.txt)) - if match: - for url in list(match.groups())[::-1]: + matches = url_pattern.findall(clean_text(message.txt)) + if matches: + for url in matches[::-1]: if nb == 1: return url else: diff --git a/src/core.py b/src/core.py index 1fb06b38..88a726ea 100644 --- a/src/core.py +++ b/src/core.py @@ -1730,7 +1730,7 @@ class Core(object): try: self.remote_fifo.write(command) except (IOError) as e: - self.information('Could not execute [%s]: %s' % (command, e,), 'Error') + self.information('Could not execute [%s]: %s' % (command.strip(), e,), 'Error') self.remote_fifo = None else: pass