untabify
darcs-hash:20050301153531-d1718-184bbeddcc246b5c917bde3ef2ff59a82099b4a4.gz
This commit is contained in:
parent
2748a74671
commit
cbe6f6619c
1 changed files with 83 additions and 83 deletions
|
@ -22,7 +22,7 @@ from tempfile import NamedTemporaryFile
|
|||
oid = '.1.3.6.1.4.1.2021.255'
|
||||
try :
|
||||
if sys.argv[1] == '-s' and sys.argv[2] == oid :
|
||||
service = sys.argv[4].strip().strip('"')
|
||||
service = sys.argv[4].strip().strip('"')
|
||||
except :
|
||||
None
|
||||
# Fin notes snmp
|
||||
|
@ -39,48 +39,48 @@ class gen_config :
|
|||
return str(self.__class__)
|
||||
|
||||
def lock(self) :
|
||||
""" Lock le service courant """
|
||||
if not self._locked :
|
||||
make_lock(self.lockname(),'')
|
||||
self._locked = 1
|
||||
|
||||
""" 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())
|
||||
""" Supression du lock """
|
||||
if self._locked : remove_lock(self.lockname())
|
||||
|
||||
def __del__(self) :
|
||||
# Au cas où...
|
||||
self.unlock()
|
||||
|
||||
# Au cas où...
|
||||
self.unlock()
|
||||
|
||||
def _restore(self) :
|
||||
""" Affichage d'une erreur et du traceback si debug
|
||||
Puis restauration des fichers """
|
||||
print ERREUR
|
||||
if self.debug :
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
# Restauration
|
||||
for nom, f in self.__restore.items() :
|
||||
os.system('cp -f %s %s' % ( f.name, nom ) )
|
||||
|
||||
""" Affichage d'une erreur et du traceback si debug
|
||||
Puis restauration des fichers """
|
||||
print ERREUR
|
||||
if self.debug :
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
# 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
|
||||
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 """
|
||||
""" 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 = """***********************************************************
|
||||
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 généré par les scripts de %s
|
||||
Les données proviennent de la base LDAP et de la conf
|
||||
présente au début du script.
|
||||
|
@ -93,53 +93,53 @@ class gen_config :
|
|||
***********************************************************""" % \
|
||||
(__name__, time.strftime('%A %d %B %Y %H:%M'), nom )
|
||||
|
||||
e = comment + e.replace('\n', '\n%s' % comment) + '\n'
|
||||
fd.write(e)
|
||||
e = comment + e.replace('\n', '\n%s' % comment) + '\n'
|
||||
fd.write(e)
|
||||
|
||||
return fd
|
||||
|
||||
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 :
|
||||
self.anim.reinit()
|
||||
print WARNING
|
||||
if self.debug : sys.stderr.write(warn.encode("ISO-8859-15"))
|
||||
else :
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
self.unlock()
|
||||
return True
|
||||
except :
|
||||
self.anim.reinit()
|
||||
self._restore()
|
||||
self.unlock()
|
||||
return False
|
||||
|
||||
""" 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 :
|
||||
self.anim.reinit()
|
||||
print WARNING
|
||||
if self.debug : sys.stderr.write(warn.encode("ISO-8859-15"))
|
||||
else :
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
self.unlock()
|
||||
return True
|
||||
except :
|
||||
self.anim.reinit()
|
||||
self._restore()
|
||||
self.unlock()
|
||||
return False
|
||||
|
||||
def restart(self) :
|
||||
""" Redémarrage du service concerné """
|
||||
if not self.restart_cmd : return
|
||||
self.lock()
|
||||
self.anim = anim('\trestart')
|
||||
status, output = commands.getstatusoutput(self.restart_cmd)
|
||||
if status :
|
||||
self.anim.reinit()
|
||||
print ERREUR
|
||||
if self.debug :
|
||||
sys.stderr.write(output+'\n')
|
||||
self.unlock()
|
||||
return 1
|
||||
else :
|
||||
print OK
|
||||
self.unlock()
|
||||
|
||||
""" Redémarrage du service concerné """
|
||||
if not self.restart_cmd : return
|
||||
self.lock()
|
||||
self.anim = anim('\trestart')
|
||||
status, output = commands.getstatusoutput(self.restart_cmd)
|
||||
if status :
|
||||
self.anim.reinit()
|
||||
print ERREUR
|
||||
if self.debug :
|
||||
sys.stderr.write(output+'\n')
|
||||
self.unlock()
|
||||
return 1
|
||||
else :
|
||||
print OK
|
||||
self.unlock()
|
||||
|
||||
def reconfigure(self) :
|
||||
""" Génère les fichiers puis redémarre le service
|
||||
si la génération c'est bien passée """
|
||||
cprint('Reconfiguration %s :' % self.__str__() , 'gras')
|
||||
if self.gen_conf() :
|
||||
return self.restart()
|
||||
else : return 1
|
||||
""" Génère les fichiers puis redémarre le service
|
||||
si la génération c'est bien passée """
|
||||
cprint('Reconfiguration %s :' % self.__str__() , 'gras')
|
||||
if self.gen_conf() :
|
||||
return self.restart()
|
||||
else : return 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue