From 52a1a1138f772ddc927bd2f96ef4ca3c619766a2 Mon Sep 17 00:00:00 2001
From: Daniel STAN <daniel.stan@crans.org>
Date: Fri, 1 Jun 2012 21:30:32 +0200
Subject: [PATCH] ajout d'un pass

---
 cranspasswords.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/cranspasswords.py b/cranspasswords.py
index ce217e5..9354915 100755
--- a/cranspasswords.py
+++ b/cranspasswords.py
@@ -252,14 +252,21 @@ def show_file(fname):
         
 def edit_file(fname):
     value = get_file(fname)
+    nfile = False
     if value == False:
-        print "Fichier introuvable"; return
-    (sin,sout) = gpg('decrypt')
-    sin.write(value['contents'])
-    sin.close()
-    texte = sout.read()
+        nfile = True
+        print "Fichier introuvable"
+        if not confirm("Créer fichier ?"):
+            return
+        texte = ""
+        value = {'roles':get_my_roles()}
+    else:
+        (sin,sout) = gpg('decrypt')
+        sin.write(value['contents'])
+        sin.close()
+        texte = sout.read()
     ntexte = editor(texte)
-    if ntexte == None:
+    if ntexte == None and not nfile and NROLES != None:
         print "Pas de modifications effectuées"
     else:
         if put_password(fname,value['roles'],ntexte):
@@ -346,7 +353,7 @@ if __name__ == "__main__":
     action_grp = parser.add_mutually_exclusive_group(required=False)
     action_grp.add_argument('--edit',action='store_const',dest='action',
         default=show_file,const=edit_file,
-        help="Editer")
+        help="Editer (ou créer)")
     action_grp.add_argument('--view',action='store_const',dest='action',
         default=show_file,const=show_file,
         help="Voir")
-- 
GitLab