Commit 5b8b19fe authored by Charlie Jacomme's avatar Charlie Jacomme

[server] Ajout d'une fonction de restoration des fichiers corrompus

parent 41083f88
......@@ -157,6 +157,37 @@ def listfiles():
files[fname] = file_dict["roles"]
return files
@server_command('restorefiles')
def restorefiles():
"""Si un fichier a été corrompu, on restore son dernier backup valide"""
os.chdir(serverconfig.STORE)
filenames = glob.glob('*.json')
files = {}
for filename in filenames:
file_dict = json.loads(open(filename).read())
if not ('-----BEGIN PGP MESSAGE-----' in file_dict["contents"]):
fname = filename[:-5].decode('utf-8')
with open(fname+'.bak') as f:
line = f.readline()
backup = ''
while not (line==''):
try:
line_dict = json.loads(line)
if ('-----BEGIN PGP MESSAGE-----' in line_dict["contents"]):
backup = line
except:
pass
line = f.readline()
if not (backup == ''):
files[fname] = 'restored'
with open(fname+'.json','w') as f2:
f2.write(backup)
else:
files[fname] = 'not restored'
return files
@server_command('getfile')
def getfile(filename):
"""Récupère le fichier ``filename``"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment