jenkins-bot has submitted this change and it was merged.
Change subject: Move unrelated parts of cosmetic_changes.py back to scripts folder
......................................................................
Move unrelated parts of cosmetic_changes.py back to scripts folder
These parts are only useful when the user wants to run as
a stand-alone script.
Change-Id: Iaccff3a58ebd6df07e5c2eaaccd04279a62bebe1
---
M pywikibot/cosmetic_changes.py
A scripts/cosmetic_changes.py
2 files changed, 143 insertions(+), 110 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 84e7db1..9c471fe 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -5,24 +5,7 @@
The changes are not supposed to change the look of the rendered wiki page.
-The following parameters are supported:
-
-¶ms;
-
--always Don't prompt you for each replacement. Warning (see below)
- has not to be confirmed. ATTENTION: Use this with care!
-
--async Put page on queue to be saved to wiki asynchronously.
-
--summary:XYZ Set the summary message text for the edit to XYZ, bypassing
- the predefined message texts with original and replacements
- inserted.
-
--ignore: Ignores if an error occured and skip either the page, or
- only that method, or only an instance of the problem in the
- page text. It can be set to 'page', 'method', or
'match'.
-
-&warning;
+If you wish to run this as an stand-alone script, use scripts/cosmetic_changes.py
For regular use, it is recommended to put this line into your user-config.py:
@@ -93,8 +76,7 @@
import pywikibot
-from pywikibot import config, i18n, textlib, pagegenerators
-from pywikibot.bot import ExistingPageBot, NoRedirectPageBot
+from pywikibot import config, textlib, pagegenerators
from pywikibot.page import url2unicode
from pywikibot.tools import deprecate_arg, first_lower, first_upper
from pywikibot.tools import MediaWikiVersion
@@ -958,93 +940,3 @@
"""Hyphenate ISBN numbers."""
return _reformat_ISBNs(
text, strict=False if self.ignore == CANCEL_MATCH else True)
-
-
-class CosmeticChangesBot(ExistingPageBot, NoRedirectPageBot):
-
- """Cosmetic changes bot."""
-
- def __init__(self, generator, **kwargs):
- self.availableOptions.update({
- 'async': False,
- 'comment': u'Robot: Cosmetic changes',
- 'ignore': CANCEL_ALL,
- })
- super(CosmeticChangesBot, self).__init__(**kwargs)
-
- self.generator = generator
-
- def treat_page(self):
- """Treat page with the cosmetic toolkit."""
- try:
- ccToolkit = CosmeticChangesToolkit.from_page(
- self.current_page, False, self.getOption('ignore'))
- changedText = ccToolkit.change(self.current_page.get())
- if changedText is not False:
- self.put_current(new_text=changedText,
- summary=self.getOption('comment'),
- async=self.getOption('async'))
- except pywikibot.LockedPage:
- pywikibot.output("Page %s is locked?!"
- % self.current_page.title(asLink=True))
- except pywikibot.EditConflict:
- pywikibot.output("An edit conflict has occured at %s."
- % self.current_page.title(asLink=True))
-
-
-def main(*args):
- """
- Process command line arguments and invoke bot.
-
- If args is an empty list, sys.argv is used.
-
- @param args: command line arguments
- @type args: list of unicode
- """
- options = {}
-
- # Process global args and prepare generator args parser
- local_args = pywikibot.handle_args(args)
- genFactory = pagegenerators.GeneratorFactory()
-
- for arg in local_args:
- if arg.startswith('-summary:'):
- options['comment'] = arg[len('-summary:'):]
- elif arg == '-always':
- options['always'] = True
- elif arg == '-async':
- options['async'] = True
- elif arg.startswith('-ignore:'):
- ignore_mode = arg[len('-ignore:'):].lower()
- if ignore_mode == 'method':
- options['ignore'] = CANCEL_METHOD
- elif ignore_mode == 'page':
- options['ignore'] = CANCEL_PAGE
- elif ignore_mode == 'match':
- options['ignore'] = CANCEL_MATCH
- else:
- raise ValueError('Unknown ignore mode
"{0}"!'.format(ignore_mode))
- else:
- genFactory.handleArg(arg)
-
- site = pywikibot.Site()
-
- if 'comment' not in options or not options['comment']:
- # Load default summary message.
- options['comment'] = i18n.twtranslate(site,
- 'cosmetic_changes-standalone')
-
- gen = genFactory.getCombinedGenerator()
- if gen:
- if options.get('always') or pywikibot.input_yn(
- warning + '\nDo you really want to continue?',
- default=False, automatic_quit=False):
- site.login()
- preloadingGen = pagegenerators.PreloadingGenerator(gen)
- bot = CosmeticChangesBot(preloadingGen, **options)
- bot.run()
- else:
- pywikibot.showHelp()
-
-if __name__ == "__main__":
- main()
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
new file mode 100644
index 0000000..1ae4bf6
--- /dev/null
+++ b/scripts/cosmetic_changes.py
@@ -0,0 +1,141 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+This module can do slight modifications to tidy a wiki page's source code.
+
+The changes are not supposed to change the look of the rendered wiki page.
+
+The following parameters are supported:
+
+¶ms;
+
+-always Don't prompt you for each replacement. Warning (see below)
+ has not to be confirmed. ATTENTION: Use this with care!
+
+-async Put page on queue to be saved to wiki asynchronously.
+
+-summary:XYZ Set the summary message text for the edit to XYZ, bypassing
+ the predefined message texts with original and replacements
+ inserted.
+
+-ignore: Ignores if an error occured and either skips the page or
+ only that method. It can be set to 'page' or 'method'.
+
+&warning;
+
+For further information see pywikibot/cosmetic_changes.py
+"""
+#
+# (C) xqt, 2009-2013
+# (C) Pywikibot team, 2006-2015
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+#
+
+import pywikibot
+from pywikibot import i18n, pagegenerators, cosmetic_changes
+from pywikibot.bot import ExistingPageBot, NoRedirectPageBot
+
+
+warning = """
+ATTENTION: You can run this script as a stand-alone for testing purposes.
+However, the changes that are made are only minor, and other users
+might get angry if you fill the version histories and watchlists with such
+irrelevant changes. Some wikis prohibit stand-alone running."""
+
+docuReplacements = {
+ '¶ms;': pagegenerators.parameterHelp,
+ '&warning;': warning,
+}
+
+
+class CosmeticChangesBot(ExistingPageBot, NoRedirectPageBot):
+
+ """Cosmetic changes bot."""
+
+ def __init__(self, generator, **kwargs):
+ self.availableOptions.update({
+ 'async': False,
+ 'summary': u'Robot: Cosmetic changes',
+ 'ignore': cosmetic_changes.CANCEL_ALL,
+ })
+ super(CosmeticChangesBot, self).__init__(**kwargs)
+
+ self.generator = generator
+
+ def treat_page(self):
+ """Treat page with the cosmetic toolkit."""
+ try:
+ ccToolkit = cosmetic_changes.CosmeticChangesToolkit.from_page(
+ self.current_page, False, self.getOption('ignore'))
+ changedText = ccToolkit.change(self.current_page.get())
+ if changedText is not False:
+ self.put_current(new_text=changedText,
+ summary=self.getOption('summary'),
+ async=self.getOption('async'))
+ except pywikibot.LockedPage:
+ pywikibot.output("Page %s is locked?!"
+ % self.current_page.title(asLink=True))
+ except pywikibot.EditConflict:
+ pywikibot.output("An edit conflict has occured at %s."
+ % self.current_page.title(asLink=True))
+
+
+def main(*args):
+ """
+ Process command line arguments and invoke bot.
+
+ If args is an empty list, sys.argv is used.
+
+ @param args: command line arguments
+ @type args: list of unicode
+ """
+ options = {}
+
+ # Process global args and prepare generator args parser
+ local_args = pywikibot.handle_args(args)
+ genFactory = pagegenerators.GeneratorFactory()
+
+ for arg in local_args:
+ if arg.startswith('-summary:'):
+ options['summary'] = arg[len('-summary:'):]
+ elif arg == '-always':
+ options['always'] = True
+ elif arg == '-async':
+ options['async'] = True
+ elif arg.startswith('-ignore:'):
+ ignore_mode = arg[len('-ignore:'):].lower()
+ if ignore_mode == 'method':
+ options['ignore'] = cosmetic_changes.CANCEL_METHOD
+ elif ignore_mode == 'page':
+ options['ignore'] = cosmetic_changes.CANCEL_PAGE
+ elif ignore_mode == 'match':
+ options['ignore'] = cosmetic_changes.CANCEL_MATCH
+ else:
+ raise ValueError('Unknown ignore mode
"{0}"!'.format(ignore_mode))
+ else:
+ genFactory.handleArg(arg)
+
+ site = pywikibot.Site()
+
+ if not options.get('summary'):
+ # Load default summary message.
+ options['summary'] = i18n.twtranslate(site,
+ 'cosmetic_changes-standalone')
+
+ gen = genFactory.getCombinedGenerator()
+ if gen:
+ if options.get('always') or pywikibot.input_yn(
+ warning + '\nDo you really want to continue?',
+ default=False, automatic_quit=False):
+ site.login()
+ preloadingGen = pagegenerators.PreloadingGenerator(gen)
+ bot = CosmeticChangesBot(preloadingGen, **options)
+ bot.run()
+ else:
+ pywikibot.showHelp()
+
+if __name__ == "__main__":
+ main()
--
To view, visit
https://gerrit.wikimedia.org/r/205843
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iaccff3a58ebd6df07e5c2eaaccd04279a62bebe1
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>