jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/558544 )

Change subject: [IMPR] Avoid deeply nested flow statements
......................................................................

[IMPR] Avoid deeply nested flow statements

- continue for loop for autoskip
- check newname directly instead of its length
- remove "else" after "break"

Change-Id: I064003e4f395e5485e48613b2b722e658dc7de4c
---
M scripts/imagecopy.py
1 file changed, 47 insertions(+), 45 deletions(-)

Approvals:
  D3r1ck01: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/imagecopy.py b/scripts/imagecopy.py
index b31c3db..efadd9e 100644
--- a/scripts/imagecopy.py
+++ b/scripts/imagecopy.py
@@ -526,60 +526,62 @@
         if not page.exists() or page.namespace() != 6 or page.isRedirectPage():
             continue

-        skip = False
         imagepage = pywikibot.FilePage(page.site, page.title())

         # First do autoskip.
         if doiskip(imagepage.get()):
             pywikibot.output('Skipping ' + page.title())
-            skip = True
+            continue
+
+        # The first upload is last in the list.
+        try:
+            username = imagepage.latest_file_info.user
+        except NotImplementedError:
+            # No API, using the page file instead
+            (datetime, username, resolution, size,
+             comment) = imagepage.get_file_history().pop()
+
+        skip = False
+        if always:
+            newname = imagepage.title(with_ns=False)
+            CommonsPage = pywikibot.Page(pywikibot.Site('commons',
+                                                        'commons'),
+                                         'File:' + newname)
+            if CommonsPage.exists():
+                continue
         else:
-            # The first upload is last in the list.
-            try:
-                username = imagepage.latest_file_info.user
-            except NotImplementedError:
-                # No API, using the page file instead
-                (datetime, username, resolution, size,
-                 comment) = imagepage.get_file_history().pop()
-            if always:
-                newname = imagepage.title(with_ns=False)
-                CommonsPage = pywikibot.Page(pywikibot.Site('commons',
-                                                            'commons'),
-                                             'File:' + newname)
-                if CommonsPage.exists():
-                    skip = True
-            else:
-                while True:
-                    # Do TkdialogIC to accept/reject and change the name
-                    newname, skip = TkdialogIC(
-                        imagepage.title(with_ns=False),
-                        imagepage.get(), username,
-                        imagepage.permalink(with_protocol=True),
-                        imagepage.templates()).getnewname()
+            while True:
+                # Do TkdialogIC to accept/reject and change the name
+                newname, skip = TkdialogIC(
+                    imagepage.title(with_ns=False),
+                    imagepage.get(), username,
+                    imagepage.permalink(with_protocol=True),
+                    imagepage.templates()).getnewname()

-                    if skip:
-                        pywikibot.output('Skipping this image')
-                        break
+                if skip:
+                    pywikibot.output('Skipping this image')
+                    break

-                    # Did we enter a new name?
-                    if len(newname) == 0:
-                        # Take the old name
-                        newname = imagepage.title(with_ns=False)
-                    else:
-                        newname = newname.decode('utf-8')
+                # Did we enter a new name?
+                if not newname:
+                    # Take the old name
+                    newname = imagepage.title(with_ns=False)
+                else:
+                    newname = newname.decode('utf-8')

-                    # Check if the image already exists
-                    CommonsPage = pywikibot.Page(
-                        imagepage.site.image_repository(),
-                        'File:' + newname)
-                    if not CommonsPage.exists():
-                        break
-                    else:
-                        pywikibot.output(
-                            'Image already exists, pick another name or '
-                            'skip this image')
-                    # We don't overwrite images, pick another name, go to
-                    # the start of the loop
+                # Check if the image already exists
+                CommonsPage = pywikibot.Page(
+                    imagepage.site.image_repository(),
+                    'File:' + newname)
+
+                if not CommonsPage.exists():
+                    break
+
+                pywikibot.output(
+                    'Image already exists, pick another name or '
+                    'skip this image')
+                # We don't overwrite images, pick another name, go to
+                # the start of the loop

         if not skip:
             imageTransfer(imagepage, newname, category,

--
To view, visit https://gerrit.wikimedia.org/r/558544
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I064003e4f395e5485e48613b2b722e658dc7de4c
Gerrit-Change-Number: 558544
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Dvorapa <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to