2024-10-10 17:36:37 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# coding: utf8
|
|
|
|
|
|
|
|
import pickle
|
|
|
|
import sys
|
|
|
|
|
|
|
|
contenu = {}
|
|
|
|
new = {}
|
|
|
|
statut = True
|
|
|
|
|
|
|
|
def charger(fic):
|
|
|
|
global contenu
|
|
|
|
try:
|
|
|
|
with open(fic, "rb") as fichier:
|
|
|
|
loader = pickle.Unpickler(fichier)
|
|
|
|
contenu = loader.load()
|
|
|
|
except:
|
|
|
|
contenu = {}
|
|
|
|
|
|
|
|
def sauver(fic):
|
|
|
|
with open(fic, "wb") as fichier:
|
|
|
|
saver = pickle.Pickler(fichier)
|
|
|
|
saver.dump(contenu)
|
|
|
|
|
|
|
|
if (len(sys.argv) is 4):
|
|
|
|
charger(sys.argv[1])
|
|
|
|
try:
|
|
|
|
for cle in contenu:
|
|
|
|
if (cle == sys.argv[2]):
|
|
|
|
print(cle)
|
|
|
|
new[sys.argv[3]] = contenu[cle]
|
|
|
|
else:
|
|
|
|
new[cle] = contenu[cle]
|
|
|
|
except Exception as err:
|
|
|
|
print(err)
|
|
|
|
statut = False
|
|
|
|
|
|
|
|
if (statut):
|
|
|
|
contenu = new
|
|
|
|
sauver(sys.argv[1])
|
|
|
|
else:
|
|
|
|
print("lecture.py <fichier> <salon_orig> <salon_dest>")
|