jenkins-bot has submitted this change and it was merged.
Change subject: update namespace aliases
......................................................................
update namespace aliases
Change-Id: Ifdcadbcc1a73a414984f70c4536bcf2560838ee1
---
M wikipedia.py
1 file changed, 4 insertions(+), 10 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/wikipedia.py b/wikipedia.py
index 052b610..d5a08de 100644
--- a/wikipedia.py
+++ b/wikipedia.py
@@ -813,8 +813,7 @@
pageInfo = data['query']['pages'].values()[0]
if data['query']['pages'].keys()[0] == "-1":
if 'missing' in pageInfo:
- raise NoPage(self.site(), unicode(self),
-"Page does not exist. In rare cases, if you are certain the page does exist, look into overriding family.RversionTab")
+ raise NoPage(self.site(), unicode(self), "Page does not exist.")
elif 'invalid' in pageInfo:
raise BadTitle('BadTitle: %s' % self)
elif 'revisions' in pageInfo: #valid Title
@@ -4580,9 +4579,7 @@
pageInfo = ndata['query']['pages'].values()[0]
if data['query']['pages'].keys()[0] == "-1":
if 'missing' in pageInfo:
- raise NoPage(self.site(), unicode(self),
-"Page does not exist. In rare cases, if you are certain the page does exist, "
- "look into overriding family.RversionTab")
+ raise NoPage(self.site(), unicode(self), "Page does not exist.")
elif 'invalid' in pageInfo:
raise BadTitle('BadTitle: %s' % self)
elif 'revisions' in pageInfo: #valid Title
@@ -4674,9 +4671,7 @@
raise RuntimeError("API query error: %s" % data)
pageInfo = entities
if 'missing' in pageInfo:
- raise NoPage(self.site(), unicode(self),
-"Page does not exist. In rare cases, if you are certain the page does exist, "
- "look into overriding family.RversionTab")
+ raise NoPage(self.site(), unicode(self), "Page does not exist.")
elif 'invalid' in pageInfo:
raise BadTitle('BadTitle: %s' % self)
return entities
@@ -4708,8 +4703,7 @@
raise RuntimeError("API query error: %s" % data)
pageInfo = search
if 'missing' in pageInfo:
- raise NoPage(self.site(), unicode(self),
-"Page does not exist. In rare cases, if you are certain the page does exist, look into overriding family.RversionTab")
+ raise NoPage(self.site(), unicode(self), "Page does not exist.")
elif 'invalid' in pageInfo:
raise BadTitle('BadTitle: %s' % self)
--
To view, visit https://gerrit.wikimedia.org/r/90564
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifdcadbcc1a73a414984f70c4536bcf2560838ee1
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: user-config: simple configuration for single username
......................................................................
user-config: simple configuration for single username
Useful for bot with SUL.
Allows the use of '*' as lang in user-config.py file,
instead of listing all languages (~300)
Change-Id: I54148aa34c20082a638ffa45e8ceda80063e917b
---
M generate_user_files.py
M pywikibot/__init__.py
M pywikibot/config2.py
3 files changed, 11 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/generate_user_files.py b/generate_user_files.py
index 914222a..b28f4df 100644
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -238,7 +238,8 @@
mylang = '%s'
# The dictionary usernames should contain a username for each site where you
-# have a bot account.
+# have a bot account. If you have a unique username for all languages of a
+# family , you can use '*'
usernames['%s']['%s'] = u'%s'
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index b3f5438..8fe058c 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -282,6 +282,11 @@
user = config.usernames[fam][code]
except KeyError:
user = None
+ if user is None:
+ try:
+ user = config.usernames[fam]['*']
+ except KeyError:
+ user = None
if sysop is None:
try:
sysop = config.sysopnames[fam][code]
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 1085ddc..af4ee98 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -38,14 +38,16 @@
# The dictionary usernames should contain a username for each site where you
# have a bot account. Please set your usernames by adding such lines to your
# user-config.py:
-#
# usernames['wikipedia']['de'] = 'myGermanUsername'
# usernames['wiktionary']['en'] = 'myEnglishUsername'
+#
+# If you have a unique username for all languages of a family,
+# you can use '*'
+# usernames['wikibooks']['*'] = 'mySingleUsername'
#
# If you have a sysop account on some wikis, this will be used to delete pages
# or to edit locked pages if you add such lines to your
# user-config.py:
-#
# sysopnames['wikipedia']['de'] = 'myGermanUsername'
# sysopnames['wiktionary']['en'] = 'myEnglishUsername'
usernames = {}
--
To view, visit https://gerrit.wikimedia.org/r/90136
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I54148aa34c20082a638ffa45e8ceda80063e917b
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Beta16 <l.rabinelli(a)gmail.com>
Gerrit-Reviewer: Beta16 <l.rabinelli(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: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: mw version 1.22wmf21
......................................................................
mw version 1.22wmf21
Change-Id: Id0239aa533525feeace335b7730f60c9469fc90f
---
M pywikibot/family.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/family.py b/pywikibot/family.py
index e446471..fc8ef51 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1065,7 +1065,7 @@
"""Return Wikimedia projects version number as a string."""
# Don't use this, use versionnumber() instead. This only exists
# to not break family files.
- return '1.22wmf20'
+ return '1.22wmf21'
def shared_image_repository(self, code):
return ('commons', 'commons')
--
To view, visit https://gerrit.wikimedia.org/r/90920
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id0239aa533525feeace335b7730f60c9469fc90f
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Bug 54726 - Add Windows unicode cmd argument support
......................................................................
Bug 54726 - Add Windows unicode cmd argument support
Instead of working with the encoded sys.argv, we now use the unicode
pywikibot.argvu, which is set by the active userinterface. The UI
knows how to get the correct unicode argv (depending on OS).
pwb.py is adapted to use pwb.argvu in addition to sys.argv
Change-Id: Ifde7e42587f4a4493ca3c5d8f5ed1ab06bbd806b
---
M pwb.py
M pywikibot/bot.py
M pywikibot/userinterfaces/terminal_interface_base.py
M pywikibot/userinterfaces/terminal_interface_win32.py
M tests/ui_tests.py
5 files changed, 46 insertions(+), 32 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 04eb17e..08e586e 100644
--- a/pwb.py
+++ b/pwb.py
@@ -23,12 +23,11 @@
import sys
-def run_python_file(filename, args):
+def run_python_file(filename, argv, argvu):
"""Run a python file as if it were the main program on the command line.
`filename` is the path to the file to execute, it need not be a .py file.
- `args` is the argument array to present as sys.argv, including the first
- element representing the file being executed.
+ `args` is the argument array to present as sys.argv, as unicode strings.
"""
# Create a module to serve as __main__
@@ -40,8 +39,11 @@
# Set sys.argv and the first path element properly.
old_argv = sys.argv
+ old_argvu = pwb.argvu
old_path0 = sys.path[0]
- sys.argv = args
+
+ sys.argv = argv
+ pwb.argvu = argvu
sys.path[0] = os.path.dirname(filename)
try:
@@ -54,6 +56,7 @@
# Restore the old argv and path
sys.argv = old_argv
sys.path[0] = old_path0
+ pwb.argvu = old_argvu
#### end of snippet
@@ -87,9 +90,11 @@
print "Please follow the prompts to create it:"
run_python_file('generate_user_files.py', ['generate_user_files.py'])
+import pywikibot as pwb
if len(sys.argv) > 1:
fn = sys.argv[1]
- args = sys.argv[1:]
+ argv = sys.argv[1:]
+ argvu = pwb.argvu[1:]
if not os.path.exists(fn):
testpath = os.path.join(os.path.split(__file__)[0], 'scripts', fn)
@@ -101,4 +106,4 @@
fn = testpath
else:
raise Exception("%s not found!" % fn)
- run_python_file(fn, args)
+ run_python_file(fn, argv, argvu)
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 45c1098..bb793c8 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -40,10 +40,10 @@
% config.userinterface,
fromlist=['UI'])
ui = uiModule.UI()
+argvu = ui.argvu()
# Logging module configuration
-
class RotatingFileHandler(logging.handlers.RotatingFileHandler):
def doRollover(self):
@@ -493,8 +493,6 @@
# Command line parsing and help
-
-
def calledModuleName():
"""Return the name of the module calling this function.
@@ -503,35 +501,17 @@
"""
# get commandline arguments
- called = sys.argv[0].strip()
+ called = argvu[0].strip()
if ".py" in called: # could end with .pyc, .pyw, etc. on some platforms
# clip off the '.py?' filename extension
called = called[:called.rindex('.py')]
return os.path.basename(called)
-def _decodeArg(arg):
- if sys.platform == 'win32':
- if config.console_encoding in ('cp437', 'cp850'):
- # Western Windows versions give parameters encoded as windows-1252
- # even though the console encoding is cp850 or cp437.
- return unicode(arg, 'windows-1252')
- elif config.console_encoding == 'cp852':
- # Central/Eastern European Windows versions give parameters encoded
- # as windows-1250 even though the console encoding is cp852.
- return unicode(arg, 'windows-1250')
- else:
- return unicode(arg, config.console_encoding)
- else:
- # Linux uses the same encoding for both.
- # I don't know how non-Western Windows versions behave.
- return unicode(arg, config.console_encoding)
-
-
def handleArgs(*args):
"""Handle standard command line arguments, return the rest as a list.
- Takes the commandline arguments, converts them to Unicode, processes all
+ Takes the commandline arguments as Unicode strings, processes all
global parameters such as -lang or -log. Returns a list of all arguments
that are not global. This makes sure that global arguments are applied
first, regardless of the order in which the arguments were given.
@@ -541,7 +521,10 @@
"""
# get commandline arguments if necessary
if not args:
- args = sys.argv[1:]
+ # it's the version in pywikibot.__init__ that is changed by scripts,
+ # not the one in pywikibot.bot.
+ from pywikibot import argvu
+ args = argvu[1:]
# get the name of the module calling this function. This is
# required because the -help option loads the module's docstring and because
# the module name will be used for the filename of the log.
@@ -552,7 +535,6 @@
username = None
do_help = False
for arg in args:
- arg = _decodeArg(arg)
if arg == '-help':
do_help = True
elif arg.startswith('-family:'):
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index 84f7102..b1fcbe1 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -45,6 +45,7 @@
self.stdin = sys.stdin
self.stdout = sys.stdout
self.stderr = sys.stderr
+ self.argv = sys.argv
self.encoding = config.console_encoding
self.transliteration_target = config.transliteration_target
@@ -262,6 +263,9 @@
return wikipedia.input(
u'What is the solution of the CAPTCHA at this url ?')
+ def argvu(self):
+ return [s.decode(self.encoding) for s in self.argv]
+
class TerminalHandler(logging.Handler):
"""A handler class that writes logging records, appropriately formatted, to
diff --git a/pywikibot/userinterfaces/terminal_interface_win32.py b/pywikibot/userinterfaces/terminal_interface_win32.py
index 3507701..3b8cea1 100755
--- a/pywikibot/userinterfaces/terminal_interface_win32.py
+++ b/pywikibot/userinterfaces/terminal_interface_win32.py
@@ -48,10 +48,11 @@
class Win32CtypesUI(Win32BaseUI):
def __init__(self):
Win32BaseUI.__init__(self)
- from win32_unicode import stdin, stdout, stderr
+ from win32_unicode import stdin, stdout, stderr, argv
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
+ self.argv = argv
self.encoding = 'utf-8'
def printColorized(self, text, targetStream):
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index 5f49727..ad8f8be 100644
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -456,6 +456,28 @@
self.assertEqual(returned, u"Заглавная_страница")
+ class TestWindowsTerminalUnicodeArguments(WindowsTerminalTestCase):
+ @classmethod
+ def setUpClass(cls):
+ import inspect
+ cls.setUpProcess(["cmd", "/k", "echo off"])
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.tearDownProcess()
+ pass
+
+ def testOutputUnicodeText_no_transliterate(self):
+ self.sendstdin(u"""python -c "import os, pywikibot; os.system('cls'); pywikibot.output(u'\\n'.join(pywikibot.handleArgs()))" Alpha Bετα Гамма دلتا\n""")
+ while(True):
+ lines = self.getstdouterr().split("\n")
+ if len(lines) >= 4 and lines[0] == "Alpha":
+ break
+ time.sleep(1)
+
+ # empty line is the new command line
+ self.assertEqual(lines, [u"Alpha", u"Bετα", u"Гамма", u"دلتا", u""])
+
try:
try:
unittest.main()
--
To view, visit https://gerrit.wikimedia.org/r/86386
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifde7e42587f4a4493ca3c5d8f5ed1ab06bbd806b
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Catlib: Removed duplicated code and refactored
......................................................................
Catlib: Removed duplicated code and refactored
Change-Id: I6073e170c511631ea802d54f4e5fdec26ceb3786
---
M pywikibot/page.py
1 file changed, 48 insertions(+), 74 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index e17acf2..cb06350 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1416,102 +1416,76 @@
def change_category(self, oldCat, newCat, comment=None, sortKey=None,
inPlace=True):
- """Remove page from oldCat and add it to newCat.
+ """
+ Remove page from oldCat and add it to newCat.
- oldCat and newCat should be Category objects.
- If newCat is None, the category will be removed.
+ @param oldCat and newCat: should be Category objects.
+ If newCat is None, the category will be removed.
- comment: string to use as an edit summary
+ @param comment: string to use as an edit summary
- sortKey: sortKey to use for the added category.
- Unused if newCat is None, or if inPlace=True
+ @param sortKey: sortKey to use for the added category.
+ Unused if newCat is None, or if inPlace=True
+
+ @param inPlace: if True, change categories in place rather than
+ rearranging them.
"""
- #TODO: is inPlace necessary?
+ #get list of Category objects the article is in and remove possible duplicates
+ cats = []
+ for cat in self.categories(get_redirect=True):
+ if cat not in cats:
+ cats.append(cat)
+
site = self.site
- changesMade = False
+
+ if not sortKey:
+ sortKey = oldCat.sortKey
if not self.canBeEdited():
pywikibot.output(u"Can't edit %s, skipping it..."
% self.title(asLink=True))
- return False
- if inPlace:
- newtext = pywikibot.replaceCategoryInPlace(self.text,
- oldCat, newCat)
- if newtext == self.text:
- pywikibot.output(
- u'No changes in made in page %s.'
- % self.title(asLink=True))
- return False
- try:
- self.put(newtext, comment)
- return True
- except pywikibot.EditConflict:
- pywikibot.output(
- u'Skipping %s because of edit conflict'
- % self.title(asLink=True))
- except pywikibot.LockedPage:
- pywikibot.output(u'Skipping locked page %s'
- % self.title(asLink=True))
- except pywikibot.SpamfilterError, error:
- pywikibot.output(
- u'Changing page %s blocked by spam filter (URL=%s)'
- % (self.title(asLink=True), error.url))
- except pywikibot.NoUsername:
- pywikibot.output(
- u"Page %s not saved; sysop privileges required."
- % self.title(asLink=True))
- except pywikibot.PageNotSaved, error:
- pywikibot.output(u"Saving page %s failed: %s"
- % (self.title(asLink=True), error.message))
- return False
+ return
- # This loop will replace all occurrences of the category to be changed,
- # and remove duplicates.
- newCatList = []
- newCatSet = set()
- cats = list(self.categories(get_redirect=True))
- for i in range(len(cats)):
- cat = cats[i]
- if cat == oldCat:
- changesMade = True
- if not sortKey:
- sortKey = cat.sortKey
- if newCat:
- if newCat.title() not in newCatSet:
- newCategory = Category(site, newCat.title(),
- sortKey=sortKey)
- newCatSet.add(newCat.title())
- newCatList.append(newCategory)
- elif cat.title() not in newCatSet:
- newCatSet.add(cat.title())
- newCatList.append(cat)
+ if oldCat not in cats:
+ pywikibot.error(u'%s is not in category %s!'
+ % (self.title(asLink=True), oldCat.title()))
+ return
- if not changesMade:
- pywikibot.output(u'ERROR: %s is not in category %s!'
- % (self.title(asLink=True), oldCat.title()))
+ if inPlace or self.namespace() == 10:
+ oldtext = self.get(get_redirect=True)
+ newtext = pywikibot.replaceCategoryInPlace(oldtext, oldCat, newCat)
else:
+ if newCat:
+ cats[cats.index(oldCat)] = Category(site, newCat.title(), sortKey=sortKey)
+ else:
+ cats.pop(cats.index(oldCat))
+ oldtext = self.get(get_redirect=True)
try:
- text = pywikibot.replaceCategoryLinks(self.text, newCatList)
+ newtext = pywikibot.replaceCategoryLinks(oldtext, cats)
except ValueError:
# Make sure that the only way replaceCategoryLinks() can return
# a ValueError is in the case of interwiki links to self.
- pywikibot.output(
- u'Skipping %s because of interwiki link to self' % self)
+ pywikibot.output(u'Skipping %s because of interwiki link to self'
+ % self.title())
+
+ if oldtext != newtext:
try:
- self.put(text, comment)
+ self.put(newtext, comment)
except pywikibot.EditConflict:
- pywikibot.output(
- u'Skipping %s because of edit conflict' % self.title())
+ pywikibot.output(u'Skipping %s because of edit conflict'
+ % self.title())
except pywikibot.SpamfilterError, e:
- pywikibot.output(
- u'Skipping %s because of blacklist entry %s'
- % (self.title(), e.url))
+ pywikibot.output(u'Skipping %s because of blacklist entry %s'
+ % (self.title(), e.url))
except pywikibot.LockedPage:
- pywikibot.output(
- u'Skipping %s because page is locked' % self.title())
+ pywikibot.output(u'Skipping %s because page is locked'
+ % self.title())
+ except pywikibot.NoUsername:
+ pywikibot.output(u'Page %s not saved; sysop privileges required.'
+ % self.title(asLink=True))
except pywikibot.PageNotSaved, error:
- pywikibot.output(u"Saving page %s failed: %s"
+ pywikibot.output(u'Saving page %s failed: %s'
% (self.title(asLink=True), error.message))
@property
--
To view, visit https://gerrit.wikimedia.org/r/90730
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6073e170c511631ea802d54f4e5fdec26ceb3786
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(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