#!/usr/bin/env python # -*- coding: utf-8 -*- # # sshmenu2sshplus.py # # Copyright 2012 manuel BERROCAL # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # """ Programme permettant de transformer un fichier de configuration de sshmenu vers un fichier de configuration de sshplus. Le résultat est affiché à l'écran et peut être redirigé vers un fichier. Le fichier de configuration de sshmenu est recherché dans ~/.sshmenu s'il n'est pas spécifié en argument au programme. """ import os, sys def writeinfos(info): """ Affiche et écrit les infos mises en forme """ print(info) def main(filemenu): """ Lecture du fichier .sshmenu et traitement des infos """ if not filemenu: filemenu = "/home/%s/.sshmenu" % os.environ['USER'] if not os.path.isfile(filemenu): print("File %s not found!\nExiting." % filemenu) sys.exit(1) sshmenu = open(filemenu, "r") # les ignes qui nous intéressent commences par "-" et se terminent par # la définition de la géométrie start_ = False deep = 0 for ligne in sshmenu: ligne = ligne.strip() # détermination des départs des sections if not len(ligne) == 0 and "- " in ligne[:2]: start_ = True if start_: if "- title:" in ligne: # c'est un sous dossier titre = ligne.split(':')[1].strip() if not deep == 0: # pas de dossier précédent existant la première fois, on # ne ferme donc pas le dossier précédent avant d'en # ouvrir un autre writeinfos("folder:") deep += 1 writeinfos("\nfolder:%s" % titre) start_ = False if "- sshparams:" in ligne: address = ligne.split(':')[1].strip() if "title:" in ligne: titre = ligne.split(':')[1].strip() if "profile:" in ligne: profile = ligne.split(':')[1].replace('"', '').strip() if not profile == '': profile = "--window-with-profile=%s" % profile if "geometry:" in ligne: geometry = ligne.split(':')[1].replace('"', '').strip() if not geometry == '': geometry = "--geometry=%s" % geometry start_ = False # fin de section, on envoie ça à l'écriture writeinfos("%s|gnome-terminal|-x ssh %s %s %s" % (titre, address, geometry, profile)) titre = "" address = "" geometry = "" profile = "" return 0 if __name__ == '__main__': main(sys.argv[1])