Warn, don't crash, if not able to decrypt or empty file

This commit is contained in:
Rupus Reinefjord 2020-06-07 22:40:54 +02:00
parent 59e9ec30ef
commit 0629c9188d
2 changed files with 6 additions and 3 deletions

View file

@ -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)
```

View file

@ -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: