Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1328307?usp=email )

Change subject: nowcommons: Reuse file titles
......................................................................

nowcommons: Reuse file titles

Resolve the local and Commons display titles once while processing a file.
Reuse them for comparisons, messages, and replacement setup.

Change-Id: I1640295392871635152054b9c822388950b51078
---
M scripts/nowcommons.py
1 file changed, 11 insertions(+), 9 deletions(-)

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




diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index 04a21d5..cc8ad52 100755
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -290,28 +290,30 @@

         commons_file_page = pywikibot.FilePage(self.commons,
                                                'File:' + file_on_commons)
-        if (local_file_page.title(with_ns=False)
-                != commons_file_page.title(with_ns=False)):
+        local_title = local_file_page.title(with_ns=False)
+        commons_title = commons_file_page.title(with_ns=False)
+
+        if local_title != commons_title:
             using_pages = list(local_file_page.using_pages())

             if using_pages and using_pages != [local_file_page]:
                 pywikibot.info(
-                    f'"<<lightred>>{local_file_page.title(with_ns=False)}'
+                    f'"<<lightred>>{local_title}'
                     f'<<default>>" is still used in {len(using_pages)} pages.'
                 )

                 if self.opt.replace:
                     pywikibot.info(
                         'Replacing "<<lightred>>'
-                        f'{local_file_page.title(with_ns=False)}'
+                        f'{local_title}'
                         '<<default>>" by "<<lightgreen>>'
-                        f'{commons_file_page.title(with_ns=False)}'
+                        f'{commons_title}'
                         '<<default>>".'
                     )

                     bot = ImageBot(local_file_page.using_pages(),
-                                   local_file_page.title(with_ns=False),
-                                   commons_file_page.title(with_ns=False),
+                                   local_title,
+                                   commons_title,
                                    always=self.opt.replacealways,
                                    loose=self.opt.replaceloose)
                     bot.run()
@@ -322,7 +324,7 @@
                         bot = ImageBot(local_file_page.using_pages(),
                                        local_file_page.title(with_ns=False,
                                                              as_url=True),
-                                       commons_file_page.title(with_ns=False),
+                                       commons_title,
                                        always=self.opt.replacealways,
                                        loose=self.opt.replaceloose)
                         bot.run()
@@ -333,7 +335,7 @@

             pywikibot.info(
                 'No page is using "<<lightgreen>>'
-                f'{local_file_page.title(with_ns=False)}<<default>>" anymore.'
+                f'{local_title}<<default>>" anymore.'
             )

         try:

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

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I1640295392871635152054b9c822388950b51078
Gerrit-Change-Number: 1328307
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to