diff --git a/cpasswords/client.py b/cpasswords/client.py index d214f493e58ca6c7040f7728f0de6ecaf82453bf..eb7eeda42fdf1620d577f5011755fcef14fce7c3 100755 --- a/cpasswords/client.py +++ b/cpasswords/client.py @@ -447,6 +447,41 @@ def show_file(options): if old_clipboard is not None: saveclipboard(restore=True, old_clipboard=old_clipboard) +@need_filename +def show_minimal(options): + """ + Action that decrypt file content and only prints the password + """ + fname = options.filename + gotit, value = get_file(options, fname) + if not gotit: + log.warn(value) # value contient le message d'erreur + return + passfile = value + content = passfile['contents'] + + # Kludge (broken db ?) + if type(content) == list: + log.warn("Eau dans le gaz") + content = content[-1] + + # Déchiffre le contenu + texte = decrypt(content) + + found = None + + # Essaie de planquer le mot de passe + for line in texte.split('\n'): + catch_pass = None + + if not found: + catch_pass = pass_regexp.match(line) + + if catch_pass is not None: + found = True + passwd = catch_pass.group(1) + break + print(passwd) @need_filename def edit_file(options): @@ -816,6 +851,13 @@ def main(): const=recrypt_files, help=_("recrypt all files having a role listed in --roles"), ) + action_grp.add_argument( + '--minimal', + action='store_const', + dest='action', + const=show_minimal, + help=_("just print the password in a file, for use in an external script."), + ) action_grp.set_defaults(action=show_file) # On parse les options fournies en commandline