[gen_conf] stripping trailing whitespaces
darcs-hash:20090225185117-bd074-1c099460d115451d0adb95e5f873bde97b87317a.gz
This commit is contained in:
parent
95b51ff7e3
commit
dd6fb093d6
2 changed files with 39 additions and 41 deletions
|
@ -11,7 +11,7 @@ import sys, os, signal
|
|||
sys.path.append('/usr/scripts/gestion')
|
||||
|
||||
import time, commands
|
||||
from affich_tools import *
|
||||
from affich_tools import *
|
||||
from lock import *
|
||||
|
||||
import config
|
||||
|
@ -27,23 +27,23 @@ class gen_config :
|
|||
def lockname(self):
|
||||
"""Nom du lock"""
|
||||
return str(self.__class__)
|
||||
|
||||
|
||||
def lock(self) :
|
||||
""" Lock le service courant """
|
||||
if not self._locked :
|
||||
make_lock(self.lockname(),'')
|
||||
self._locked = 1
|
||||
|
||||
|
||||
def unlock(self) :
|
||||
""" Supression du lock """
|
||||
if self._locked : remove_lock(self.lockname())
|
||||
|
||||
|
||||
def __del__(self) :
|
||||
# Au cas où...
|
||||
self.unlock()
|
||||
|
||||
|
||||
def _restore(self) :
|
||||
""" Affichage d'une erreur et du traceback si debug
|
||||
""" Affichage d'une erreur et du traceback si debug
|
||||
Puis restauration des fichers """
|
||||
print ERREUR
|
||||
if self.debug :
|
||||
|
@ -52,53 +52,53 @@ class gen_config :
|
|||
# Restauration
|
||||
for nom, f in self.__restore.items() :
|
||||
os.system('cp -f %s %s' % ( f.name, nom ) )
|
||||
|
||||
|
||||
def _open_conf(self,nom,comment=None) :
|
||||
""" Créé un fichier
|
||||
si comment est fourni, insère une entète qui utilisera le caractère
|
||||
""" Créé un fichier
|
||||
si comment est fourni, insère une entète qui utilisera le caractère
|
||||
de commentaire fourni
|
||||
|
||||
|
||||
copie l'ancien fichier dans un fichier temporaire pour permettre
|
||||
la restauration en cas d'échec de la configuration
|
||||
|
||||
|
||||
Retourne le descripteur du fichier """
|
||||
|
||||
|
||||
f = NamedTemporaryFile()
|
||||
os.system('cp %s %s 2> /dev/null' % ( nom, f.name ) )
|
||||
self.__restore[nom] = f
|
||||
|
||||
|
||||
fd = open(nom, 'w')
|
||||
|
||||
|
||||
if comment :
|
||||
e = """***********************************************************
|
||||
Ce fichier est genere par les scripts de %s
|
||||
Les donnees proviennent de la base LDAP et de la conf
|
||||
Les donnees proviennent de la base LDAP et de la conf
|
||||
presente au debut du script.
|
||||
|
||||
|
||||
Generation : %s
|
||||
Fichier : %s
|
||||
|
||||
|
||||
NE PAS EDITER
|
||||
|
||||
***********************************************************""" % \
|
||||
(__name__, time.strftime('%A %d %B %Y %H:%M'), nom )
|
||||
|
||||
e = comment + e.replace('\n', '\n%s' % comment) + '\n'
|
||||
fd.write(e)
|
||||
fd.write(e)
|
||||
|
||||
return fd
|
||||
|
||||
|
||||
def gen_conf(self) :
|
||||
""" Génération des fichiers de conf, retourne False si erreur """
|
||||
self.lock()
|
||||
self.anim = anim('\tgénération fichiers')
|
||||
try :
|
||||
warn = self._gen()
|
||||
if warn :
|
||||
if warn :
|
||||
self.anim.reinit()
|
||||
print WARNING
|
||||
if self.debug : sys.stderr.write(warn.encode("ISO-8859-15"))
|
||||
else :
|
||||
else :
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
self.unlock()
|
||||
|
@ -108,7 +108,7 @@ class gen_config :
|
|||
self._restore()
|
||||
self.unlock()
|
||||
return False
|
||||
|
||||
|
||||
def restart(self) :
|
||||
""" Redémarrage du service concerné """
|
||||
if not self.restart_cmd : return
|
||||
|
@ -125,9 +125,9 @@ class gen_config :
|
|||
else :
|
||||
print OK
|
||||
self.unlock()
|
||||
|
||||
|
||||
def reconfigure(self) :
|
||||
""" Génère les fichiers puis redémarre le service
|
||||
""" Génère les fichiers puis redémarre le service
|
||||
si la génération c'est bien passée """
|
||||
cprint(u'Reconfiguration %s :' % self.__str__(), 'gras')
|
||||
if self.gen_conf() :
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue