2011-10-29 14:58:36 +00:00
|
|
|
|
#/usr/bin/env python3
|
2011-10-29 03:13:12 +00:00
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
"""
|
2011-10-29 14:58:36 +00:00
|
|
|
|
This file is a standalone program that reads commands on
|
|
|
|
|
stdin and executes them (each line should be a command).
|
2011-10-29 03:13:12 +00:00
|
|
|
|
|
2011-10-29 14:58:36 +00:00
|
|
|
|
Usage: cat some_fifo | ./daemon.py
|
2011-10-29 03:13:12 +00:00
|
|
|
|
|
2011-10-29 14:58:36 +00:00
|
|
|
|
Poezio writes commands in the fifo, and this daemon executes them on the
|
|
|
|
|
local machine.
|
2011-10-29 03:13:12 +00:00
|
|
|
|
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):
|
2011-10-29 14:58:36 +00:00
|
|
|
|
print('executing %s' % (self.command.strip(),))
|
2011-10-29 03:13:12 +00:00
|
|
|
|
subprocess.call(self.command.split())
|
|
|
|
|
|
2011-10-29 14:58:36 +00:00
|
|
|
|
def main():
|
2011-10-29 03:13:12 +00:00
|
|
|
|
while True:
|
2011-10-29 14:58:36 +00:00
|
|
|
|
line = sys.stdin.readline()
|
|
|
|
|
if line == '':
|
|
|
|
|
break
|
|
|
|
|
e = Executor(line)
|
|
|
|
|
e.start()
|
2011-10-29 03:13:12 +00:00
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2011-10-29 14:58:36 +00:00
|
|
|
|
main()
|