Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/112322

Change subject: (bugfix) follow-up for 
https://gerrit.wikimedia.org/r/#/c/112195/
......................................................................

(bugfix) follow-up for https://gerrit.wikimedia.org/r/#/c/112195/

Since the last committ we use Site.fromDBName() to get the the site
code instead extracting them directly. Site.fromDBName() creates a
site object and this may fail with NoSuchSite exception if the
dbname returned by wikidata is a obsolete site. Unfortunately
that may occur.

In this case we can no longer test against that exception outside
generator because the site object is already been created but we
must check it inside the generator. This is impossible for
generator expressions. We need a generator method instead.

Change-Id: I990b0d65909fe9f2adfec96a270b88bb62336360
---
M scripts/featured.py
1 file changed, 20 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/22/112322/1

diff --git a/scripts/featured.py b/scripts/featured.py
index 9db0162..5277e53 100644
--- a/scripts/featured.py
+++ b/scripts/featured.py
@@ -242,19 +242,27 @@
 
     def itercode(self, task):
         """ generator for site codes to be processed """
-        if task == 'good':
-            item_no = good_name['wikidata'][1]
-        elif task == 'featured':
-            item_no = featured_name['wikidata'][1]
-        elif task == 'former':
-            item_no = former_name['wikidata'][1]
-        dp = pywikibot.ItemPage(self.site.data_repository(), item_no)
-        dp.get()
 
-        generator = (site.code for site in
-                     sorted([self.site.fromDBName(key)
-                             for key in dp.sitelinks.keys()])
-                     if site.family == self.site.family)  # wikipedia sites 
only
+        def _generator():
+            if task == 'good':
+                item_no = good_name['wikidata'][1]
+            elif task == 'featured':
+                item_no = featured_name['wikidata'][1]
+            elif task == 'former':
+                item_no = former_name['wikidata'][1]
+            dp = pywikibot.ItemPage(self.site.data_repository(), item_no)
+            dp.get()
+            for key in dp.sitelinks.keys():
+                try:
+                    site = self.site.fromDBName(key)
+                except pywikibot.NoSuchSite:
+                    pywikibot.output('"%s" is not a valid site. Skipping...'
+                                     % key)
+                else:
+                    if site.family == self.site.family:
+                        yield site.code
+
+        generator = _generator()
 
         if self.getOption('fromall'):
             return generator
@@ -327,9 +335,6 @@
             except KeyboardInterrupt:
                 pywikibot.output('\nQuitting %s treat...' % task)
                 break
-            except pywikibot.NoSuchSite:
-                pywikibot.output('"%s" is not a valid site. Skipping...' % 
code)
-                continue
         self.writecache()
 
     def treat(self, code, process):

-- 
To view, visit https://gerrit.wikimedia.org/r/112322
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I990b0d65909fe9f2adfec96a270b88bb62336360
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <i...@gno.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to