From 02df31759fca5fdb4b40850d14da397fc494f443 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Mon, 9 Sep 2019 17:23:24 +0100 Subject: [PATCH] Error on archive with same name already present --- maintenance/extract_data/extract_data.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/maintenance/extract_data/extract_data.py b/maintenance/extract_data/extract_data.py index 1b0b034a..666abc6a 100644 --- a/maintenance/extract_data/extract_data.py +++ b/maintenance/extract_data/extract_data.py @@ -10,6 +10,9 @@ import zipfile import psycopg2 +class ZipFileExistsError(Exception): + pass + def get_connection(): return psycopg2.connect( host=os.environ['PGHOST'], @@ -82,6 +85,9 @@ edit_history_query = read_sql('./export_edit_history.sql') def make_data_extract(current_time, connection, zip_file_path): + if zip_file_path.exists(): + raise ZipFileExistsError('Archive file under specified name already exists') + zip_file_path.parent.mkdir(parents=True, exist_ok=True) try: