jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/587635 )

Change subject: [IMPR] Shorten the loop in add_text.py
......................................................................

[IMPR] Shorten the loop in add_text.py

- if putText is not True add_text function may return earlier
- in result the next if statement needs only to check whether
  text != newtext
- the while loop is only needed for 'b'rowser choice, so shorten
  the loop here too.

Change-Id: Ie5002dec8e23b15a78c8f6fd7b9351e3cfe0c09d
---
M scripts/add_text.py
1 file changed, 13 insertions(+), 12 deletions(-)

Approvals:
  Matěj Suchánek: Looks good to me, but someone else must approve
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/add_text.py b/scripts/add_text.py
index 43e80c3..7481198 100755
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -248,7 +248,12 @@
     else:
         newtext = addText + '\n' + text

-    if putText and text != newtext:
+    if not putText:
+        # If someone load it as module, maybe it's not so useful to put the
+        # text in the page
+        return (text, newtext, always)
+
+    if text != newtext:
         pywikibot.output(color_format(
             '\n\n>>> {lightpurple}{0}{default} <<<', page.title()))
         pywikibot.showDiff(text, newtext)
@@ -256,11 +261,6 @@
     # Let's put the changes.
     error_count = 0
     while True:
-        # If someone load it as module, maybe it's not so useful to put the
-        # text in the page
-        if not putText:
-            return (text, newtext, always)
-
         if not always:
             try:
                 choice = pywikibot.input_choice(
@@ -276,13 +276,14 @@
                 return (False, False, always)
             elif choice == 'b':
                 pywikibot.bot.open_webbrowser(page)
+                continue

-        if always or choice == 'y':
-            result = put_text(page, newtext, summary, error_count,
-                              asynchronous=not always)
-            if result is not None:
-                return (result, result, always)
-            error_count += 1
+        # either always or choice == 'y' is selected
+        result = put_text(page, newtext, summary, error_count,
+                          asynchronous=not always)
+        if result is not None:
+            return (result, result, always)
+        error_count += 1


 def main(*args):

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/587635
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie5002dec8e23b15a78c8f6fd7b9351e3cfe0c09d
Gerrit-Change-Number: 587635
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to