jenkins-bot has submitted this change and it was merged.
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'
Also adding support for connection configuration file.
Change-Id: I8931fd456fb6dc67e668421469b6ada07ed827ef --- M pywikibot/config2.py M pywikibot/pagegenerators.py 2 files changed, 18 insertions(+), 11 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py index 3d2a674..e7df241 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -544,9 +544,17 @@ 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. +# Example for a pywikibot running on wmflabs: +# db_hostname = 'enwiki.labsdb' +# db_name_format = '{0}_p' +# db_connect_file = '~/replica.my.cnf' db_hostname = 'localhost' -db_username = 'wikiuser' +db_username = '' db_password = '' +db_name_format = '{0}' +db_connect_file = None
# ############# SEARCH ENGINE SETTINGS ##############
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index e5c0e31..e3841d5 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,14 +1967,13 @@ 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, - user=config.db_username, - passwd=config.db_password) + if config.db_connect_file is None: + conn = mysqldb.connect(config.db_hostname, db=config.db_name_format.format(site.dbName()), + user=config.db_username, passwd=config.db_password) + else: + conn = mysqldb.connect(config.db_hostname, db=config.db_name_format.format(site.dbName()), + read_default_file=config.db_connect_file) + cursor = conn.cursor() pywikibot.output(u'Executing query:\n%s' % query) query = query.encode(site.encoding())
pywikibot-commits@lists.wikimedia.org