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'
|
oid = '.1.3.6.1.4.1.2021.255'
|
||||||
try :
|
try :
|
||||||
if sys.argv[1] == '-s' and sys.argv[2] == oid :
|
if sys.argv[1] == '-s' and sys.argv[2] == oid :
|
||||||
service = sys.argv[4].strip().strip('"')
|
service = sys.argv[4].strip().strip('"')
|
||||||
except :
|
except :
|
||||||
None
|
None
|
||||||
# Fin notes snmp
|
# Fin notes snmp
|
||||||
|
@ -39,48 +39,48 @@ class gen_config :
|
||||||
return str(self.__class__)
|
return str(self.__class__)
|
||||||
|
|
||||||
def lock(self) :
|
def lock(self) :
|
||||||
""" Lock le service courant """
|
""" Lock le service courant """
|
||||||
if not self._locked :
|
if not self._locked :
|
||||||
make_lock(self.lockname(),'')
|
make_lock(self.lockname(),'')
|
||||||
self._locked = 1
|
self._locked = 1
|
||||||
|
|
||||||
def unlock(self) :
|
def unlock(self) :
|
||||||
""" Supression du lock """
|
""" Supression du lock """
|
||||||
if self._locked : remove_lock(self.lockname())
|
if self._locked : remove_lock(self.lockname())
|
||||||
|
|
||||||
def __del__(self) :
|
def __del__(self) :
|
||||||
# Au cas où...
|
# Au cas où...
|
||||||
self.unlock()
|
self.unlock()
|
||||||
|
|
||||||
def _restore(self) :
|
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 """
|
Puis restauration des fichers """
|
||||||
print ERREUR
|
print ERREUR
|
||||||
if self.debug :
|
if self.debug :
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
# Restauration
|
# Restauration
|
||||||
for nom, f in self.__restore.items() :
|
for nom, f in self.__restore.items() :
|
||||||
os.system('cp -f %s %s' % ( f.name, nom ) )
|
os.system('cp -f %s %s' % ( f.name, nom ) )
|
||||||
|
|
||||||
def _open_conf(self,nom,comment=None) :
|
def _open_conf(self,nom,comment=None) :
|
||||||
""" Créé un fichier
|
""" Créé un fichier
|
||||||
si comment est fourni, insère une entète qui utilisera le caractère
|
si comment est fourni, insère une entète qui utilisera le caractère
|
||||||
de commentaire fourni
|
de commentaire fourni
|
||||||
|
|
||||||
copie l'ancien fichier dans un fichier temporaire pour permettre
|
copie l'ancien fichier dans un fichier temporaire pour permettre
|
||||||
la restauration en cas d'échec de la configuration
|
la restauration en cas d'échec de la configuration
|
||||||
|
|
||||||
Retourne le descripteur du fichier """
|
Retourne le descripteur du fichier """
|
||||||
|
|
||||||
f = NamedTemporaryFile()
|
f = NamedTemporaryFile()
|
||||||
os.system('cp %s %s 2> /dev/null' % ( nom, f.name ) )
|
os.system('cp %s %s 2> /dev/null' % ( nom, f.name ) )
|
||||||
self.__restore[nom] = f
|
self.__restore[nom] = f
|
||||||
|
|
||||||
fd = open(nom, 'w')
|
fd = open(nom, 'w')
|
||||||
|
|
||||||
if comment :
|
if comment :
|
||||||
e = """***********************************************************
|
e = """***********************************************************
|
||||||
Ce fichier est généré par les scripts de %s
|
Ce fichier est généré par les scripts de %s
|
||||||
Les données proviennent de la base LDAP et de la conf
|
Les données proviennent de la base LDAP et de la conf
|
||||||
présente au début du script.
|
présente au début du script.
|
||||||
|
@ -93,53 +93,53 @@ class gen_config :
|
||||||
***********************************************************""" % \
|
***********************************************************""" % \
|
||||||
(__name__, time.strftime('%A %d %B %Y %H:%M'), nom )
|
(__name__, time.strftime('%A %d %B %Y %H:%M'), nom )
|
||||||
|
|
||||||
e = comment + e.replace('\n', '\n%s' % comment) + '\n'
|
e = comment + e.replace('\n', '\n%s' % comment) + '\n'
|
||||||
fd.write(e)
|
fd.write(e)
|
||||||
|
|
||||||
return fd
|
return fd
|
||||||
|
|
||||||
def gen_conf(self) :
|
def gen_conf(self) :
|
||||||
""" Génération des fichiers de conf, retourne False si erreur """
|
""" Génération des fichiers de conf, retourne False si erreur """
|
||||||
self.lock()
|
self.lock()
|
||||||
self.anim = anim('\tgénération fichiers')
|
self.anim = anim('\tgénération fichiers')
|
||||||
try :
|
try :
|
||||||
warn = self._gen()
|
warn = self._gen()
|
||||||
if warn :
|
if warn :
|
||||||
self.anim.reinit()
|
self.anim.reinit()
|
||||||
print WARNING
|
print WARNING
|
||||||
if self.debug : sys.stderr.write(warn.encode("ISO-8859-15"))
|
if self.debug : sys.stderr.write(warn.encode("ISO-8859-15"))
|
||||||
else :
|
else :
|
||||||
self.anim.reinit()
|
self.anim.reinit()
|
||||||
print OK
|
print OK
|
||||||
self.unlock()
|
self.unlock()
|
||||||
return True
|
return True
|
||||||
except :
|
except :
|
||||||
self.anim.reinit()
|
self.anim.reinit()
|
||||||
self._restore()
|
self._restore()
|
||||||
self.unlock()
|
self.unlock()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def restart(self) :
|
def restart(self) :
|
||||||
""" Redémarrage du service concerné """
|
""" Redémarrage du service concerné """
|
||||||
if not self.restart_cmd : return
|
if not self.restart_cmd : return
|
||||||
self.lock()
|
self.lock()
|
||||||
self.anim = anim('\trestart')
|
self.anim = anim('\trestart')
|
||||||
status, output = commands.getstatusoutput(self.restart_cmd)
|
status, output = commands.getstatusoutput(self.restart_cmd)
|
||||||
if status :
|
if status :
|
||||||
self.anim.reinit()
|
self.anim.reinit()
|
||||||
print ERREUR
|
print ERREUR
|
||||||
if self.debug :
|
if self.debug :
|
||||||
sys.stderr.write(output+'\n')
|
sys.stderr.write(output+'\n')
|
||||||
self.unlock()
|
self.unlock()
|
||||||
return 1
|
return 1
|
||||||
else :
|
else :
|
||||||
print OK
|
print OK
|
||||||
self.unlock()
|
self.unlock()
|
||||||
|
|
||||||
def reconfigure(self) :
|
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 """
|
si la génération c'est bien passée """
|
||||||
cprint('Reconfiguration %s :' % self.__str__() , 'gras')
|
cprint('Reconfiguration %s :' % self.__str__() , 'gras')
|
||||||
if self.gen_conf() :
|
if self.gen_conf() :
|
||||||
return self.restart()
|
return self.restart()
|
||||||
else : return 1
|
else : return 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue