diff options
author | Florent Le Coz <louiz@louiz.org> | 2011-10-29 05:11:30 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-10-29 05:11:30 +0200 |
commit | 7e16ffd9e0558b4895684c61f49059f7e603dc06 (patch) | |
tree | 336a14ae1c2196725b32a8e93403329519ea928e /src/core.py | |
parent | 5050d775d9e1f117766e721168c2f35f981d7146 (diff) | |
download | poezio-7e16ffd9e0558b4895684c61f49059f7e603dc06.tar.gz poezio-7e16ffd9e0558b4895684c61f49059f7e603dc06.tar.bz2 poezio-7e16ffd9e0558b4895684c61f49059f7e603dc06.tar.xz poezio-7e16ffd9e0558b4895684c61f49059f7e603dc06.zip |
Remote execution.
We can use a fifo to write command, and execute them on the local
machine by running a simple daemon.
Diffstat (limited to 'src/core.py')
-rw-r--r-- | src/core.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/core.py b/src/core.py index 41a54b23..2b305f21 100644 --- a/src/core.py +++ b/src/core.py @@ -49,6 +49,7 @@ from contact import Contact, Resource from text_buffer import TextBuffer from keyboard import read_char from theming import get_theme +from fifo import Fifo # http://xmpp.org/extensions/xep-0045.html#errorstatus ERROR_AND_STATUS_CODES = { @@ -94,6 +95,7 @@ class Core(object): sys.excepthook = self.on_exception self.running = True self.xmpp = singleton.Singleton(connection.Connection) + self.remote_fifo = None # a unique buffer used to store global informations # that are displayed in almost all tabs, in an # information window. @@ -1707,3 +1709,31 @@ class Core(object): return False self.current_tab().command_say(msg) return True + + def exec_command(self, command): + """ + Execute an external command on the local or a remote + machine, depending on the conf. For example, to open a link in a + browser, do exec_command("firefox http://poezio.eu"), + and this will call the command on the correct computer. + The remote execution is done by writing the command on a fifo. + That fifo has to be on the machine where poezio is running, and + accessible (through sshfs for example) from the local machine (where + poezio is not running). A very simple daemon reads on that fifo, + and executes any command that is read in it. + """ + if config.get('exec_remote', 'false') == 'true': + # We just write the command in the fifo + if not self.remote_fifo: + try: + self.remote_fifo = Fifo(os.path.join(config.get('remote_fifo_path', './'), 'poezio.fifo'), 'w') + except (OSError, IOError) as e: + self.information('Could not open fifo file for writing: %s' % (e,), 'Error') + return + try: + self.remote_fifo.write(command) + except (IOError) as e: + self.information('Could not execute [%s]: %s' % (command, e,), 'Error') + self.remote_fifo = None + else: + pass |