diff options
author | Florent Le Coz <louiz@louiz.org> | 2011-10-29 05:21:27 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-10-29 05:21:27 +0200 |
commit | afcc3870021ddfda19fdee5069349ed8e929a077 (patch) | |
tree | e766bfb168fde098ed6a7eaf322bad511ec6695a /src/core.py | |
parent | 5050d775d9e1f117766e721168c2f35f981d7146 (diff) | |
parent | f8fcf6696d0044817d596e7d09dcbdcc8a52aac6 (diff) | |
download | poezio-afcc3870021ddfda19fdee5069349ed8e929a077.tar.gz poezio-afcc3870021ddfda19fdee5069349ed8e929a077.tar.bz2 poezio-afcc3870021ddfda19fdee5069349ed8e929a077.tar.xz poezio-afcc3870021ddfda19fdee5069349ed8e929a077.zip |
Merge branch 'remote_exec' into plugins
Diffstat (limited to 'src/core.py')
-rw-r--r-- | src/core.py | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/core.py b/src/core.py index 41a54b23..712eed62 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. @@ -157,7 +159,6 @@ class Core(object): 'M-z': self.go_to_previous_tab, '^L': self.full_screen_redraw, 'M-j': self.go_to_room_number, -# 'M-c': self.coucou, } # Add handlers @@ -191,9 +192,6 @@ class Core(object): for plugin in plugins.split(): self.plugin_manager.load(plugin) - def coucou(self): - self.command_pubsub('pubsub.louiz.org') - def start(self): """ Init curses, create the first tab, etc @@ -1707,3 +1705,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 |