Import initial !
darcs-hash:20040831131446-d1718-0734aa73d3b8481b3b4b861e447e85128e488e8a.gz
This commit is contained in:
parent
c9083dfd86
commit
6626a44f15
20 changed files with 6494 additions and 0 deletions
69
gestion/secours.py
Executable file
69
gestion/secours.py
Executable file
|
@ -0,0 +1,69 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
|
||||
# Fichiers à modifier et chaine indiquant un commentaire dans ceux-ci
|
||||
fichiers = { '/etc/bind/named.conf.options' : '//' ,
|
||||
'/etc/postfix/main.cf' : '#' }
|
||||
|
||||
import sys, sre
|
||||
|
||||
def edit(file,comment,secours) :
|
||||
""" Edite le fichier fourni en commentant (mode normal)
|
||||
ou décommentant (mode secours) les lignes se terminant avec #POUR SECOURS """
|
||||
|
||||
signal = '#POUR SECOURS'
|
||||
l = len(signal)
|
||||
|
||||
fd = open(file)
|
||||
line = fd.readline()
|
||||
new = ''
|
||||
while line :
|
||||
l = line.rstrip()
|
||||
if sre.match('.*'+signal+'$',l) :
|
||||
# Ligne pour secours
|
||||
if not sre.match('^' + comment,l) and not secours:
|
||||
# On est actuellement configuré en secours
|
||||
# Il faut passer en normal
|
||||
new += comment + line
|
||||
elif sre.match('^' + comment,l) and secours :
|
||||
# On est actuellement configuré en normal
|
||||
# Il faut passer en secours
|
||||
new += line.replace(comment,'',1)
|
||||
else :
|
||||
# Rien à faire, on est bien configuré
|
||||
new += line
|
||||
else :
|
||||
# Ligne normale
|
||||
new += line
|
||||
|
||||
line = fd.readline()
|
||||
|
||||
fd.close()
|
||||
|
||||
# Ecriture de la nouvelle version
|
||||
fd = open(file,'w')
|
||||
fd.write(new)
|
||||
fd.close()
|
||||
|
||||
|
||||
def usage() :
|
||||
print 'Usage : %s 0 pour reconfigurer les services locaux en normal' % sys.argv[0]
|
||||
print ' %s 1 pour reconfigurer les services locaux en secours' % sys.argv[0]
|
||||
print 'Fichiers modifiés par le changement de mode : \n\t', '\n\t'.join(fichiers.keys())
|
||||
|
||||
if __name__ == '__main__' :
|
||||
if len(sys.argv) != 2 :
|
||||
usage()
|
||||
else :
|
||||
mode = sys.argv[1]
|
||||
if mode not in '01' :
|
||||
usage()
|
||||
else :
|
||||
mode = int(mode)
|
||||
for f, c in fichiers.items() :
|
||||
try :
|
||||
print 'Edition de %s' % f
|
||||
edit(f,c,mode)
|
||||
except :
|
||||
import traceback
|
||||
traceback.print_exc()
|
Loading…
Add table
Add a link
Reference in a new issue