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(): ...@@ -157,6 +157,37 @@ def listfiles():
files[fname] = file_dict["roles"] files[fname] = file_dict["roles"]
return files return files
def restorefiles():
"""Si un fichier a été corrompu, on restore son dernier backup valide"""
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==''):
line_dict = json.loads(line)
if ('-----BEGIN PGP MESSAGE-----' in line_dict["contents"]):
backup = line
line = f.readline()
if not (backup == ''):
files[fname] = 'restored'
with open(fname+'.json','w') as f2:
files[fname] = 'not restored'
return files
@server_command('getfile') @server_command('getfile')
def getfile(filename): def getfile(filename):
"""Récupère le fichier ``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