#!/usr/bin/env python """ Convert a SSHMenu configuration found in ~/.sshmenu to Remmina host configuration snippets in ~/.remmina. The folder structure is created within a "SSHMenu" folder. Remmina must be restarted after running this script. The "geometry" and "profile" parameters are dropped as these aren't configurable in Remmina. The "sshparams" parameter is split into a host and a command part. This script creates Remmina configuration files with a "sshmenu_" prefix. If you want to get rid of them, just run "rm ~/.remmina/sshmenu_*.remmina" and restart Remmina again. As you can see, this script is fairly simple. Please read the code before using it to make sure it will do what you want. Tested with SSHMenu 3.18 and Remmina 0.9.3. 2011-09-17 Ulf Rompe http://rompe.net/ """ __revision__ = "$Revision: 4 $" __id__ = "$Id: sshmenu_to_remmina.py 4 2011-09-17 15:46:11Z ulf $" __author__ = "Ulf Rompe" __date__ = "2011-09-17" import logging import os import re import tempfile import yaml def handle_items(folder, items): """ Handle a list of items. """ for item in items: if item["type"] == "menu": handle_items(folder + '/' + item["title"], item["items"]) elif item["type"] == "host": write_remmina_config(folder=folder, title=item["title"], sshparams=item["sshparams"]) def write_remmina_config(folder, title, sshparams): """ Write a Remmina configuration snippet. """ rex = "(-\S+\s+)*(([\w._-]+)@)?([\w._-]+)([\s]+\"?(-\S+\s+)*([^\"]+))*\"?$" match = re.match(rex, sshparams) if match is None: logging.warning("Couldn't find hostname in params for %s: %s", title, sshparams) return user = match.group(3) or "" host = match.group(4) command = match.group(7) or "" snippet = """ [remmina] ssh_auth=2 ssh_charset= ssh_privatekey= group=%s password= name=%s ssh_username=%s exec=%s ssh_server= protocol=SSH ssh_enabled=1 server=%s window_maximize=1 scale=0 viewmode=1""" % (folder, title, user, command, host) remmina_dir = os.path.join(os.path.expanduser("~"), ".remmina") with tempfile.NamedTemporaryFile(suffix=".remmina", prefix="sshmenu_", dir=remmina_dir, delete=False) as outfile: outfile.write(snippet) logging.info("Created %s for %s.", outfile.name, title) if __name__ == "__main__": logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") config = yaml.safe_load(open(os.path.join(os.path.expanduser("~"), ".sshmenu")).read()) handle_items("SSHMenu", config["items"])