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
jenkins-bot has submitted this change and it was merged.
Change subject: [flickrripper] Fallback to photo_id for filename when no title is set
......................................................................
[flickrripper] Fallback to photo_id for filename when no title is set
Otherwise filename is invalid (leading space) and also duplicate.
Tested on Commons, all is well.
Change-Id: I5cc2d9fce0a7768527b6e14b88880e3c7630be8a
---
M flickrripper.py
1 file changed, 3 insertions(+), 4 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/flickrripper.py b/flickrripper.py
index 24d676e..5e7297c 100644
--- a/flickrripper.py
+++ b/flickrripper.py
@@ -140,7 +140,7 @@
return rawDescription.decode('utf-8')
-def getFilename(photoInfo=None, site=None, project=u'Flickr'):
+def getFilename(photoInfo=None, site=None, project=u'Flickr', photoId=None):
""" Build a good filename for the upload based on the username and the
title. Prevents naming collisions.
@@ -166,8 +166,7 @@
description = description[:items]
title = cleanUpTitle(description)
else:
- title = u''
- # Should probably have the id of the photo as last resort.
+ title = photoId
if pywikibot.Page(site, u'File:%s - %s - %s.jpg'
% (title, project, username)).exists():
@@ -256,7 +255,7 @@
if duplicates:
pywikibot.output(u'Found duplicate image at %s' % duplicates.pop())
else:
- filename = getFilename(photoInfo)
+ filename = getFilename(photoInfo, photoId=photo_id)
flinfoDescription = getFlinfoDescription(photo_id)
photoDescription = buildDescription(flinfoDescription,
flickrreview, reviewer,
--
To view, visit https://gerrit.wikimedia.org/r/90097
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5cc2d9fce0a7768527b6e14b88880e3c7630be8a
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Nemo bis <federicoleva(a)tiscali.it>
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: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: Nemo bis <federicoleva(a)tiscali.it>
Gerrit-Reviewer: Platonides <platonides(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Show page generators parameters in module documentation
......................................................................
Show page generators parameters in module documentation
Change-Id: I8e0f72a35d6923c54d45d31b179f105704af9a4b
---
M pywikibot/pagegenerators.py
1 file changed, 5 insertions(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
Mineo: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index d749dbc..fbc27c2 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -169,6 +169,11 @@
# if a bot uses GeneratorFactory, the module should include the line
# docuReplacements = {'¶ms;': pywikibot.pagegenerators.parameterHelp}
# and include the marker ¶ms; in the module's docstring
+#
+# We manually include it so the parameters show up in the auto-generated
+# module documentation:
+
+__doc__ = __doc__.replace("¶ms;", parameterHelp)
class GeneratorFactory(object):
--
To view, visit https://gerrit.wikimedia.org/r/90728
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8e0f72a35d6923c54d45d31b179f105704af9a4b
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mineo <themineo(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: Remove obsolete line from docstring (-api flag not used in core).
......................................................................
Remove obsolete line from docstring (-api flag not used in core).
Change-Id: I3b802c50ac08a9e229f306572f0e3e74f51dc475
---
M scripts/redirect.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Legoktm: Looks good to me, approved
Xqt: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/redirect.py b/scripts/redirect.py
index 57778ac..233cad9 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -13,7 +13,7 @@
double Fix redirects which point to other redirects
broken Delete redirects where targets don\'t exist. Requires adminship.
-both Both of the above. Permitted only with -api. Implies -api.
+both Both of the above.
and arguments can be:
--
To view, visit https://gerrit.wikimedia.org/r/90680
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3b802c50ac08a9e229f306572f0e3e74f51dc475
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Nemo bis <federicoleva(a)tiscali.it>
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: Ie90b6432f18e0de768c23db9f4f7e207196235ab
---
M catlib.py
1 file changed, 40 insertions(+), 56 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/catlib.py b/catlib.py
index 6e17363..c2ca83f 100644
--- a/catlib.py
+++ b/catlib.py
@@ -623,81 +623,62 @@
def change_category(article, oldCat, newCat, comment=None, sortKey=None,
inPlace=False):
- """Given an article which is in category oldCat, moves it to
- category newCat. Moves subcategories of oldCat as well.
- oldCat and newCat should be Category objects.
- If newCat is None, the category will be removed.
+ """
+ Remove page from oldCat and add it to newCat.
+
+ @param oldCat and newCat: should be Category objects.
+ If newCat is None, the category will be removed.
+
+ @param comment: string to use as an edit summary
+
+ @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.
"""
- cats = article.categories(get_redirect=True)
+ #get list of Category objects the article is in and remove possible duplicates
+ cats = []
+ for cat in article.categories(get_redirect=True):
+ if cat not in cats:
+ cats.append(cat)
+
site = article.site()
- changesMade = False
+
+ if not sortKey:
+ sortKey = oldCat.sortKey
if not article.canBeEdited():
pywikibot.output("Can't edit %s, skipping it..."
% article.title(asLink=True))
return
+
+ if oldCat not in cats:
+ pywikibot.error(u'%s is not in category %s!'
+ % (article.title(asLink=True), oldCat.title()))
+ return
+
if inPlace or article.namespace() == 10:
oldtext = article.get(get_redirect=True)
newtext = pywikibot.replaceCategoryInPlace(oldtext, oldCat, newCat)
- if newtext == oldtext:
- pywikibot.output(
- u'No changes in made in page %s.' % article.title(asLink=True))
- return
- try:
- article.put(newtext, comment)
- return True
- except pywikibot.EditConflict:
- pywikibot.output(u'Skipping %s because of edit conflict'
- % article.title(asLink=True))
- except pywikibot.LockedPage:
- pywikibot.output(u'Skipping locked page %s'
- % article.title(asLink=True))
- except pywikibot.SpamfilterError, error:
- pywikibot.output(u'Changing page %s blocked by spam filter (URL=%s)'
- % (article.title(asLink=True), error.url))
- except pywikibot.NoUsername:
- pywikibot.output(u'Page %s not saved; sysop privileges required.'
- % article.title(asLink=True))
- except pywikibot.PageNotSaved, error:
- pywikibot.output(u'Saving page %s failed: %s'
- % (article.title(asLink=True), error.message))
- return
-
- # This loop will replace all occurrences of the category to be changed,
- # and remove duplicates.
- newCatList = []
- newCatSet = set()
- 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 not changesMade:
- pywikibot.error(u'%s is not in category %s!'
- % (article.title(asLink=True), oldCat.title()))
else:
- text = article.get(get_redirect=True)
+ if newCat:
+ cats[cats.index(oldCat)] = Category(site, newCat.title(), sortKey=sortKey)
+ else:
+ cats.pop(cats.index(oldCat))
+ oldtext = article.get(get_redirect=True)
try:
- text = pywikibot.replaceCategoryLinks(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'
% article)
+
+ if oldtext != newtext:
try:
- article.put(text, comment)
+ article.put(newtext, comment)
except pywikibot.EditConflict:
pywikibot.output(u'Skipping %s because of edit conflict'
% article.title())
@@ -707,6 +688,9 @@
except pywikibot.LockedPage:
pywikibot.output(u'Skipping %s because page is locked'
% article.title())
+ except pywikibot.NoUsername:
+ pywikibot.output(u'Page %s not saved; sysop privileges required.'
+ % article.title(asLink=True))
except pywikibot.PageNotSaved, error:
pywikibot.output(u"Saving page %s failed: %s"
% (article.title(asLink=True), error.message))
--
To view, visit https://gerrit.wikimedia.org/r/90662
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie90b6432f18e0de768c23db9f4f7e207196235ab
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(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
Xqt has submitted this change and it was merged.
Change subject: win32_unicode: make sure argv always has a first element
......................................................................
win32_unicode: make sure argv always has a first element
If Python is started without script as argument, argv is [''], and thus
argvu should be [u''] and not [].
Change-Id: I380b85bfe11615289ab47a483b5d1746a5137a76
---
M pywikibot/userinterfaces/win32_unicode.py
1 file changed, 3 insertions(+), 0 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py
index 3646dc0..b06025a 100755
--- a/pywikibot/userinterfaces/win32_unicode.py
+++ b/pywikibot/userinterfaces/win32_unicode.py
@@ -256,3 +256,6 @@
if arg == u'-c':
argv[0] = u'-c'
break
+
+ if argv == []:
+ argv = [u'']
--
To view, visit https://gerrit.wikimedia.org/r/86385
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I380b85bfe11615289ab47a483b5d1746a5137a76
Gerrit-PatchSet: 4
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
Xqt has submitted this change and it was merged.
Change subject: Improve Windows Terminal UI tests
......................................................................
Improve Windows Terminal UI tests
- Refactored generic terminal testcase out of the Windows I/O testcase
- Getstdinout is now triggered by a sentinel being overwritten by the
copy operation
- Wait for the window to be ready before sending keys
- Add ui_tests.bat to run ui_tests correctly on Windows
Change-Id: Id132afbd51999a7db3974c0fddd5016c35c7a335
---
A tests/ui_tests.bat
M tests/ui_tests.py
2 files changed, 61 insertions(+), 12 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/tests/ui_tests.bat b/tests/ui_tests.bat
new file mode 100644
index 0000000..c497d6e
--- /dev/null
+++ b/tests/ui_tests.bat
@@ -0,0 +1,4 @@
+@echo off
+set PYTHONPATH=%~dp0..;%~dp0../externals
+set PYWIKIBOT2_DIR=%~dp0..
+"%~dp0ui_tests.py"
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index d4ba066..4b1634c 100644
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -7,6 +7,26 @@
#
# Distributed under the terms of the MIT license.
#
+
+# NOTE FOR RUNNING WINDOWS UI TESTS
+#
+# Windows UI tests have to be run using the tests\ui_tests.bat helper script.
+# This will set PYTHONPATH and PYWIKIBOT2_DIR, and then run the tests. Do not
+# touch mouse or keyboard while the tests are running, as this might disturb the
+# interaction tests.
+#
+# The Windows tests were developed on a Dutch Windows 7 OS. You might need to adapt the
+# helper functions in TestWindowsTerminalUnicode for other versions.
+#
+# For the Windows-based tests, you need the following packages installed:
+# - pywin32, for clipboard access, which can be downloaded here:
+# http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/
+# make sure to download the package for the correct python version!
+#
+# - pywinauto, to send keys to the terminal, which can be installed using:
+# easy_install --upgrade https://pywinauto.googlecode.com/files/pywinauto-0.4.2.zip
+#
+#
__version__ = '$Id$'
import unittest
@@ -15,6 +35,7 @@
import logging
import os
import sys
+import time
if os.name == "nt":
from multiprocessing.managers import BaseManager
@@ -328,19 +349,15 @@
self.assertEqual(newstderr.getvalue(), "abcd \x1b[33;1mA\x1b[0m\x1b[33;1mB\x1b[0m\x1b[33;1mG\x1b[0m\x1b[33;1mD\x1b[0m \x1b[33;1ma\x1b[0m\x1b[33;1mb\x1b[0m\x1b[33;1mg\x1b[0m\x1b[33;1md\x1b[0m \x1b[33;1ma\x1b[0m\x1b[33;1mi\x1b[0m\x1b[33;1mu\x1b[0m\x1b[33;1me\x1b[0m\x1b[33;1mo\x1b[0m\n\x1b[0m") # noqa
@unittest.skipUnless(os.name == "nt", "requires Windows console")
- class TestWindowsTerminalUnicode(UITestCase):
+ class WindowsTerminalTestCase(UITestCase):
@classmethod
- def setUpClass(cls):
- import inspect
+ def setUpProcess(cls, command):
import pywinauto
import subprocess
si = subprocess.STARTUPINFO()
si.dwFlags = subprocess.STARTF_USESTDHANDLES
- fn = inspect.getfile(inspect.currentframe())
- cls._process = subprocess.Popen(["python", "pwb.py", fn, "--run-as-slave-interpreter"],
+ cls._process = subprocess.Popen(command,
creationflags=subprocess.CREATE_NEW_CONSOLE)
- _manager.connect()
- cls.pywikibot = _manager.pywikibot()
cls._app = pywinauto.application.Application()
cls._app.connect_(process=cls._process.pid)
@@ -349,15 +366,29 @@
cls._app.window_().TypeKeys("% {UP}{ENTER}^L{HOME}L{ENTER}", with_spaces=True)
@classmethod
- def tearDownClass(cls):
- del cls.pywikibot
+ def tearDownProcess(cls):
cls._process.kill()
+ def setUp(self):
+ super(WindowsTerminalTestCase, self).setUp()
+ self.setclip(u'')
+
+ def waitForWindow(self):
+ while not self._app.window_().IsEnabled():
+ time.sleep(0.01)
+
def getstdouterr(self):
+ sentinel = u'~~~~SENTINEL~~~~cedcfc9f-7eed-44e2-a176-d8c73136c185'
# select all and copy to clipboard
self._app.window_().SetFocus()
+ self.waitForWindow()
self._app.window_().TypeKeys('% {UP}{UP}{UP}{RIGHT}{DOWN}{DOWN}{DOWN}{ENTER}{ENTER}', with_spaces=True)
- return self.getclip()
+
+ while True:
+ data = self.getclip()
+ if data != sentinel:
+ return data
+ time.sleep(0.01)
def setclip(self, text):
win32clipboard.OpenClipboard()
@@ -375,8 +406,23 @@
def sendstdin(self, text):
self.setclip(text.replace(u"\n", u"\r\n"))
self._app.window_().SetFocus()
+ self.waitForWindow()
self._app.window_().TypeKeys('% {UP}{UP}{UP}{RIGHT}{DOWN}{DOWN}{ENTER}', with_spaces=True)
- self.setclip(u'')
+
+ class TestWindowsTerminalUnicode(WindowsTerminalTestCase):
+ @classmethod
+ def setUpClass(cls):
+ import inspect
+ fn = inspect.getfile(inspect.currentframe())
+ cls.setUpProcess(["python", "pwb.py", fn, "--run-as-slave-interpreter"])
+
+ _manager.connect()
+ cls.pywikibot = _manager.pywikibot()
+
+ @classmethod
+ def tearDownClass(cls):
+ del cls.pywikibot
+ cls.tearDownProcess()
def setUp(self):
super(TestWindowsTerminalUnicode, self).setUp()
@@ -388,7 +434,6 @@
self.pywikibot.set_ui('encoding', 'utf-8')
self.pywikibot.cls()
- self.setclip(u'')
def testOutputUnicodeText_no_transliterate(self):
self.pywikibot.output(u"Заглавная_страница")
--
To view, visit https://gerrit.wikimedia.org/r/86384
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id132afbd51999a7db3974c0fddd5016c35c7a335
Gerrit-PatchSet: 4
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