Commit a395d23b authored by Antoine Bernard's avatar Antoine Bernard
parents 610fd750 83a489fa
......@@ -365,6 +365,12 @@ def all_files(options):
"""Récupère les fichiers du serveur distant"""
return remote_command(options, "listfiles")
def restore_all_files(options):
"""Récupère les fichiers du serveur distant"""
return remote_command(options, "restorefiles")
def get_files(options, filenames):
"""Récupère le contenu des fichiers distants"""
return remote_command(options, "getfiles", stdin_contents=filenames)
......@@ -602,6 +608,16 @@ def show_files(options):
print((u" %s %s (%s)" % ((access and '+' or '-'), fname, ", ".join(froles))).encode("utf-8"))
print((u"""--Mes roles: %s""" % (", ".join(my_roles),)).encode("utf-8"))
def restore_files(options):
"""Restore les fichiers corrompues sur le serveur distant"""
print(u"Fichier corrompus :".encode("utf-8"))
files = restore_all_files(options)
keys = files.keys()
for fname in keys:
print((u" %s (%s)" % ( fname, files[fname])).encode("utf-8"))
def show_roles(options):
"""Affiche la liste des roles existants"""
print(u"Liste des roles disponibles".encode("utf-8"))
......@@ -985,6 +1001,9 @@ if __name__ == "__main__":
action_grp.add_argument('-l', '--list', action='store_const', dest='action',
default=show_file, const=show_files,
help="Lister les fichiers")
action_grp.add_argument('-r', '--restore', action='store_const', dest='action',
default=show_file, const=restore_files,
help="Restorer les fichiers corrompues")
action_grp.add_argument('--check-keys', action='store_const', dest='action',
default=show_file, const=my_check_keys,
help="Vérifier les clés")
......@@ -157,6 +157,37 @@ def listfiles():
files[fname] = file_dict["roles"]
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
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