Eranroz has uploaded a new change for review.

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

Change subject: Fixing the MySqlPageGenerator
......................................................................

Fixing the MySqlPageGenerator

MySqlPageGenerator code was broken (e.g getting into site.encoding(), while 
site is a string).
This fix it by expecting site to be site object and never set it to string, to 
avoid messy code.

To allow users to override the dbName of a site, it is now possible to set the 
db name in the config.
For example in wmflabs, users may want to set db_name_format = '{}_p'

Change-Id: I8931fd456fb6dc67e668421469b6ada07ed827ef
---
M pywikibot/config2.py
M pywikibot/pagegenerators.py
2 files changed, 6 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/60/179560/1

diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 3d2a674..76f021d 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -544,9 +544,12 @@
 report_dead_links_on_talk = False
 
 # ############# DATABASE SETTINGS ##############
+# Setting to connect the database or replica of the database of the wiki. 
+# db_name_format can be used to manipulate the dbName of site
 db_hostname = 'localhost'
 db_username = 'wikiuser'
 db_password = ''
+db_name_format = '{}'
 
 # ############# SEARCH ENGINE SETTINGS ##############
 
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index e5c0e31..d1d9929 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -1957,8 +1957,8 @@
     MySQLdb <https://sourceforge.net/projects/mysql-python/>
 
     @param query: MySQL query to execute
-    @param site: Site object or raw database name
-    @type site: L{pywikibot.site.BaseSite} or str
+    @param site: Site object 
+    @type site: L{pywikibot.site.BaseSite}
     @return: iterator of pywikibot.Page
     """
     try:
@@ -1967,12 +1967,7 @@
         import MySQLdb as mysqldb
     if site is None:
         site = pywikibot.Site()
-    if isinstance(site, pywikibot.site.BaseSite):
-        # We want to let people to set a custom dbname
-        # since the master dbname might not be exactly
-        # equal to the name on the replicated site
-        site = site.dbName()
-    conn = mysqldb.connect(config.db_hostname, db=site,
+    conn = mysqldb.connect(config.db_hostname, 
db=config.db_name_format.format(site.dbName()),
                            user=config.db_username,
                            passwd=config.db_password)
     cursor = conn.cursor()

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8931fd456fb6dc67e668421469b6ada07ed827ef
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Eranroz <eranro...@gmail.com>

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

Reply via email to