jenkins-bot has submitted this change and it was merged.
Change subject: Revert "Make it possible to define a custom families folder" ......................................................................
Revert "Make it possible to define a custom families folder"
This reverts commit 6f464a0b3a06e1c2803aa5345ac4c0647c84584c.
Change-Id: Ic9b24c6e1119acd93f301da5c5fcf00d36ccc65e --- M generate_user_files.py M pywikibot/config2.py M pywikibot/site.py 3 files changed, 39 insertions(+), 74 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/generate_user_files.py b/generate_user_files.py index 75130aa..0df0b15 100644 --- a/generate_user_files.py +++ b/generate_user_files.py @@ -237,34 +237,9 @@ # This is an automatically generated file. You can find more configuration # parameters in 'config.py' file.
-# The family of sites to work on by default. -# -# ‘wikipedia.py’ imports ‘families/xxx_family.py’, so if you want to change -# this variable, you need to use the name of one of the existing family files -# in that folder or write your own, custom family file. -# -# For ‘wikipedia.py’ to be able to read your custom family file, you must -# save it to ‘families/xxx_family.py’, where ‘xxx‘ is the codename of the -# family that your custom ‘xxx_family.py’ family file defines. -# -# You can also save your custom family files to a different folder. As long -# as you follow the ‘xxx_family.py’ naming convention, you can register your -# custom folder in this configuration file with the following global function: -# -# register_families_folder(folder_path) -# -# Alternatively, you can register particular family files that do not need -# to follow the ‘xxx_family.py’ naming convention using the following -# global function: -# -# register_family_file(family_name, file_path) -# -# Where ‘family_name’ is the family code (the ‘xxx’ in standard family file -# names) and ‘file_path’ is the absolute path to the target family file. -# -# If you use either of these functions to define the family to work on by -# default (the ‘family’ variable below), you must place the function call -# before the definition of the ‘family’ variable. +# The family of sites we are working on. wikipedia.py will import +# families/xxx_family.py so if you want to change this variable, +# you need to write such a file. family = '%s'
# The language code of the site we're working on. diff --git a/pywikibot/config2.py b/pywikibot/config2.py index d83009d..3f6342c 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -106,6 +106,8 @@ default_edit_summary = u'Wikipedia python library v.2'
+# Get the names of all known families, and initialize +# with empty dictionaries def _get_base_dir(): """Return the directory in which user-specific information is stored.
@@ -160,27 +162,14 @@ return base_dir
_base_dir = _get_base_dir() - - -family_files = {} - - -def register_family_file(family_name, file_path): - usernames[family_name] = {} - sysopnames[family_name] = {} - disambiguation_comment[family_name] = {} - family_files[family_name] = file_path - - -def register_families_folder(folder_path): - for file_name in os.listdir(folder_path): - if file_name.endswith("_family.py"): - family_name = file_name[:-len("_family.py")] - register_family_file(family_name, os.path.join(folder_path, file_name)) - -# Get the names of all known families, and initialize with empty dictionaries. -# ‘families/’ is a subdirectory of the directory in which config2.py is found. -register_families_folder(os.path.join(os.path.dirname(__file__), 'families')) +# families/ is a subdirectory of the directory in which config.py is found +for _filename in os.listdir( + os.path.join(os.path.dirname(__file__), 'families')): + if _filename.endswith("_family.py"): + familyName = _filename[:-len("_family.py")] + usernames[familyName] = {} + sysopnames[familyName] = {} + disambiguation_comment[familyName] = {}
# Set to True to override the {{bots}} exclusion protocol (at your own risk!) ignore_bot_templates = False diff --git a/pywikibot/site.py b/pywikibot/site.py index 2df94e3..141f0e9 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -16,7 +16,6 @@ except ImportError: from md5 import md5 import datetime -import imp import itertools import os import re @@ -85,16 +84,24 @@ if fam is None: fam = config.family try: - myfamily = imp.load_source(name, config.family_files[fam]) - except (ImportError, KeyError): - if fatal: - pywikibot.error(u"""\ + # first try the built-in families + name = "pywikibot.families.%s_family" % fam + __import__(name) + myfamily = sys.modules[name] + except ImportError: + # next see if user has defined a local family module + try: + sys.path.append(config.datafilepath('families')) + myfamily = __import__("%s_family" % fam) + except ImportError: + if fatal: + pywikibot.error(u"""\ Error importing the %s family. This probably means the family does not exist. Also check your configuration file.""" - % fam, exc_info=True) - sys.exit(1) - else: - raise Error("Family %s does not exist" % fam) + % fam, exc_info=True) + sys.exit(1) + else: + raise Error("Family %s does not exist" % fam) return myfamily.Family()
@@ -874,13 +881,10 @@ self._loginstatus = LoginStatus.IN_PROGRESS if hasattr(self, "_userinfo"): del self._userinfo - try: - self.getuserinfo() - if self.userinfo['name'] == self._username[sysop] and \ - self.logged_in(sysop): - return - except pywikibot.data.api.APIError: # May occur if you are not logged in (no API read permissions). - pass + self.getuserinfo() + if self.userinfo['name'] == self._username[sysop] and \ + self.logged_in(sysop): + return loginMan = api.LoginManager(site=self, sysop=sysop, user=self._username[sysop]) if loginMan.login(retry=True): @@ -1327,15 +1331,12 @@ version numbers and any other text contained in the version.
""" - try: - if force: - self._getsiteinfo(force=True) # drop/expire cache and reload - versionstring = self.siteinfo['generator'] - m = re.match(r"^MediaWiki ([0-9]+).([0-9]+)(.*)$", versionstring) - if m: - return (int(m.group(1)), int(m.group(2)), m.group(3)) - except pywikibot.data.api.APIError: # May occur if you are not logged in (no API read permissions). - return (0, 0, 0) + if force: + self._getsiteinfo(force=True) # drop/expire cache and reload + versionstring = self.siteinfo['generator'] + m = re.match(r"^MediaWiki ([0-9]+).([0-9]+)(.*)$", versionstring) + if m: + return (int(m.group(1)), int(m.group(2)), m.group(3))
def loadpageinfo(self, page): """Load page info from api and save in page attributes"""