jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] scripts: Sensible error information
......................................................................
[FEAT] scripts: Sensible error information
Instead of just printing the help text, scripts now specifically tell
what is wrong and don't print the help (just tell how to do it) so that
the error message doesn't get overlooked in the wall of text.
It additionally returns False if this occurs to make it possible for a caller
of main() to differentiate between success and failure. If it was easy to add
it also returns True if it could be run.
Bug: T91575
Change-Id: I01dc24dc91825446d24a0eb28e563eb9ddb70e87
---
M pywikibot/bot.py
M scripts/add_text.py
M scripts/archivebot.py
M scripts/basic.py
M scripts/blockreview.py
M scripts/capitalize_redirects.py
M scripts/category.py
M scripts/claimit.py
M scripts/clean_sandbox.py
M scripts/commons_link.py
M scripts/commonscat.py
M scripts/coordinate_import.py
M scripts/cosmetic_changes.py
M scripts/create_categories.py
M scripts/data_ingestion.py
M scripts/delete.py
M scripts/disambredir.py
M scripts/djvutext.py
M scripts/featured.py
M scripts/fixing_redirects.py
M scripts/illustrate_wikidata.py
M scripts/image.py
M scripts/imagetransfer.py
M scripts/imageuncat.py
M scripts/isbn.py
M scripts/listpages.py
M scripts/login.py
M scripts/makecat.py
M scripts/match_images.py
M scripts/movepages.py
M scripts/newitem.py
M scripts/noreferences.py
M scripts/pagefromfile.py
M scripts/piper.py
M scripts/protect.py
M scripts/redirect.py
M scripts/reflinks.py
M scripts/replace.py
M scripts/script_wui.py
M scripts/selflink.py
M scripts/solve_disambiguation.py
M scripts/spamremove.py
M scripts/template.py
M scripts/templatecount.py
M scripts/touch.py
M scripts/unlink.py
M scripts/unusedfiles.py
M scripts/weblinkchecker.py
M scripts/welcome.py
M tests/script_tests.py
50 files changed, 214 insertions(+), 120 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 2f85289..ec1c1de 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1249,6 +1249,44 @@
pywikibot.stdout(globalHelp)
+def suggest_help(missing_parameters=[], missing_generator=False,
+ unknown_parameters=[], exception=None,
+ missing_action=False, additional_text=''):
+ """
+ Output error message to use -help with additional text before it.
+
+ @param missing_parameters: A list of parameters which are missing.
+ @type missing_parameters: list of str
+ @param missing_generator: Whether a generator is missing.
+ @type missing_generator: bool
+ @param unknown_parameters: A list of parameters which are unknown.
+ @type unknown_parameters: list of str
+ @param exception: An exception thrown.
+ @type exception: Exception
+ @param missing_action: Add an entry that no action was defined.
+ @type missing_action: bool
+ @param additional_text: Additional text added to the end.
+ @type additional_text: str
+ """
+ if exception:
+ additional_text = ('An error occured: "{0}"'.format(exception)
+
+ additional_text)
+ if missing_generator:
+ additional_text = ('Unable to execute script because no generator was '
+ 'defined.\n' + additional_text)
+ if missing_parameters:
+ additional_text = 'Missing parameter(s) "{0}"\n'.format(
+ '", "'.join(missing_parameters)) + additional_text
+ if missing_action:
+ additional_text = 'No action defined.\n' + additional_text
+ if unknown_parameters:
+ additional_text = 'Unknown parameter(s) "{0}"\n'.format(
+ '", "'.join(unknown_parameters)) + additional_text
+ if not additional_text.endswith('\n'):
+ additional_text += '\n'
+ error(additional_text + 'Use -help for further information.')
+
+
def writeToCommandLogFile():
"""
Save name of the called module along with all parameters to logs/commands.log.
diff --git a/scripts/add_text.py b/scripts/add_text.py
index 7c03d85..b585321 100755
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -340,8 +340,8 @@
addText = f.read()
generator = genFactory.getCombinedGenerator()
if not generator:
- pywikibot.showHelp()
- return
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if not addText:
pywikibot.error("The text to add wasn't given.")
return
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 37ca904..49bcf45 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -640,11 +640,8 @@
if calc:
if not salt:
- pywikibot.showHelp()
- pywikibot.output(
- 'NOTE: you must specify a salt to calculate a key using '
- '-salt:SALT option.')
- return
+ pywikibot.bot.suggest_help(missing_parameters=['-salt'])
+ return False
page = pywikibot.Page(site, calc)
if page.exists():
calc = page.title()
@@ -660,9 +657,8 @@
salt = ''
if not args:
- pywikibot.showHelp()
- pywikibot.output(u'NOTE: you must specify a template to run the bot.')
- return
+ pywikibot.bot.suggest_help(additional_text='No template was specified.')
+ return False
for a in args:
pagelist = []
diff --git a/scripts/basic.py b/scripts/basic.py
index 7582c97..188c9a1 100755
--- a/scripts/basic.py
+++ b/scripts/basic.py
@@ -131,8 +131,10 @@
gen = pagegenerators.PreloadingGenerator(gen)
bot = BasicBot(gen)
bot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/blockreview.py b/scripts/blockreview.py
index 47b40bf..6be52a9 100755
--- a/scripts/blockreview.py
+++ b/scripts/blockreview.py
@@ -303,17 +303,14 @@
@param args: command line arguments
@type args: list of unicode
"""
- show = False
-
- # Parse command line arguments
- if pywikibot.handle_args(args):
- show = True
-
- if not show:
+ unknown_args = pywikibot.handle_args(args)
+ if unknown_args:
+ pywikibot.bot.suggest_help(unknown_parameters=unknown_args)
+ return False
+ else:
bot = BlockreviewBot()
bot.run()
- else:
- pywikibot.showHelp()
+ return True
if __name__ == "__main__":
main()
diff --git a/scripts/capitalize_redirects.py b/scripts/capitalize_redirects.py
index 82b93c0..3603041 100755
--- a/scripts/capitalize_redirects.py
+++ b/scripts/capitalize_redirects.py
@@ -120,8 +120,10 @@
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = CapitalizeBot(preloadingGen, **options)
bot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/category.py b/scripts/category.py
index ad4d119..587555c 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -1271,8 +1271,10 @@
finally:
if catDB:
catDB.dump()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_action=True)
+ return False
if __name__ == "__main__":
diff --git a/scripts/claimit.py b/scripts/claimit.py
index 099d9a2..ef634fe 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -203,12 +203,12 @@
generator = gen.getCombinedGenerator()
if not generator:
- # show help text from the top of this file
- pywikibot.showHelp()
- return
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
bot = ClaimRobot(generator, claims, exists_arg)
bot.run()
+ return True
if __name__ == "__main__":
main()
diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py
index b6d9824..46ed724 100755
--- a/scripts/clean_sandbox.py
+++ b/scripts/clean_sandbox.py
@@ -287,8 +287,13 @@
generator = gen_factory.getCombinedGenerator()
- bot = SandboxBot(generator=generator, **opts)
- bot.run()
+ if generator:
+ bot = SandboxBot(generator=generator, **opts)
+ bot.run()
+ return True
+
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/commons_link.py b/scripts/commons_link.py
index 17ed26f..3d1f974 100755
--- a/scripts/commons_link.py
+++ b/scripts/commons_link.py
@@ -132,14 +132,16 @@
else:
genFactory.handleArg(arg)
- if 'action' in options:
- gen = genFactory.getCombinedGenerator()
- if gen:
- gen = pagegenerators.PreloadingGenerator(gen)
- bot = CommonsLinkBot(gen, **options)
- bot.run()
- return
- pywikibot.showHelp()
+ gen = genFactory.getCombinedGenerator()
+ if 'action' in options and gen:
+ gen = pagegenerators.PreloadingGenerator(gen)
+ bot = CommonsLinkBot(gen, **options)
+ bot.run()
+ return True
+
+ pywikibot.bot.suggest_help(missing_action='action' not in options,
+ missing_generator=not gen)
+ return False
if __name__ == "__main__":
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 2289005..55cd8c1 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -533,8 +533,10 @@
pregenerator = pagegenerators.PreloadingGenerator(generator)
bot = CommonscatBot(pregenerator, **options)
bot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py
index e7fb94c..3a63791 100755
--- a/scripts/coordinate_import.py
+++ b/scripts/coordinate_import.py
@@ -127,8 +127,10 @@
if generator:
coordbot = CoordImportRobot(generator)
coordbot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index 3aff85f..de6afcf 100644
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -135,8 +135,10 @@
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = CosmeticChangesBot(preloadingGen, **options)
bot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/create_categories.py b/scripts/create_categories.py
index a133c80..3f4c3ac 100755
--- a/scripts/create_categories.py
+++ b/scripts/create_categories.py
@@ -107,14 +107,22 @@
else:
genFactory.handleArg(arg)
+ missing = set()
+ if not parent:
+ missing.add('-parent')
+ if not basename:
+ missing.add('-basename')
+
generator = genFactory.getCombinedGenerator()
- if generator and parent and basename:
+ if generator and missing:
bot = CreateCategoriesBot(generator, parent, basename, **options)
bot.run()
- pywikibot.output(u'All done')
+ pywikibot.output('All done')
+ return True
else:
- pywikibot.output(u'No pages to work on')
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_parameters=missing,
+ missing_generator=not generator)
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/data_ingestion.py b/scripts/data_ingestion.py
index 14faa89..b79f447 100755
--- a/scripts/data_ingestion.py
+++ b/scripts/data_ingestion.py
@@ -271,8 +271,10 @@
config_generator = genFactory.getCombinedGenerator()
if not config_generator or not csv_dir:
- pywikibot.showHelp()
- return
+ pywikibot.bot.suggest_help(
+ missing_parameters=[] if csv_dir else ['-csvdir'],
+ missing_generator=not config_generator)
+ return False
for config_page in config_generator:
try:
diff --git a/scripts/delete.py b/scripts/delete.py
index 0391072..41af4fa 100755
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -156,9 +156,10 @@
% ['',
'un'][options.get('undelete', False)])
bot = DeletionRobot(generator, summary, **options)
bot.run()
+ return True
else:
- # Show help text from the top of this file
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
diff --git a/scripts/disambredir.py b/scripts/disambredir.py
index 2d1ac32..50bed26 100755
--- a/scripts/disambredir.py
+++ b/scripts/disambredir.py
@@ -75,9 +75,8 @@
try:
mysite.disambcategory()
except pywikibot.Error as e:
- pywikibot.output(e)
- pywikibot.showHelp()
- return
+ pywikibot.bot.suggest_help(exception=e)
+ return False
generator = pagegenerators.CategorizedPageGenerator(
mysite.disambcategory(), start=start, content=True, namespaces=[0])
diff --git a/scripts/djvutext.py b/scripts/djvutext.py
index 688b19a..b72b0b7 100644
--- a/scripts/djvutext.py
+++ b/scripts/djvutext.py
@@ -158,7 +158,7 @@
# index is mandatory.
if not index:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_parameters=['-index'])
return False
# If djvu_path is not a fle, build djvu_path from dir+index.
diff --git a/scripts/featured.py b/scripts/featured.py
index 9e534b7..08bf8f9 100755
--- a/scripts/featured.py
+++ b/scripts/featured.py
@@ -627,11 +627,8 @@
else:
options[arg[1:].lower()] = True
- if options:
- bot = FeaturedBot(**options)
- bot.run()
- else:
- pywikibot.showHelp()
+ bot = FeaturedBot(**options)
+ bot.run()
if __name__ == "__main__":
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index 78821f2..b922626 100755
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -141,8 +141,10 @@
if gen:
for page in pagegenerators.PreloadingGenerator(gen):
workon(page)
+ return True
else:
- pywikibot.showHelp('fixing_redirects')
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/illustrate_wikidata.py b/scripts/illustrate_wikidata.py
index cc1e4e2..7a3bd60 100755
--- a/scripts/illustrate_wikidata.py
+++ b/scripts/illustrate_wikidata.py
@@ -116,11 +116,12 @@
generator = generator_factory.getCombinedGenerator()
if not generator:
- pywikibot.output('I need a generator with pages to work on')
- return
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
bot = IllustrateRobot(generator, wdproperty)
bot.run()
+ return True
if __name__ == "__main__":
main()
diff --git a/scripts/image.py b/scripts/image.py
index d7b61a2..b6038a3 100755
--- a/scripts/image.py
+++ b/scripts/image.py
@@ -205,8 +205,10 @@
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = ImageRobot(preloadingGen, old_image, new_image, **options)
bot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_parameters=['old image'])
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py
index c88d07e..8f4329f 100755
--- a/scripts/imagetransfer.py
+++ b/scripts/imagetransfer.py
@@ -338,8 +338,8 @@
page = pywikibot.Page(pywikibot.Site(), pageTitle)
gen = iter([page])
else:
- pywikibot.showHelp()
- return
+ pywikibot.bot.suggest_help(missing_parameters=['page'])
+ return False
if not targetLang and not targetFamily:
targetSite = pywikibot.Site('commons', 'commons')
diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py
index 85a6d7e..85a8bfc 100755
--- a/scripts/imageuncat.py
+++ b/scripts/imageuncat.py
@@ -1377,8 +1377,8 @@
generator = genFactory.getCombinedGenerator(gen=generator)
if not generator:
- pywikibot.output(
- u'You have to specify the generator you want to use for the
program!')
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
else:
pregenerator = pagegenerators.PreloadingGenerator(generator)
site.login()
@@ -1388,6 +1388,7 @@
and (not page.isRedirectPage()):
if isUncat(page):
addUncat(page)
+ return True
if __name__ == "__main__":
main()
diff --git a/scripts/isbn.py b/scripts/isbn.py
index b5357d1..170c43c 100755
--- a/scripts/isbn.py
+++ b/scripts/isbn.py
@@ -1650,8 +1650,10 @@
else:
bot = IsbnBot(preloadingGen, **options)
bot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/listpages.py b/scripts/listpages.py
index c89be5a..9153d99 100755
--- a/scripts/listpages.py
+++ b/scripts/listpages.py
@@ -232,8 +232,10 @@
with open(filename, mode='wb') as f:
f.write(page.text.encode(encoding))
pywikibot.output(u"%i page(s) found" % i)
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
diff --git a/scripts/login.py b/scripts/login.py
index 1e87a4e..43271e3 100755
--- a/scripts/login.py
+++ b/scripts/login.py
@@ -76,6 +76,7 @@
sysop = False
logall = False
logout = False
+ unknown_args = []
for arg in pywikibot.handle_args(args):
if arg.startswith("-pass"):
if len(arg) == 5:
@@ -94,8 +95,12 @@
elif arg == "-logout":
logout = True
else:
- pywikibot.showHelp('login')
- return
+ unknown_args += [arg]
+
+ if unknown_args:
+ pywikibot.bot.suggest_help(unknown_parameters=unknown_args)
+ return False
+
if logall:
if sysop:
namedict = config.sysopnames
diff --git a/scripts/makecat.py b/scripts/makecat.py
index ded4a20..47b652e 100755
--- a/scripts/makecat.py
+++ b/scripts/makecat.py
@@ -204,7 +204,7 @@
workingcatname = arg
if not workingcatname:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_parameters=['working category'])
sys.exit(0)
mysite = pywikibot.Site()
diff --git a/scripts/match_images.py b/scripts/match_images.py
index d74b715..cabef37 100755
--- a/scripts/match_images.py
+++ b/scripts/match_images.py
@@ -164,12 +164,10 @@
images.append(arg)
if len(images) != 2:
- pywikibot.showHelp('match_images')
- pywikibot.error('Require two images to work on.')
- return
-
- else:
- pass
+ pywikibot.bot.suggest_help(
+ additional_text='Unable to execute script because it '
+ 'requires two images to work on.')
+ return False
imagePageA = pywikibot.page.FilePage(pywikibot.Site(),
images[0])
diff --git a/scripts/movepages.py b/scripts/movepages.py
index a27837a..1b72afa 100755
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -270,8 +270,11 @@
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = MovePagesBot(preloadingGen, **options)
bot.run()
- elif not fromToPairs:
- pywikibot.showHelp()
+ return True
+ else:
+ # in theory pairs could be missing too
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == '__main__':
main()
diff --git a/scripts/newitem.py b/scripts/newitem.py
index fcf3873..e2e1783 100755
--- a/scripts/newitem.py
+++ b/scripts/newitem.py
@@ -144,11 +144,12 @@
generator = gen.getCombinedGenerator()
if not generator:
- pywikibot.showHelp()
- return
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
bot = NewItemRobot(generator, **options)
bot.run()
+ return True
if __name__ == "__main__":
main()
diff --git a/scripts/noreferences.py b/scripts/noreferences.py
index 11f03b0..6fb6204 100755
--- a/scripts/noreferences.py
+++ b/scripts/noreferences.py
@@ -735,8 +735,10 @@
if gen:
bot = NoReferencesBot(gen, **options)
bot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index 209355a..98d2ea6 100755
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -317,7 +317,8 @@
# show help text from the top of this file if reader failed
# or User quit.
if failed_filename:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_parameters=['-file'])
+ return False
else:
reader = PageFromFileReader(filename, pageStartMarker, pageEndMarker,
titleStartMarker, titleEndMarker, include,
diff --git a/scripts/piper.py b/scripts/piper.py
index a7af13d..f5d04eb 100755
--- a/scripts/piper.py
+++ b/scripts/piper.py
@@ -146,8 +146,10 @@
gen = pagegenerators.PreloadingGenerator(gen)
bot = PiperBot(gen, **options)
bot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == '__main__':
diff --git a/scripts/protect.py b/scripts/protect.py
index 750c1cf..c7f4b98 100755
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -250,9 +250,10 @@
u'Enter a reason for the protection change:')
bot = ProtectionRobot(generator, combined_protections, site, **options)
bot.run()
+ return True
else:
- # Show help text from the top of this file
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == '__main__':
diff --git a/scripts/redirect.py b/scripts/redirect.py
index e2b53ad..93f2b55 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -775,7 +775,13 @@
xmlFilename and moved_pages or
fullscan and xmlFilename
):
- pywikibot.showHelp()
+ problems = []
+ if xmlFilename and moved_pages:
+ problems += ['Either use a XML file or the moved pages from the
API']
+ if xmlFilename and fullscan:
+ problems += ['Either use a XML file or do a full scan using the
API']
+ pywikibot.bot.suggest_help(additional_text='\n'.join(problems),
+ missing_action=not action)
else:
pywikibot.Site().login()
gen = RedirectGenerator(xmlFilename, namespaces, offset, moved_pages,
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 197c445..28efd97 100755
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -838,13 +838,14 @@
if not generator:
generator = genFactory.getCombinedGenerator()
if not generator:
- # syntax error, show help text from the top of this file
- pywikibot.showHelp()
- return
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
+
generator = pagegenerators.PreloadingGenerator(generator, step=50)
generator = pagegenerators.RedirectFilterPageGenerator(generator)
bot = ReferencesRobot(generator, **options)
bot.run()
+ return True
if __name__ == "__main__":
main()
diff --git a/scripts/replace.py b/scripts/replace.py
index 31188d8..9a7f650 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -950,9 +950,8 @@
gen = genFactory.getCombinedGenerator(gen)
if not gen:
- # syntax error, show help text from the top of this file
- pywikibot.showHelp('replace')
- return
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = ReplaceRobot(preloadingGen, replacements, exceptions, acceptall,
diff --git a/scripts/script_wui.py b/scripts/script_wui.py
index aa87b53..daf7572 100755
--- a/scripts/script_wui.py
+++ b/scripts/script_wui.py
@@ -306,9 +306,10 @@
"""
global __simulate, __sys_argv
- for arg in pywikibot.handle_args(args):
- pywikibot.showHelp('script_wui')
- return
+ unknown_args = pywikibot.handle_args(args)
+ if unknown_args:
+ pywikibot.bot.suggest_help(unknown_parameters=unknown_args)
+ return False
__simulate = pywikibot.config.simulate
__sys_argv = sys.argv
diff --git a/scripts/selflink.py b/scripts/selflink.py
index 9502e8a..144dc3a 100755
--- a/scripts/selflink.py
+++ b/scripts/selflink.py
@@ -98,12 +98,13 @@
gen = genFactory.getCombinedGenerator()
if not gen:
- pywikibot.showHelp()
- return
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
preloadingGen = PreloadingGenerator(gen)
bot = SelflinkBot(preloadingGen, **botArgs)
bot.run()
+ return True
if __name__ == "__main__":
main()
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index 447f012..275b21c 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -1153,8 +1153,8 @@
generator = iter([page])
if not generator:
- pywikibot.showHelp()
- return
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
site.login()
diff --git a/scripts/spamremove.py b/scripts/spamremove.py
index c728e9b..269deb0 100755
--- a/scripts/spamremove.py
+++ b/scripts/spamremove.py
@@ -62,9 +62,8 @@
spamSite = arg
if not spamSite:
- pywikibot.showHelp()
- pywikibot.output(u"No spam site specified.")
- return
+ pywikibot.bot.suggest_help(missing_parameters=['spam site'])
+ return False
mysite = pywikibot.Site()
pages = mysite.exturlusage(spamSite, namespaces=namespaces, content=True)
diff --git a/scripts/template.py b/scripts/template.py
index 3cec5d9..c8d0810 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -323,8 +323,8 @@
templateNames.append(templateName.title(withNamespace=False))
if not templateNames:
- pywikibot.showHelp()
- return
+ pywikibot.bot.suggest_help(missing_parameters=['templates'])
+ return False
if options.get('subst', False) ^ options.get('remove', False):
for templateName in templateNames:
diff --git a/scripts/templatecount.py b/scripts/templatecount.py
index f875627..b7d2c42 100755
--- a/scripts/templatecount.py
+++ b/scripts/templatecount.py
@@ -133,8 +133,8 @@
argsList.append(arg)
if not operation:
- pywikibot.showHelp('templatecount')
- return
+ pywikibot.bot.suggest_help(missing_parameters=['operation'])
+ return False
robot = TemplateCountRobot()
if not argsList:
diff --git a/scripts/touch.py b/scripts/touch.py
index 20dad4c..fb1031c 100755
--- a/scripts/touch.py
+++ b/scripts/touch.py
@@ -96,8 +96,10 @@
bot = bot_class(generator=preloadingGen, **options)
pywikibot.Site().login()
bot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
diff --git a/scripts/unlink.py b/scripts/unlink.py
index 6672217..6baf5ad 100755
--- a/scripts/unlink.py
+++ b/scripts/unlink.py
@@ -166,8 +166,10 @@
page = pywikibot.Page(pywikibot.Site(), page_title)
bot = UnlinkBot(page, **options)
bot.run()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_parameters=['page title'])
+ return False
if __name__ == "__main__":
main()
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index 1db7922..36bd97a 100755
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -123,8 +123,10 @@
try:
bot.run()
except pywikibot.Error as e:
- pywikibot.showHelp()
- pywikibot.warning(e)
+ pywikibot.bot.suggest_help(exception=e)
+ return False
+ else:
+ return True
if __name__ == "__main__":
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py
index e3c8caf..2ccd232 100755
--- a/scripts/weblinkchecker.py
+++ b/scripts/weblinkchecker.py
@@ -938,8 +938,10 @@
bot.history.reportThread.kill()
pywikibot.output(u'Saving history...')
bot.history.save()
+ return True
else:
- pywikibot.showHelp()
+ pywikibot.bot.suggest_help(missing_generator=True)
+ return False
if __name__ == "__main__":
diff --git a/scripts/welcome.py b/scripts/welcome.py
index b77d9e2..cd82b74 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -992,9 +992,8 @@
bot = WelcomeBot()
except KeyError as error:
# site not managed by welcome.py
- pywikibot.showHelp()
- pywikibot.warning(error)
- return
+ pywikibot.bot.suggest_help(exception=error)
+ return False
try:
bot.run()
diff --git a/tests/script_tests.py b/tests/script_tests.py
index f7938cd..cdbdf87 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -102,6 +102,7 @@
'checkimages',
'clean_sandbox',
'disambredir',
+ 'featured',
'imagerecat',
'login',
'lonelypages',
@@ -123,25 +124,20 @@
# Some of these are not pretty, but at least they are informative
# and not backtraces starting deep in the pywikibot package.
no_args_expected_results = {
- 'archivebot': 'NOTE: you must specify a template to run the bot',
- 'create_categories': 'No pages to work on',
# TODO: until done here, remember to set editor = None in user_config.py
'editarticle': 'Nothing changed', # This masks related bug 68645 but
that
# bug is more broadly about config
# rather than editarticle.
'freebasemappingupload': 'Cannot find ',
'harvest_template': 'ERROR: Please specify',
- 'illustrate_wikidata': 'I need a generator with pages to work on',
'imageuncat': 'WARNING: This script is primarily written for Wikimedia
Commons',
# script_input['interwiki'] above lists a title that should not exist
'interwiki': 'does not exist. Skipping.',
'login': 'Logged in on ',
- 'match_images': 'Require two images to work on.',
'pagefromfile': 'Please enter the file name',
'replace': 'Press Enter to use this automatic message',
'script_wui': 'Pre-loading all relevant page contents',
'shell': ('>>> ', 'Welcome to the'),
- 'spamremove': 'No spam site specified',
'transferbot': 'Target site not different from source site', # Bug
68662
'unusedfiles': ('Working on', None),
'watchlist': 'Retrieving watchlist',
@@ -273,9 +269,13 @@
elif not is_autorun:
if stderr_other == ['']:
stderr_other = None
- self.assertIsNone(stderr_other)
- self.assertIn('Global arguments available for all',
- result['stdout'])
+ if stderr_other is not None:
+ self.assertIn('Use -help for further information.',
+ stderr_other)
+ self.assertNotIn('-help', args)
+ else:
+ self.assertIn('Global arguments available for all',
+ result['stdout'])
exit_codes = [0]
else:
--
To view, visit
https://gerrit.wikimedia.org/r/194542
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I01dc24dc91825446d24a0eb28e563eb9ddb70e87
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
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 <>