From 90c7849baad7ad900009d6f4c1324966c038682f Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 7 Jun 2022 19:04:20 +0200 Subject: [PATCH] Add flag to overwrite existing file when exporting records --- tasks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks.py b/tasks.py index e7600ae520..e643044d5d 100644 --- a/tasks.py +++ b/tasks.py @@ -282,8 +282,8 @@ def content_excludes(): return output -@task(help={'filename': "Output filename (default = 'data.json')"}) -def export_records(c, filename='data.json'): +@task(help={'filename': "Output filename (default = 'data.json')", 'overwrite': "Overwrite existing files without asking first (default False)"}) +def export_records(c, filename='data.json', overwrite = False): """Export all database records to a file""" # Get an absolute path to the file if not os.path.isabs(filename): @@ -292,7 +292,7 @@ def export_records(c, filename='data.json'): print(f"Exporting database records to file '{filename}'") - if os.path.exists(filename): + if os.path.exists(filename) and overwrite is False: response = input("Warning: file already exists. Do you want to overwrite? [y/N]: ") response = str(response).strip().lower()