From b884908b75a1ab7983db4b2c01d180de78a21cc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Thu, 7 Apr 2022 23:49:37 +0200
Subject: [PATCH] shared: Jekyll import skip save images on dry run

---
 shared/jekyll_import.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/shared/jekyll_import.py b/shared/jekyll_import.py
index b092f214..a471ad35 100644
--- a/shared/jekyll_import.py
+++ b/shared/jekyll_import.py
@@ -120,7 +120,8 @@ def get_or_create_image(
     try:
         file = ImageFile(open(os.path.join(path, file_path), "rb"), name=file_path)
         image = Image(title=file_path, file=file, collection=collection)
-        image.save()
+        if not image_params["dry_run"]:
+            image.save()
         return image, ""
     except FileNotFoundError:
         pass  # cesta pomocí file_path neexisuje, jdeme dál
@@ -131,7 +132,8 @@ def get_or_create_image(
             name=file_path,
         )
         image = Image(title=file_path, file=file, collection=collection)
-        image.save()
+        if not image_params["dry_run"]:
+            image.save()
         return image, ""
     except FileNotFoundError:
         pass  # cesta s vložením "assets/img" před file_path neexisuje, jdeme dál
@@ -142,7 +144,8 @@ def get_or_create_image(
             name=file_path,
         )
         image = Image(title=file_path, file=file, collection=collection)
-        image.save()
+        if not image_params["dry_run"]:
+            image.save()
         return image, ""
     except FileNotFoundError:
         pass
@@ -183,7 +186,8 @@ def get_or_create_image(
     image = Image(title=file_path, file=file, collection=collection)
 
     try:
-        image.save()
+        if not image_params["dry_run"]:
+            image.save()
     except Exception as e:
         msg = "Nelze uložit obrázek"
         logger.warning(msg, extra={"exc": e})
@@ -320,6 +324,7 @@ class JekyllArticleImporter:
         image_params["path"] = self.path
         image_params["collection"] = self.collection
         image_params["repo_name"] = self.repo_name
+        image_params["dry_run"] = self.dry_run
 
     def create_redirects(self, article, match):
         y = match.group(1)
-- 
GitLab