diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-07-05 17:05:17 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-07-05 17:05:17 +0200 |
commit | 4b0d9a2872050c704ad39c4228a7dc634ae29554 (patch) | |
tree | b8aa3ee4ff7b05fc5b999f439e254a8538a56a12 | |
parent | d11ea32f0b3194561b54ceeb98ce6ed91cc02803 (diff) | |
download | poezio-4b0d9a2872050c704ad39c4228a7dc634ae29554.tar.gz poezio-4b0d9a2872050c704ad39c4228a7dc634ae29554.tar.bz2 poezio-4b0d9a2872050c704ad39c4228a7dc634ae29554.tar.xz poezio-4b0d9a2872050c704ad39c4228a7dc634ae29554.zip |
Add the pipe_cmd plugin
This plugins lets the user manipulate a poezio instance by writing commands
into a pipe, read by poezio which will execute them.
-rw-r--r-- | plugins/pipe_cmd.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/plugins/pipe_cmd.py b/plugins/pipe_cmd.py new file mode 100644 index 00000000..c73bdea5 --- /dev/null +++ b/plugins/pipe_cmd.py @@ -0,0 +1,42 @@ +""" + +This plugins allows commands to be sent to poezio via a named pipe. + +""" + + +from plugin import BasePlugin +import threading +import os +import stat +import logging + +log = logging.getLogger(__name__) + +PIPENAME = "/tmp/poezio.fifo" + +class Plugin(BasePlugin): + def init(self): + self.stop = False + + self.pipename = self.config.get("pipename", PIPENAME) + + if not os.path.exists(self.pipename): + os.mkfifo(self.pipename) + + if not stat.S_ISFIFO(os.stat(self.pipename).st_mode): + log.error("File %s is not a fifo file" % self.pipename) + raise TypeError + + thread = threading.Thread(target=self.main_loop) + thread.start() + + def main_loop(self): + while not self.stop: + fd = open(self.pipename, 'r') + line = fd.read().strip() + self.api.run_command(line) + fd.close() + + def cleanup(self): + self.stop = True |