jenkins-bot has submitted this change and it was merged.

Change subject: Allow Family name and langs to be class variables
......................................................................


Allow Family name and langs to be class variables

Use new syntax for families which dont have any other __init__ logic.
Remove unnecessary functions, which replicate the logic in Family,
or version() which is no longer needed by Site.
Add test to ensure all Family classes load and have name and langs.

Change-Id: I052164948830396bd9353bc0f044ec43159ee432
---
M pywikibot/families/battlestarwiki_family.py
M pywikibot/families/i18n_family.py
M pywikibot/families/lyricwiki_family.py
M pywikibot/families/omegawiki_family.py
M pywikibot/families/osm_family.py
M pywikibot/families/test_family.py
M pywikibot/families/vikidia_family.py
M pywikibot/families/wikitech_family.py
M pywikibot/family.py
M tests/family_tests.py
10 files changed, 38 insertions(+), 132 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, but someone else must approve
  XZise: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/families/battlestarwiki_family.py 
b/pywikibot/families/battlestarwiki_family.py
index 44a9182..a5fe75d 100644
--- a/pywikibot/families/battlestarwiki_family.py
+++ b/pywikibot/families/battlestarwiki_family.py
@@ -12,20 +12,9 @@
 
     """Family class for Battlestar Wiki."""
 
-    def __init__(self):
-        """Constructor."""
-        family.Family.__init__(self)
-        self.name = 'battlestarwiki'
+    name = 'battlestarwiki'
 
-        self.languages_by_size = ['en', 'de', 'fr', 'zh', 'es', 'ms', 'tr', 
'simple']
+    languages_by_size = ['en', 'de', 'fr', 'zh', 'es', 'ms', 'tr', 'simple']
 
-        for lang in self.languages_by_size:
-            self.langs[lang] = '%s.battlestarwiki.org' % lang
-
-    def hostname(self, code):
-        """Return the hostname for a site in this family."""
-        return '%s.battlestarwiki.org' % code
-
-    def version(self, code):
-        """Return the version for this family."""
-        return "1.16.4"
+    langs = dict([(lang, '%s.battlestarwiki.org' % lang)
+                  for lang in languages_by_size])
diff --git a/pywikibot/families/i18n_family.py 
b/pywikibot/families/i18n_family.py
index 73930a1..31c33e0 100644
--- a/pywikibot/families/i18n_family.py
+++ b/pywikibot/families/i18n_family.py
@@ -11,17 +11,8 @@
 
     """Family class for Translate Wiki."""
 
-    def __init__(self):
-        """Constructor."""
-        family.Family.__init__(self)
-        self.name = 'i18n'
-        self.langs = {
-            'i18n': 'translatewiki.net',
-        }
-
-    def version(self, code):
-        """Return the version for this family."""
-        return "1.23alpha"
+    name = 'i18n'
+    langs = {'i18n': 'translatewiki.net'}
 
     def protocol(self, code):
         """Return https as the protocol for this family."""
diff --git a/pywikibot/families/lyricwiki_family.py 
b/pywikibot/families/lyricwiki_family.py
index a0bfcf9..642e573 100644
--- a/pywikibot/families/lyricwiki_family.py
+++ b/pywikibot/families/lyricwiki_family.py
@@ -14,22 +14,11 @@
 
     """Family class for LyricWiki."""
 
-    def __init__(self):
-        """Constructor."""
-        family.Family.__init__(self)
-        self.name = 'lyricwiki'
-        self.langs = {
-            'en': 'lyrics.wikia.com',
-        }
-
-    def version(self, code):
-        """Return the version for this family."""
-        return '1.19.20'
+    name = 'lyricwiki'
+    langs = {
+        'en': 'lyrics.wikia.com',
+    }
 
     def scriptpath(self, code):
         """Return the script path for this family."""
         return ''
-
-    def apipath(self, code):
-        """Return the path to api.php for this family."""
-        return '/api.php'
diff --git a/pywikibot/families/omegawiki_family.py 
b/pywikibot/families/omegawiki_family.py
index 7661dac..d6b4a8d 100644
--- a/pywikibot/families/omegawiki_family.py
+++ b/pywikibot/families/omegawiki_family.py
@@ -10,36 +10,21 @@
 
     """Family class for Omega Wiki."""
 
+    name = 'omegawiki'
+    langs = {'omegawiki': 'www.omegawiki.org'}
+
     def __init__(self):
         """Constructor."""
         family.Family.__init__(self)
-        self.name = 'omegawiki'
-        self.langs['omegawiki'] = 'www.omegawiki.org'
 
         # On most Wikipedias page names must start with a capital letter, but 
some
         # languages don't use this.
 
         self.nocapitalize = list(self.langs.keys())
 
-    def hostname(self, code):
-        """Return the hostname for this family."""
-        return 'www.omegawiki.org'
-
-    def version(self, code):
-        """Return the version for this family."""
-        return "1.22.6"
-
     def scriptpath(self, code):
         """Return the script path for this family."""
         return ''
-
-    def path(self, code):
-        """Return the path to index.php for this family."""
-        return '/index.php'
-
-    def apipath(self, code):
-        """Return the path to api.php for this family."""
-        return '/api.php'
 
     def protocol(self, code):
         """Return https as the protocol for this family."""
diff --git a/pywikibot/families/osm_family.py b/pywikibot/families/osm_family.py
index fbb9fe6..995c8d6 100644
--- a/pywikibot/families/osm_family.py
+++ b/pywikibot/families/osm_family.py
@@ -11,17 +11,8 @@
 
     """Family class for OpenStreetMap wiki."""
 
