Skip to content

Commit

Permalink
Merge "Fixing the MySqlPageGenerator"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Dec 16, 2014
2 parents bf9edb2 + 7c913d5 commit 40cfc31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
10 changes: 9 additions & 1 deletion pywikibot/config2.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,17 @@ def register_families_folder(folder_path):
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 ##############

Expand Down
19 changes: 9 additions & 10 deletions pywikibot/pagegenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1993,8 +1993,8 @@ def MySQLPageGenerator(query, site=None):
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:
Expand All @@ -2003,14 +2003,13 @@ def MySQLPageGenerator(query, site=None):
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())
Expand Down

0 comments on commit 40cfc31

Please sign in to comment.