jenkins-bot has submitted this change and it was merged.
Change subject: replace nicepath() + page.title() with nice_get_address(title())
......................................................................
replace nicepath() + page.title() with nice_get_address(title())
- we use the site methods instead of the family method
- fix for title(), must be asUrl=True
- use page.site instead of pywikibot.Site()
Change-Id: I40d77625ea5e025f44c26fdafaa226a931d34068
---
M scripts/add_text.py
1 file changed, 5 insertions(+), 6 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/add_text.py b/scripts/add_text.py
index d5c6d3a..a8aca2f 100644
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -126,8 +126,9 @@
oldTextGiven=None, reorderEnabled=True, create=False):
if not addText:
raise NoEnoughData('You have to specify what text you want to add!')
+ site = page.site
if not summary:
- summary = i18n.twtranslate(pywikibot.Site(), 'add_text-adding',
+ summary = i18n.twtranslate(site, 'add_text-adding',
{'adding': addText[:200]})
# When a page is tagged as "really well written" it has a star in the
@@ -135,8 +136,6 @@
# format) to make the stars appear.
errorCount = 0
- site = pywikibot.Site()
- pathWiki = site.family.nicepath(site.code)
if putText:
pywikibot.output(u'Loading %s...' % page.title())
@@ -159,7 +158,7 @@
# Understand if the bot has to skip the page or not
# In this way you can use both -except and -excepturl
if regexSkipUrl is not None:
- url = '%s%s' % (pathWiki, page.title(asUrl=True))
+ url = site.nice_get_address(page.title(asUrl=True))
result = re.findall(regexSkipUrl, site.getUrl(url))
if result != []:
pywikibot.output(
@@ -236,8 +235,8 @@
return (False, False, always)
elif choice == 'b':
webbrowser.open("http://%s%s" % (
- page.site.hostname(),
- page.site.nice_get_address(page.title())
+ site.hostname(),
+ site.nice_get_address(page.title(asUrl=True))
))
pywikibot.input("Press Enter when finished in browser.")
if always or choice == 'y':
--
To view, visit https://gerrit.wikimedia.org/r/138322
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I40d77625ea5e025f44c26fdafaa226a931d34068
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Pyfisch <pyfisch(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
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: small improvements to category.py
......................................................................
small improvements to category.py
- fix most docstrings according to pep257
- use a single multiline string instead of multiple single-line ones
- use string formatting instead of concatenation where appropriate
- merge several `else if` statements into a tuple lookup
- remove obsolete script name from showHelp
Change-Id: Ie903a2b299db506bb0b4345847cefc537d151094
---
M scripts/category.py
1 file changed, 43 insertions(+), 47 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index ff8ae07..3923ca0 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -92,7 +92,7 @@
# (C) Cyde, 2006-2010
# (C) Anreas J Schwab, 2007
# (C) xqt, 2009-2014
-# (C) Pywikibot team, 2008-2013
+# (C) Pywikibot team, 2008-2014
#
# Distributed under the terms of the MIT license.
#
@@ -131,11 +131,13 @@
class CategoryDatabase:
- '''This is a temporary knowledge base saving for each category the contained
+
+ """This is a temporary knowledge base saving for each category the contained
subcategories and articles, so that category pages do not need to be loaded
over and over again
- '''
+ """
+
def __init__(self, rebuild=False, filename='category.dump.bz2'):
if rebuild:
self.rebuild()
@@ -163,11 +165,11 @@
self.superclassDB = {}
def getSubcats(self, supercat):
- '''For a given supercategory, return a list of Categorys for all its
+ """For a given supercategory, return a list of Categorys for all its
subcategories. Saves this list in a temporary database so that it won't
be loaded from the server next time it's required.
- '''
+ """
# if we already know which subcategories exist here
if supercat in self.catContentDB:
return self.catContentDB[supercat][0]
@@ -179,11 +181,11 @@
return subcatset
def getArticles(self, cat):
- '''For a given category, return a list of Pages for all its articles.
+ """For a given category, return a list of Pages for all its articles.
Saves this list in a temporary database so that it won't be loaded from
the server next time it's required.
- '''
+ """
# if we already know which articles exist here
if cat in self.catContentDB:
return self.catContentDB[cat][1]
@@ -205,10 +207,9 @@
return supercatset
def dump(self, filename='category.dump.bz2'):
- '''Saves the contents of the dictionaries superclassDB and catContentDB
+ """Save the contents of the dictionaries superclassDB and catContentDB
to disk.
-
- '''
+ """
if not os.path.isabs(filename):
filename = config.datafilepath(filename)
if self.catContentDB or self.superclassDB:
@@ -236,7 +237,8 @@
class AddCategory:
- '''A robot to mass-add a category to a list of pages.'''
+
+ """A robot to mass-add a category to a list of pages."""
def __init__(self, generator, sort_by_last_name=False, create=False,
editSummary='', follow_redirects=False, dry=False):
@@ -250,7 +252,7 @@
self.editSummary = editSummary
def sorted_by_last_name(self, catlink, pagelink):
- '''Return a Category with key that sorts persons by their last name.
+ """Return a Category with key that sorts persons by their last name.
Parameters: catlink - The Category to be linked
pagelink - the Page to be placed in the category
@@ -260,7 +262,7 @@
(senior)]], this function will return this Category:
[[Category:Author|Dumas, Alexandre]]
- '''
+ """
page_name = pagelink.title()
site = pagelink.site
# regular expression that matches a name followed by a space and
@@ -290,9 +292,7 @@
pywikibot.output(u"%d page(s) processed." % counter)
def load(self, page):
- """
- Loads the given page, does some changes, and saves it.
- """
+ """Load the given page, do some changes, and save it."""
try:
# Load the page
text = page.get()
@@ -393,10 +393,12 @@
class CategoryMoveRobot(object):
+
"""Bot to move pages from one category to another or to remove
pages from categories. The bot moves per default pages and
subcategories.
"""
+
@deprecate_arg("oldCatTitle", "oldcat")
@deprecate_arg("newCatTitle", "newcat")
@deprecate_arg("batchMode", "batch")
@@ -568,7 +570,9 @@
class CategoryListifyRobot:
- '''Creates a list containing all of the members in a category.'''
+
+ """Create a list containing all of the members in a category."""
+
def __init__(self, catTitle, listTitle, editSummary, overwrite=False,
showImages=False, subCats=False, talkPages=False,
recurse=False):
@@ -617,13 +621,14 @@
class CategoryRemoveRobot:
- '''Removes the category tag from all pages in a given category
- and if pagesonly parameter is False also from the category pages of all
- subcategories, without prompting. If the category is empty, it will be
- tagged for deleting. Does not remove category tags pointing at
- subcategories.
- '''
+ """Remove the category tag from all pages in a given category
+ and if pagesonly parameter is False also from the category pages of all
+ subcategories, without prompting.
+ If the category is empty, it will be tagged for deletion.
+ Do not remove category tags pointing at subcategories.
+
+ """
def __init__(self, catTitle, batchMode=False, editSummary='',
useSummaryForDeletion=True, titleRegex=None, inPlace=False,
@@ -683,6 +688,7 @@
class CategoryTidyRobot:
+
"""Script to help a human to tidy up a category by moving its articles into
subcategories
@@ -706,6 +712,7 @@
account uses this skin
"""
+
def __init__(self, catTitle, catDB):
self.catTitle = catTitle
self.catDB = catDB
@@ -715,13 +722,13 @@
'newcat': u''})
def move_to_category(self, article, original_cat, current_cat):
- '''
+ """
Given an article which is in category original_cat, ask the user if
it should be moved to one of original_cat's subcategories.
Recursively run through subcategories' subcategories.
NOTE: current_cat is only used for internal recursion. You should
always use current_cat = original_cat.
- '''
+ """
pywikibot.output(u'')
# Show the title of the page where the link was found.
# Highlight the title in purple.
@@ -763,12 +770,11 @@
for i, subcat in enumerate(subcatlist):
# layout: we don't expect a cat to have more than 100 subcats
pywikibot.output(u'%2d - Move down to %s' % (i, subcat.title()))
- pywikibot.output(' j - Jump to another category')
- pywikibot.output(' s - Skip this article')
- pywikibot.output(' r - Remove this category tag')
- pywikibot.output(
- ' ? - Print first part of the page (longer and longer)')
- pywikibot.output(u'Enter - Save category as %s' % current_cat.title())
+ pywikibot.output(' j - Jump to another category\n'
+ ' s - Skip this article\n'
+ ' r - Remove this category tag\n'
+ ' ? - Print first part of the page (longer and longer)\n'
+ u'Enter - Save category as %s' % current_cat.title())
flag = False
while not flag:
@@ -831,8 +837,8 @@
cat = pywikibot.Category(self.site, self.catTitle)
if cat.categoryinfo['pages'] == 0:
- pywikibot.output(u'There are no articles in category ' +
- self.catTitle)
+ pywikibot.output(u'There are no articles in category %s'
+ % self.catTitle)
else:
preloadingGen = pagegenerators.PreloadingGenerator(cat.articles())
for article in preloadingGen:
@@ -842,6 +848,7 @@
class CategoryTreeRobot:
+
""" Robot to create tree overviews of the category structure.
Parameters:
@@ -873,7 +880,6 @@
* parent - the Category of the category we're coming from
"""
-
result = u'#' * currentDepth
if currentDepth > 0:
result += u' '
@@ -964,18 +970,8 @@
follow_redirects = False
deleteEmptySourceCat = True
for arg in local_args:
- if arg == 'add':
- action = 'add'
- elif arg == 'remove':
- action = 'remove'
- elif arg == 'move':
- action = 'move'
- elif arg == 'tidy':
- action = 'tidy'
- elif arg == 'tree':
- action = 'tree'
- elif arg == 'listify':
- action = 'listify'
+ if arg in ('add', 'remove', 'move', 'tidy', 'tree', 'listify'):
+ action = arg
elif arg == '-nodelete':
deleteEmptySourceCat = False
elif arg == '-person':
@@ -1081,7 +1077,7 @@
talkPages=talkPages, recurse=recurse)
bot.run()
else:
- pywikibot.showHelp('category')
+ pywikibot.showHelp()
if __name__ == "__main__":
--
To view, visit https://gerrit.wikimedia.org/r/147745
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie903a2b299db506bb0b4345847cefc537d151094
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Test python 2.7 before 2.6
......................................................................
Test python 2.7 before 2.6
As only a limited number of builds occur on travis concurrently,
do the py 2.7 tests before the py 2.6 tests.
Change-Id: Ib9ce4e8cb388712f1276e87c79978d2ea8e51c33
---
M .travis.yml
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.travis.yml b/.travis.yml
index ecd9ae1..dbd5764 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,8 +1,8 @@
language: python
python:
- - '2.6'
- '2.7'
+ - '2.6'
install:
- mkdir ~/.pywikibot
--
To view, visit https://gerrit.wikimedia.org/r/147729
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib9ce4e8cb388712f1276e87c79978d2ea8e51c33
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Site: add canonical namespaces to site._namespaces
......................................................................
Site: add canonical namespaces to site._namespaces
Needed to identify which namespaces can be accessed by an Extension.
E.g. Proofread Page works on Page and Index namespaces, which keep the
same name as 'canonical' namespaces but not as 'actual' namespaces.
Code improvements as well
Preparation for ProofreadPage class.
Change-Id: I58d67501e00ff9f1afdbdde97ac43bd7aeb40963
---
M pywikibot/site.py
M tests/site_tests.py
2 files changed, 19 insertions(+), 7 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 5f5ba7e..03928e5 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1133,16 +1133,26 @@
assert 'namespaces' in sidata, \
"API siteinfo response lacks 'namespaces' key"
self._siteinfo = sidata['general']
+
nsdata = sidata['namespaces']
for nskey in nsdata:
ns = int(nskey)
- if ns in self._namespaces:
- if nsdata[nskey]["*"] in self._namespaces[ns]:
+ # this is the preferred form so it goes at front of list
+ self._namespaces.setdefault(ns, []).insert(0, nsdata[nskey]["*"])
+
+ if LV(self.version()) >= LV("1.14"):
+ # nsdata["0"] has no canonical key.
+ # canonical ns -2 to 15 are hard coded in self._namespaces
+ # do not get them from API result to avoid canonical duplicates
+ if -2 <= ns <= 15:
continue
- # this is the preferred form so it goes at front of list
- self._namespaces[ns].insert(0, nsdata[nskey]["*"])
- else:
- self._namespaces[ns] = [nsdata[nskey]["*"]]
+ if 'canonical' not in nsdata[nskey]:
+ pywikibot.warning(
+ u'namespace %s without a canonical name. Misconfigured?'
+ % self._namespaces[ns][0])
+ continue
+ self._namespaces.setdefault(ns, []).append(nsdata[nskey]["canonical"])
+
if 'namespacealiases' in sidata:
aliasdata = sidata['namespacealiases']
for item in aliasdata:
@@ -1150,6 +1160,7 @@
continue
# this is a less preferred form so it goes at the end
self._namespaces[int(item['id'])].append(item["*"])
+
if 'extensions' in sidata:
self._extensions = sidata['extensions']
else:
diff --git a/tests/site_tests.py b/tests/site_tests.py
index cbce977..1f169b0 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -91,7 +91,8 @@
"""Test cases for methods manipulating namespace names"""
builtins = {
- 'Talk': 1, # these should work in any MW wiki
+ '': 0, # these should work in any MW wiki
+ 'Talk': 1,
'User': 2,
'User talk': 3,
'Project': 4,
--
To view, visit https://gerrit.wikimedia.org/r/142735
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I58d67501e00ff9f1afdbdde97ac43bd7aeb40963
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>