From 0629c9188d4fae9cbe4896b229e0e0b4fd6eb340 Mon Sep 17 00:00:00 2001 From: Rupus Reinefjord Date: Sun, 7 Jun 2020 22:40:54 +0200 Subject: [PATCH] Warn, don't crash, if not able to decrypt or empty file --- README.md | 3 ++- pass2csv.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c7c1bba..27ce3cc 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ optional arguments: strings to interpret as names of login fields (only used with -x) -u, --get-url match row starting with 'url:' and extract it (only used with -x) -e EXCLUDE_ROWS [EXCLUDE_ROWS ...], --exclude-rows EXCLUDE_ROWS [EXCLUDE_ROWS ...] - regexp strings to exclude from the notes field (only used with -x) + regexps to exclude from the notes field (only used with -x) + ``` diff --git a/pass2csv.py b/pass2csv.py index 8889478..69956a7 100755 --- a/pass2csv.py +++ b/pass2csv.py @@ -7,11 +7,13 @@ from argparse import ArgumentParser import gnupg +logger = logging.getLogger(__name__) + class CSVExporter(): def __init__(self, kpx_format, login_fields, get_url, exclude_rows): logging.basicConfig(level=logging.INFO) - self.logger = logging.getLogger(__name__) + self.logger = logger # Set to True to allow for alternate password csv to be created # See README for differences @@ -115,7 +117,7 @@ def main(gpgbinary, use_agent, pass_path, with open(file_path, 'rb') as f: data = str(gpg.decrypt_file(f)) if len(data) == 0: - raise ValueError("The password file is empty") + logger.warning("Could not decrypt %s or it is empty.", file_path) csv_data.append(exporter.parse(pass_path, file_path, data)) with open('pass.csv', 'w', newline='') as csv_file: