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

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

[IMPR] Avoid deeply nested flow statements

continue loop instead of indenting if-statement

Change-Id: I5f2ca921203119174fc094a0d9b5d8a965e6ffb3
---
M scripts/imagecopy.py
1 file changed, 54 insertions(+), 53 deletions(-)

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



diff --git a/scripts/imagecopy.py b/scripts/imagecopy.py
index 07e819a..b31c3db 100644
--- a/scripts/imagecopy.py
+++ b/scripts/imagecopy.py
@@ -523,66 +523,67 @@
     load_global_archivo()

     for page in pregenerator:
+        if not page.exists() or page.namespace() != 6 or page.isRedirectPage():
+            continue
+
         skip = False
-        if page.exists() and page.namespace() == 6 \
-           and not page.isRedirectPage():
-            imagepage = pywikibot.FilePage(page.site, page.title())
+        imagepage = pywikibot.FilePage(page.site, page.title())

-            # First do autoskip.
-            if doiskip(imagepage.get()):
-                pywikibot.output('Skipping ' + page.title())
-                skip = True
+        # First do autoskip.
+        if doiskip(imagepage.get()):
+            pywikibot.output('Skipping ' + page.title())
+            skip = True
+        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:
-                # 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 len(newname) == 0:
+                        # 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
+                    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

-            if not skip:
-                imageTransfer(imagepage, newname, category,
-                              delete_after_done).start()
+        if not skip:
+            imageTransfer(imagepage, newname, category,
+                          delete_after_done).start()

     pywikibot.output('Still ' + str(threading.activeCount())
                      + ' active threads, lets wait')

--
To view, visit https://gerrit.wikimedia.org/r/558542
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: I5f2ca921203119174fc094a0d9b5d8a965e6ffb3
Gerrit-Change-Number: 558542
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