-    def __init__(self):
-        """Constructor."""
-        family.Family.__init__(self)
-        self.name = 'osm'
-        self.langs = {
-            'en': 'wiki.openstreetmap.org',
-        }
-
-    def version(self, code):
-        """Return the version for this family."""
-        return "1.22.7"
+    name = 'osm'
+    langs = {'en': 'wiki.openstreetmap.org'}
 
     def protocol(self, code):
         """Return https as the protocol for this family."""
diff --git a/pywikibot/families/test_family.py 
b/pywikibot/families/test_family.py
index 8d72b7c..1517af2 100644
--- a/pywikibot/families/test_family.py
+++ b/pywikibot/families/test_family.py
@@ -10,12 +10,8 @@
 
     """Family class for test.wikipedia.org."""
 
-    def __init__(self):
-        super(Family, self).__init__()
-        self.name = 'test'
-        self.langs = {
-            'test': 'test.wikipedia.org',
-        }
+    name = 'test'
+    langs = {'test': 'test.wikipedia.org'}
 
     def from_url(self, url):
         return None  # Don't accept this, but 'test' of 'wikipedia'
diff --git a/pywikibot/families/vikidia_family.py 
b/pywikibot/families/vikidia_family.py
index e02e803..735cd36 100644
--- a/pywikibot/families/vikidia_family.py
+++ b/pywikibot/families/vikidia_family.py
@@ -9,48 +9,15 @@
 
     """Family class for Vikidia."""
 
-    def __init__(self):
-        """Constructor."""
-        family.Family.__init__(self)
-        self.name = 'vikidia'
+    name = 'vikidia'
 
-        self.langs = {
-            'en': 'en.vikidia.org',
-            'es': 'es.vikidia.org',
-            'fr': 'fr.vikidia.org',
-            'it': 'it.vikidia.org',
-            'ru': 'ru.vikidia.org',
-        }
-
-        # Wikimedia wikis all use "bodyContent" as the id of the <div>
-        # element that contains the actual page content; change this for
-        # wikis that use something else (e.g., mozilla family)
-        self.content_id = "bodyContent"
-
-    def scriptpath(self, code):
-        """The prefix used to locate scripts on this wiki.
-
-        This is the value displayed when you enter {{SCRIPTPATH}} on a
-        wiki page (often displayed at [[Help:Variables]] if the wiki has
-        copied the master help page correctly).
-
-        The default value is the one used on Wikimedia Foundation wikis,
-        but needs to be overridden in the family file for any wiki that
-        uses a different value.
-
-        """
-        return '/w'
-
-    # Which version of MediaWiki is used? REQUIRED
-    def version(self, code):
-        """Return the version for this family."""
-        return '1.23.1'
-
-    def code2encoding(self, code):
-        """Return the encoding for a specific language wiki."""
-        # Most wikis nowadays use UTF-8, but change this if yours uses
-        # a different encoding
-        return 'utf-8'
+    langs = {
+        'en': 'en.vikidia.org',
+        'es': 'es.vikidia.org',
+        'fr': 'fr.vikidia.org',
+        'it': 'it.vikidia.org',
+        'ru': 'ru.vikidia.org',
+    }
 
     def protocol(self, code):
         """Return https as the protocol for this family."""
diff --git a/pywikibot/families/wikitech_family.py 
b/pywikibot/families/wikitech_family.py
index d406f42..4fd054e 100644
--- a/pywikibot/families/wikitech_family.py
+++ b/pywikibot/families/wikitech_family.py
@@ -10,17 +10,8 @@
 
     """Family class for Wikitech."""
 
-    def __init__(self):
-        """Constructor."""
-        super(Family, self).__init__()
-        self.name = 'wikitech'
-        self.langs = {
-            'en': 'wikitech.wikimedia.org',
-        }
-
-    def version(self, code):
-        """Return the version for this family."""
-        return '1.21wmf8'
+    name = 'wikitech'
+    langs = {'en': 'wikitech.wikimedia.org'}
 
     def protocol(self, code):
         """Return the protocol for this family."""
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 0501f3e..b3941ff 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -35,6 +35,9 @@
         if not hasattr(self, 'name'):
             self.name = None
 
+        if not hasattr(self, 'langs'):
+            self.langs = {}
+
         # For interwiki sorting order see
         # https://meta.wikimedia.org/wiki/Interwiki_sorting_order
 
@@ -113,8 +116,6 @@
         self.fyinterwiki.remove('nb')
         self.fyinterwiki.sort(key=lambda x:
                               x.replace("y", "i") + x.count("y") * "!")
-
-        self.langs = {}
 
         self.namespacesWithSubpage = [2] + list(range(1, 16, 2))
 
diff --git a/tests/family_tests.py b/tests/family_tests.py
index b8a8c32..3cbadea 100644
--- a/tests/family_tests.py
+++ b/tests/family_tests.py
@@ -26,8 +26,14 @@
 
     def test_family_load_valid(self):
         """Test that a family can be loaded via Family.load."""
-        f = Family.load('anarchopedia')
-        self.assertEqual(f.name, 'anarchopedia')
+        for name in pywikibot.config.family_files:
+            f = Family.load(name)
+            self.assertIsInstance(f.langs, dict)
+            self.assertNotEqual(f.langs, {})
+            # There is one inconsistency
+            if f.name == 'wikimediachapter' and name == 'wikimedia':
+                continue
+            self.assertEqual(f.name, name)
 
     def test_family_load_invalid(self):
         """Test that an invalid family raised UnknownFamily exception."""

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I052164948830396bd9353bc0f044ec43159ee432
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to