Subject: [PATCH] pglister: load_subscribers.py: don't wait for user input when there is nothing to commit

From: Célestin Matte <[email-masked]>
Date: Wed, 3 Nov 2021 20:01:37 +0100

-- 
Célestin Matte

From 05e778e77f3a33b66626bf3668eca4c899c22a0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <[email-masked]>
Date: Wed, 3 Nov 2021 10:56:41 +0100
Subject: [PATCH] load_subscribers.py: don't wait for user input when there is
 nothing to commit

---
 bin/load_subscribers.py | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/bin/load_subscribers.py b/bin/load_subscribers.py
index 2b894bf..62e2be1 100755
--- a/bin/load_subscribers.py
+++ b/bin/load_subscribers.py
@@ -104,15 +104,18 @@ if __name__ == "__main__":
         })
         newsub += curs.rowcount
 
-    while True:
-        r = input('Added %s subscribers, of which %s were new. Commit? ' % (newsub, newaddr)).strip().lower()
-        if r == 'y':
-            break
-        elif r == 'n':
-            print("OK, aborting")
-            conn.rollback()
-            sys.exit(1)
-    print("OK, committing")
-    conn.commit()
+    if newaddr > 0:
+        while True:
+            r = input('Added %s subscribers, of which %s were new. Commit? ' % (newsub, newaddr)).strip().lower()
+            if r == 'y':
+                break
+            elif r == 'n':
+                print("OK, aborting")
+                conn.rollback()
+                sys.exit(1)
+        print("OK, committing")
+        conn.commit()
+    else:
+        print("No new subscriber, nothing to do.")
     print("Done.")
     conn.close()
-- 
2.33.1

---

From: Magnus Hagander <[email-masked]>
Date: Thu, 4 Nov 2021 12:50:01 +0100

LGTM. Patch applied, thanks!

-- 
 Magnus Hagander
 Me: https://www.hagander.net/ <http://www.hagander.net/>
 Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/>