summaryrefslogtreecommitdiff
path: root/src/daemon.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-11-09 01:23:35 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-11-09 01:23:35 +0100
commitad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f (patch)
tree3f2bbf1be7f753f1c7495f0a60833f469e7f10a7 /src/daemon.py
parent7fadb35fe2e7932a0a4aa6a8184ab6b186669edc (diff)
parent03999f1ef08036b7ea25e2239cf7b6bcdb4d76cc (diff)
downloadpoezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.tar.gz
poezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.tar.bz2
poezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.tar.xz
poezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.zip
Merge branch 'plugins'
Conflicts: README src/core.py src/tabs.py
Diffstat (limited to 'src/daemon.py')
-rwxr-xr-xsrc/daemon.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/daemon.py b/src/daemon.py
new file mode 100755
index 00000000..f23d6b5f
--- /dev/null
+++ b/src/daemon.py
@@ -0,0 +1,50 @@
+#/usr/bin/env python3
+# Copyright 2011 Florent Le Coz <louiz@louiz.org>
+#
+# This file is part of Poezio.
+#
+# Poezio is free software: you can redistribute it and/or modify
+# it under the terms of the zlib license. See the COPYING file.
+
+"""
+This file is a standalone program that reads commands on
+stdin and executes them (each line should be a command).
+
+Usage: cat some_fifo | ./daemon.py
+
+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.
+"""
+
+import sys
+import threading
+import subprocess
+
+class Executor(threading.Thread):
+ """
+ Just a class to execute commands in a thread.
+ This way, the execution can totally fail, we don’t care,
+ and we can start commands without having to wait for them
+ to return
+ """
+ def __init__(self, command):
+ threading.Thread.__init__(self)
+ self.command = command
+
+ def run(self):
+ print('executing %s' % (self.command.strip(),))
+ subprocess.call(self.command.split())
+
+def main():
+ while True:
+ line = sys.stdin.readline()
+ if line == '':
+ break
+ e = Executor(line)
+ e.start()
+
+if __name__ == '__main__':
+ main()