Export command to a contact (with video)

goffi 11 years ago projet GNU-Linux technique jabber-xmpp-en Libre SàT

G'day everybody,

I have made a small plugin for fun which export the input/outputs of an Unix command to a contact. The principle is really simple: you enter a command (so far it's not implemented in the frontends, so you'll have to directly use the D-Bus API, throught e.g. D-Feet or qdbus), then the contacts allowed to communicate with it, with options if necessary, and voilà !

There are 2 mains advantages by doing this:

the first one is that you can give access to an interpreter to any of your contacts (I'm doing this with FTP in the video, I have also made tests with bc, ipython or zsh), without using heavy tools like ssh which need to create an access account, a client, an opened port, etc. Of course, it's not elaborated, it's not a terminal, but it can help out. The escape sequences (what bring colors and others things in your interpreter) are not managed yet, and it can scramble your output (I had the case with ipython). I'm thinking about catching them, and convert to color with XHTML-IM (well, a first step would be that SàT manage XHTML-IM :p ).

the second one is to help to write bots really quickly: you just have to make a script with read stdin and react to it. You can make a bot in a couple of minutes with any scripting language (sh, Python, Ruby, etc) or others. And you can directly debug it from a terminal, without the need of an XMPP server to test it. To show you how easy it is, I have made a little test in Python, here what it looks like:

#!/usr/bin/python
#-*- coding: utf-8 -*-
import sys

class QuickBot(object):

    def out(self, msg):
        sys.stdout.write((u"%s\n" % msg).encode('utf-8'))
        sys.stdout.flush()

    def start(self):
        while(True):
            _input = raw_input().decode('utf-8','ignore')
            if _input.startswith('!'):
                args = _input[1:].split()
                try:
                    getattr(self, "cmd_%s" % args[0].encode('ascii').lower())(args[1:])
                except (IndexError, AttributeError, UnicodeEncodeError):
                    pass

    def cmd_salut(self, args):
        self.out(u"à Toi !")

if __name__ == "__main__":
    bot = QuickBot()
    bot.start()

The contact just have to enter !command [arguments] to make it do something (here !salut). To add a new command, you just have to create a new method named cmd_my_command, e.g. cmd_toto will add the command !toto. Easy isn't it ?

I have made a short video to show you this, it's in french but easy to understand even without sound, where I export a FTP server.

I have also made a small web widget for Libervia (it's not pushed on the repository yet). Of course it's limited (because of javascript security restrictions), but it allow to show whatever you want beside your conversations, and to enjoy Libervia's layout management (you'll can, for example, put 4 websites on a grid).

See you soon

As usual, to watch the video you can use a recent browser (the last Firefox/Iceweasel for example).
You can also use VLC (version >=1.1 only), by using the "Media/Open Netword Stream" menu and by entering this URL: http://www.goffi.org/videos/pr%c3%a9sentation_S%c3%a0T_6_export_commande.webm
Last but not least, you can use mplayer:: mplayer "http://www.goffi.org/videos/pr%c3%a9sentation_S%c3%a0T_6_export_commande.webm"

this video is licenced under Creative Common BY-SA