jenkins-bot has submitted this change and it was merged.
Change subject: Bugfix and code cleanup
......................................................................
Bugfix and code cleanup
- fix for string formatting
- format doc and script to max 80 chars
- change page.get/put to text assignment
Change-Id: Iae5a02ac7e83204eb7a8a468e086ac431a6e8572
---
M scripts/replicate_wiki.py
1 file changed, 42 insertions(+), 28 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py
index f8d2c30..a7defbc 100644
--- a/scripts/replicate_wiki.py
+++ b/scripts/replicate_wiki.py
@@ -1,25 +1,29 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
-This bot replicates all pages (from specific namespaces) in a wiki to a second wiki within one family.
+This bot replicates all pages (from specific namespaces) in a wiki to a second
+wiki within one family.
Example:
python replicate_wiki.py [-r] -ns 10 -f wikipedia -o nl li fy
-to copy all templates from an nlwiki to liwiki and fywiki. It will show which pages have to be changed
-if -r is not present, and will only actually write pages if -r /is/ present.
+to copy all templates from an nlwiki to liwiki and fywiki. It will show which
+pages have to be changed if -r is not present, and will only actually write
+pages if -r /is/ present.
-You can add replicate_replace to your user_config.py, which has the following format:
+You can add replicate_replace to your user_config.py, which has the following
+format:
replicate_replace = {
'wikipedia:li': {'Hoofdpagina': 'Veurblaad'}
}
-to replace all occurences of 'Hoofdpagina' with 'Veurblaad' when writing to liwiki. Note that this does
-not take the origin wiki into account.
+to replace all occurences of 'Hoofdpagina' with 'Veurblaad' when writing to
+liwiki. Note that this does not take the origin wiki into account.
"""
#
# (C) Kasper Souren 2012-2013
+# (C) Pywikibot team, 2013-2014
#
# Distributed under the terms of the MIT license.
#
@@ -32,7 +36,7 @@
def namespaces(site):
- '''dict from namespace number to prefix'''
+ """dict from namespace number to prefix"""
ns = dict(map(lambda n: (site.getNamespaceIndex(n), n),
site.namespaces()))
ns[0] = ''
@@ -40,14 +44,14 @@
def multiple_replace(text, word_dict):
- '''Replace all occurrences in text of key value pairs in word_dict'''
+ """Replace all occurrences in text of key value pairs in word_dict"""
for key in word_dict:
text = text.replace(key, word_dict[key])
return text
class SyncSites:
- '''Work is done in here.'''
+ """Work is done in here."""
def __init__(self, options):
self.options = options
@@ -85,7 +89,7 @@
pywikibot.output('')
def check_sysops(self):
- '''Check if sysops are the same on all wikis '''
+ """Check if sysops are the same on all wikis """
def get_users(site):
userlist = [ul['name'] for ul in site.allusers(group='sysop')]
return set(userlist)
@@ -98,7 +102,7 @@
self.user_diff[site] = diff
def check_namespaces(self):
- '''Check all namespaces, to be ditched for clarity'''
+ """Check all namespaces, to be ditched for clarity"""
namespaces = [
0, # Main
8, # MediaWiki
@@ -119,7 +123,7 @@
self.check_namespace(ns)
def check_namespace(self, namespace):
- '''Check an entire namespace'''
+ """Check an entire namespace"""
pywikibot.output("\nCHECKING NAMESPACE %s" % namespace)
pages = imap(lambda p: p.title(),
@@ -130,40 +134,47 @@
try:
self.check_page(p)
except pywikibot.exceptions.NoPage:
- pywikibot.output('Bizarre NoPage exception that we are just going to ignore')
+ pywikibot.output('Bizarre NoPage exception that we are '
+ 'just going to ignore')
except pywikibot.exceptions.IsRedirectPage:
- pywikibot.output('error: Redirectpage - todo: handle gracefully')
+ pywikibot.output(
+ 'error: Redirectpage - todo: handle gracefully')
pywikibot.output('')
def generate_overviews(self):
- '''Create page on wikis with overview of bot results'''
+ """Create page on wikis with overview of bot results"""
for site in self.sites:
- sync_overview_page = Page(site, 'User:' + site.user() + '/sync.py overview')
+ sync_overview_page = Page(site,
+ 'User:%s/sync.py overview' % site.user())
output = "== Pages that differ from original ==\n\n"
if self.differences[site]:
- output += "".join(map(lambda l: '* [[:' + l + "]]\n", self.differences[site]))
+ output += "".join(map(lambda l: '* [[:%s]]\n' % l,
+ self.differences[site]))
else:
output += "All important pages are the same"
output += "\n\n== Admins from original that are missing here ==\n\n"
if self.user_diff[site]:
- output += "".join(map(lambda l: '* ' + l.replace('_', ' ') + "\n", self.user_diff[site]))
+ output += "".join(map(lambda l: '* %s\n' % l.replace('_', ' '),
+ self.user_diff[site]))
else:
output += "All users from original are also present on this wiki"
pywikibot.output(output)
- sync_overview_page.put(output, self.put_message(site))
+ sync_overview_page.text = output
+ sync_overview_page.save(self.put_message(site))
def put_message(self, site):
- return site.user() + ' replicate_wiki.py synchronization from ' + str(self.original)
+ return ('%s replicate_wiki.py synchronization from %s'
+ % (site.user(), str(self.original)))
def check_page(self, pagename):
- '''Check one page'''
+ """Check one page"""
pywikibot.output("\nChecking %s" % pagename)
sys.stdout.flush()
page1 = Page(self.original, pagename)
- txt1 = page1.get()
+ txt1 = page1.text
for site in self.sites:
if options.dest_namespace:
@@ -171,21 +182,23 @@
if prefix:
prefix += ':'
new_pagename = prefix + page1.titleWithoutNamespace()
- pywikibot.output("\nCross namespace, new title: %s", new_pagename)
+ pywikibot.output("\nCross namespace, new title: %s"
+ % new_pagename)
else:
new_pagename = pagename
page2 = Page(site, new_pagename)
if page2.exists():
- txt2 = page2.get()
-
+ txt2 = page2.text
else:
txt2 = ''
if str(site) in config.replicate_replace:
- txt_new = multiple_replace(txt1, config.replicate_replace[str(site)])
+ txt_new = multiple_replace(txt1,
+ config.replicate_replace[str(site)])
if txt1 != txt_new:
- pywikibot.output('NOTE: text replaced using config.sync_replace')
+ pywikibot.output(
+ 'NOTE: text replaced using config.sync_replace')
pywikibot.output('%s %s %s' % (txt1, txt_new, txt2))
txt1 = txt_new
@@ -194,7 +207,8 @@
self.differences[site].append(pagename)
if self.options.replace:
- page2.put(txt1, self.put_message(site))
+ page2.text = txt1
+ page2.save(self.put_message(site))
else:
sys.stdout.write('.')
sys.stdout.flush()
--
To view, visit https://gerrit.wikimedia.org/r/133450
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iae5a02ac7e83204eb7a8a468e086ac431a6e8572
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: support special sites in APISite.fromDBName()
......................................................................
support special sites in APISite.fromDBName()
that constructor could not initialize some sites correctly,
such as multilingual ones (Meta-Wiki, Commons, Wikidata)
also updated site_tests.py accordingly
Change-Id: I6e8f78bfe09bd985ff7b2b988d39d02e05898ee3
---
M pywikibot/site.py
M tests/site_tests.py
2 files changed, 15 insertions(+), 9 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index ef20492..79cadc8 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -643,14 +643,19 @@
action='sitematrix')
data = req.submit()
for num in data['sitematrix']:
- if num in ['specials', 'count']:
+ if num == 'count':
continue
- lang = data['sitematrix'][num]['code']
- for site in data['sitematrix'][num]['site']:
- if site['dbname'] == dbname:
- if site['code'] == 'wiki':
- site['code'] = 'wikipedia'
- return APISite(lang, site['code'])
+ if 'code' in data['sitematrix'][num]:
+ lang = data['sitematrix'][num]['code']
+ for site in data['sitematrix'][num]['site']:
+ if site['dbname'] == dbname:
+ if site['code'] == 'wiki':
+ site['code'] = 'wikipedia'
+ return APISite(lang, site['code'])
+ else:
+ for site in data['sitematrix'][num]:
+ if site['dbname'] == dbname:
+ return APISite(site['code'], site['code'])
raise ValueError("Cannot parse a site out of %s." % dbname)
def _generator(self, gen_class, type_arg=None, namespaces=None,
diff --git a/tests/site_tests.py b/tests/site_tests.py
index ae2c92a..51a9c9e 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -64,8 +64,9 @@
self.assertEqual(pywikibot.site.APISite.fromDBName('eswikisource'), pywikibot.Site('es', 'wikisource'))
self.assertEqual(pywikibot.site.APISite.fromDBName('dewikinews'), pywikibot.Site('de', 'wikinews'))
self.assertEqual(pywikibot.site.APISite.fromDBName('ukwikivoyage'), pywikibot.Site('uk', 'wikivoyage'))
-
- self.assertRaises(ValueError, pywikibot.site.APISite.fromDBName, 'metawiki')
+ self.assertEqual(pywikibot.site.APISite.fromDBName('metawiki'), pywikibot.Site('meta', 'meta'))
+ self.assertEqual(pywikibot.site.APISite.fromDBName('commonswiki'), pywikibot.Site('commons', 'commons'))
+ self.assertEqual(pywikibot.site.APISite.fromDBName('wikidatawiki'), pywikibot.Site('wikidata', 'wikidata'))
def testLanguageMethods(self):
"""Test cases for languages() and related methods"""
--
To view, visit https://gerrit.wikimedia.org/r/132231
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6e8f78bfe09bd985ff7b2b988d39d02e05898ee3
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [tox] Block this stupid E265 error which breaks the IDLE
......................................................................
[tox] Block this stupid E265 error which breaks the IDLE
Python's Integrated Development Environmet has functions to
to comment out region and uncomment regions and therefore
uses "##" on first position of a line. Changing it breaks that
behaviour.
Change-Id: I9273a9b44c6c37d36fe9cffe34279360caa3e252
---
M tox.ini
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tox.ini b/tox.ini
index 3d09c39..5a6209e 100644
--- a/tox.ini
+++ b/tox.ini
@@ -17,7 +17,7 @@
commands = {posargs}
[flake8]
-ignore = E122,E127,E241,E502
+ignore = E122,E127,E241,E265,E502
exclude = .tox,.git,./*.egg,ez_setup.py,externals,user-config.py,./scripts/i18n/*,./pywikibot/date.py
max_line_length = 256
--
To view, visit https://gerrit.wikimedia.org/r/132443
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9273a9b44c6c37d36fe9cffe34279360caa3e252
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>