diff --git a/gestion/affich_tools.py b/gestion/affich_tools.py index cf111474..59858d9d 100755 --- a/gestion/affich_tools.py +++ b/gestion/affich_tools.py @@ -129,16 +129,16 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None): titre : liste des titres Si none, n'affiche pas de ligne de titre - + largeur : liste des largeurs des colonnes, '*' met la plus grande largeur possible. Si None, réduit aux max chaque colonne - + alignement : liste des alignements : c = centrer g = gauche d = droit Si None, met c pour chaque colonne - + format : liste des formats : s = string o = octet Si None, s pour chaque colonne @@ -150,16 +150,16 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None): nbcols = len(titre) else : return u'Aucune donnée' - + # Formats ######### if not format : format = ['s'] * nbcols - + def reformate(data, format): if format == 's': return unicode(data) - + elif format == 'o' : data = float(data) if data > 1024**3: @@ -170,9 +170,9 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None): return str(round(data/1024, 1)) + 'ko' else: return str(round(data, 1)) + 'o' - + data = [ [ reformate(ligne[i],format[i]) for i in range(nbcols) ] for ligne in data ] - + # Largeurs ########## if not largeur : @@ -183,23 +183,23 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None): if largeur[i] in ['*',-1] : largeur[i] = max(cols - sum([l for l in largeur if l != '*']) - nbcols - 1, 3) break - + # Alignement ############ if not alignement : alignement = ['c'] * nbcols - + def aligne (data, alignement, largeur) : # Longeur sans les chaines de formatage l = len(re.sub('\x1b\[1;([0-9]|[0-9][0-9])m','',data)) - + # Alignement if l > largeur : # découpage d'une chaine trop longue regexp = re.compile('\x1b\[1;([0-9]|[0-9][0-9])m') new_data = u'' new_len = 0 - + # On laisse la mise en forme et on coupe les caratères affichés while True : s = regexp.search(data) @@ -217,21 +217,21 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None): data = data[1:] if not data : return new_data + '*' - + elif l == largeur : return data - + elif alignement == 'g' : return u' ' + data + u' '*(largeur-l-1) - + elif alignement == 'd' : return u' '*(largeur-l-1) + data + u' ' - + else : return u' '*((largeur-l)/2) + data + u' '*((largeur-l+1)/2) data = [ [ aligne(ligne[i],alignement[i],largeur[i]) for i in range(nbcols) ] for ligne in data ] - + # Le titre ########## if titre : @@ -245,14 +245,14 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None): # Les données ############# chaine += u'\n'.join([sep_col + sep_col.join([ligne[i] for i in range(nbcols)]) + sep_col for ligne in data]) - + return chaine def get_screen_size(): """Retourne la taille de l'écran. Sous la forme d'un tuble (lignes, colonnes)""" - + try: from termios import TIOCGWINSZ from struct import pack, unpack @@ -291,18 +291,18 @@ class anim : self.iter = iter sys.stdout.write(self.txt) sys.stdout.flush() - + def reinit(self) : - """ Efface la ligne courrante et + """ Efface la ligne courrante et affiche : truc................. """ sys.stdout.write(el + self.txt) if self.iter : sys.stdout.write(' '*28) sys.stdout.write(el + self.txt) sys.stdout.flush() - + def cycle(self) : - """ Efface la ligne courrante et + """ Efface la ligne courrante et affiche : truc..................? ? caratère variant à chaque appel """ sys.stdout.write(el + self.txt) diff --git a/gestion/gen_confs/switchs.py b/gestion/gen_confs/switchs.py index b911b853..b2cc258a 100755 --- a/gestion/gen_confs/switchs.py +++ b/gestion/gen_confs/switchs.py @@ -14,7 +14,7 @@ Dans tous les cas FAIRE LE SNMP A LA MAIN (script hpttols) """ -import string, sys, os, commands, smtplib +import string, sys, os, commands, smtplib, tempfile sys.path.append('/usr/scripts/gestion') from hptools import hpswitch, sw_chbre @@ -31,7 +31,7 @@ class switch(gen_config) : # Répertoire ou écire les fichiers de conf CONF_REP='/tmp/' # avec un / derrière - config = """; Configuration Editor; Created on release #H.08.86 + config = """%(switch_config_header)s hostname "%(switch)s" ;-------------------------------------------------------- Snmp @@ -253,6 +253,14 @@ exit # Batiment et numéro du switch bat = switch[3].lower() sw_num = int(switch[5]) + old_config = NamedTemporaryFile() + res, msg = commands.getstatusoutput("scp bat%s-%i:cfg/startup-config %s" % (bat, sw_num, old_config.name)) + + if not res: + raise RuntimeError(u"Erreur : impossible de récupérer l'ancienne configuration du switch") + + params['switch_config_header'] = old_config.readline() + old_config.close() # Conf radius sys.path.append('/usr/scripts/gestion/secrets')