jenkins-bot submitted this change.

View Change

Approvals: Mpaa: Looks good to me, approved jenkins-bot: Verified
[help] Only show _GLOBAL_HELP options if explicitly wanted

- Many scripts have a long documentation to show all the options supported.
Now do not show global options by default but show a short hint how they
are printed. There are two ways:
-help:global prints the global options after the others
pwb.py -help prints the global options as well as pwb.py -help:global
- rename showHelp to show_help due to naming convention and deprecate the
old variant.
- reorder imports
- use module_name directly for import
- update casechecker.py
- update script_tests.py
- update pywikibot/__init__.py

Change-Id: I77bd3b9d214e5ecb866602bf7111375dc4cba31f
---
M pywikibot/__init__.py
M pywikibot/bot.py
M scripts/casechecker.py
M tests/script_tests.py
4 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 98c543c..9524911 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -24,7 +24,7 @@

from pywikibot._wbtypes import WbRepresentation as _WbRepresentation
from pywikibot.bot import (
- input, input_choice, input_yn, handle_args, showHelp, ui,
+ input, input_choice, input_yn, handle_args, show_help, ui,
calledModuleName, Bot, CurrentPageBot, WikidataBot,
# the following are flagged as deprecated on usage
handleArgs,
@@ -92,12 +92,13 @@
'output', 'Page', 'PageCreatedConflict', 'PageDeletedConflict',
'PageNotSaved', 'PageRelatedError', 'PageSaveRelatedError', 'PropertyPage',
'QuitKeyboardInterrupt', 'SectionError', 'Server504Error', 'ServerError',
- 'showDiff', 'showHelp', 'Site', 'SiteDefinitionError', 'SiteLink',
- 'SpamblacklistError', 'stdout', 'Timestamp', 'TitleblacklistError',
- 'translate', 'ui', 'unicode2html', 'UnknownExtension', 'UnknownFamily',
- 'UnknownSite', 'UnsupportedPage', 'UploadWarning', 'url2unicode', 'User',
- 'UserBlocked', 'warning', 'WbGeoShape', 'WbMonolingualText', 'WbQuantity',
- 'WbTabularData', 'WbTime', 'WbUnknown', 'WikiBaseError', 'WikidataBot',
+ 'showDiff', 'show_help', 'showHelp', 'Site', 'SiteDefinitionError',
+ 'SiteLink', 'SpamblacklistError', 'stdout', 'Timestamp',
+ 'TitleblacklistError', 'translate', 'ui', 'unicode2html',
+ 'UnknownExtension', 'UnknownFamily', 'UnknownSite', 'UnsupportedPage',
+ 'UploadWarning', 'url2unicode', 'User', 'UserBlocked', 'warning',
+ 'WbGeoShape', 'WbMonolingualText', 'WbQuantity', 'WbTabularData', 'WbTime',
+ 'WbUnknown', 'WikiBaseError', 'WikidataBot',
)


@@ -1403,3 +1404,5 @@
wrapper._add_deprecated_attr('__release__', __version__,
replacement_name='pywikibot.__version__',
since='20200707')
+wrapper._add_deprecated_attr('showHelp', show_help,
+ since='20200705', future_warning=True)
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index da21a7f..34eead8 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -72,7 +72,7 @@
'QuitKeyboardInterrupt',
'InteractiveReplace',
'calledModuleName', 'handle_args', 'handleArgs',
- 'showHelp', 'suggest_help',
+ 'show_help', 'showHelp', 'suggest_help',
'writeToCommandLogFile', 'open_webbrowser',
'OptionHandler',
'BaseBot', 'Bot', 'ConfigParserBot', 'SingleSiteBot', 'MultipleSitesBot',
@@ -128,7 +128,6 @@
from pywikibot.tools._logging import LoggingFormatter, RotatingFileHandler
from pywikibot.tools.formatter import color_format

-
# Note: all output goes through python std library "logging" module
_logger = 'bot'

@@ -165,7 +164,7 @@
-help Show this help text.

-log Enable the log file, using the default filename
- '%s-bot.log'
+ '{}-bot.log'
Logs will be stored in the logs subdirectory.

-log:xyz Enable the log file, using 'xyz' as the filename.
@@ -202,6 +201,13 @@

"""

+_GLOBAL_HELP_NOTE = """
+GLOBAL OPTIONS
+==============
+For global options use -help:global or run pwb.py -help
+
+"""
+

class UnhandledAnswer(Exception):

@@ -767,7 +773,7 @@
for arg in args:
option, _, value = arg.partition(':')
if do_help is not False and option == '-help':
- do_help = True
+ do_help = value or True
elif option == '-dir':
pass
elif option == '-family':
@@ -856,7 +862,7 @@
pywikibot.output('Python ' + sys.version)

if do_help:
- showHelp()
+ show_help(show_global=do_help == 'global')
sys.exit(0)

debug('handle_args() completed.', _logger)
@@ -869,7 +875,7 @@
return handle_args(args)


-def showHelp(module_name=None):
+def show_help(module_name=None, show_global=False):
"""Show help for the Bot."""
if not module_name:
module_name = calledModuleName()
@@ -879,19 +885,29 @@
except NameError:
module_name = 'no_module'

- global_help = _GLOBAL_HELP % module_name
try:
- module = import_module('%s' % module_name)
+ module = import_module(module_name)
help_text = module.__doc__
if hasattr(module, 'docuReplacements'):
for key, value in module.docuReplacements.items():
help_text = help_text.replace(key, value.strip('\n\r'))
- pywikibot.stdout(help_text) # output to STDOUT
except Exception:
if module_name:
- pywikibot.stdout('Sorry, no help available for %s' % module_name)
- pywikibot.log('showHelp:', exc_info=True)
- pywikibot.stdout(global_help)
+ pywikibot.stdout('Sorry, no help available for ' + module_name)
+ pywikibot.log('show_help:', exc_info=True)
+ else:
+ pywikibot.stdout(help_text) # output to STDOUT
+
+ if show_global or module_name == 'pwb':
+ pywikibot.stdout(_GLOBAL_HELP.format(module_name))
+ else:
+ pywikibot.stdout(_GLOBAL_HELP_NOTE)
+
+
+@deprecated('show_help', since='20200705')
+def showHelp(module_name=None):
+ """DEPRECATED. Use show_help()."""
+ return show_help(module_name)


def suggest_help(missing_parameters=[], missing_generator=False,
diff --git a/scripts/casechecker.py b/scripts/casechecker.py
index 4e76a00..7768c2b 100755
--- a/scripts/casechecker.py
+++ b/scripts/casechecker.py
@@ -121,7 +121,7 @@
self.doFailed = True
else:
pywikibot.output('Unknown argument {}.'.format(arg))
- pywikibot.showHelp()
+ pywikibot.show_help()
sys.exit()

if self.namespaces == [] and not self.doFailed:
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 6186a48..085a748 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -352,7 +352,7 @@
_expected_failures = {'version'}
_allowed_failures = []

- _arguments = '-help'
+ _arguments = '-help:global'
_results = None



To view, visit change 222762. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I77bd3b9d214e5ecb866602bf7111375dc4cba31f
Gerrit-Change-Number: 222762
Gerrit-PatchSet: 14
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw@arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa@disroot.org>
Gerrit-Reviewer: Russell Blau <russblau@imapmail.org>
Gerrit-Reviewer: XZise <CommodoreFabianus@gmx.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-MessageType: merged