import os.path #Methodes ============================================================== def MDP(ligne): print "!!! decouverte du mot de passe !!!" contenu = ligne.replace("TheMDP","drup@@CDS") print "ecriture ..." cible.write(contenu) print "OK" trouvaille.append(fichier[j] + " = MDP") def root(ligne): print "! decouverte du mot root !" print "ecriture ..." cible.write(ligne) trouvaille.append(fichier[j] + " = root") print "OK" def adresse(ligne): print "!! decouverte de l'ancienne adresse !!" print "ecriture ..." contenu = ligne.replace("10.0.0.5","ncdsgit.u-strasbg.fr") cible.write(contenu) trouvaille.append(fichier[j] + " = adresse") print "OK" def mail(ligne): print " decouverte de l'adresse mail " print "ecriture ..." cible.write(ligne) trouvaille.append(fichier[j] + " = mail") print "OK" #======================================================================== if not os.path.exists("Transfert"): os.makedirs("Transfert") #creation du dossier trouvaille=[] dossier=[] fichier=[] path="Convoi" for root, dirs, files in os.walk(path): for i in files: dossier.append(os.path.join(root)) fichier.append(os.path.join(root, i)) for j in range(len(fichier)): #{ boucle qui lit if not os.path.exists("Transfert/" + dossier[j]): print "creation du dossier " + dossier[j] + " ..." os.makedirs("Transfert/" + dossier[j]) print "OK" print "Converion de " + fichier[j] + " ..." creation = open("Transfert/"+fichier[j], 'w') creation.close cible = open("Transfert/"+fichier[j], 'a') print "OK" print "lecture du fichier "+fichier[j] + " ..." source = open(fichier[j]) numero = 0 while True: #{ line = source.readline() if line == "": #ici, il n'y a plus de ligne, on sort de la boucle print "lignes totales : ",numero print "=== Fin du document ===" break #ici, il y a une ligne numero = numero+1 print "Lecture de la ligne ",numero, ":" if "TheMDP" in line: MDP(line) elif "root" in line: root(line) elif "10.0.0.5" in line: adresse(line) elif "contact@ovfrance.fr" in line: mail(line) else: print "ecriture ..." cible.write(line) print "OK" #} source.close() cible.close() #} for f in trouvaille: print f