jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/496796 )
Change subject: [IMPR] Start the script if its name is similar to the given script name. ......................................................................
[IMPR] Start the script if its name is similar to the given script name.
With I0fb163eef misspelled scripts are offered to the operator to choose the right one.
If only one script is found, start this without asking the bot owner but give him a notice and wait a bit to let it be cancelled.
Note: I0fb163eef must be merged first
Bug: T217195 Change-Id: I4b4873e7172d98f1c7d91ef76eea8d6f775809ee --- M pwb.py 1 file changed, 18 insertions(+), 5 deletions(-)
Approvals: Szynal: Looks good to me, but someone else must approve Dvorapa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py index 0fefb5a..d21d2d4 100755 --- a/pwb.py +++ b/pwb.py @@ -20,6 +20,7 @@ from importlib import import_module import os import sys +from time import sleep import types
from warnings import warn @@ -170,8 +171,9 @@
def find_alternates(filename, script_paths): """Search for similar filenames in the given script paths.""" - from pywikibot import input_choice + from pywikibot import input_choice, output from pywikibot.bot import ShowingListOption, QuitKeyboardInterrupt + from pywikibot.tools.formatter import color_format
print('ERROR: {} not found! Misspelling?'.format(filename), file=sys.stderr) @@ -190,16 +192,27 @@ if not similar_scripts: return None
- msg = '\nThe most similar script{}:'.format( - ' is' if len(similar_scripts) == 1 else 's are') - alternatives = ShowingListOption(similar_scripts, pre=msg, post='') + if len(similar_scripts) == 1: + script = similar_scripts[0] + wait_time = 5 + output(color_format( + 'NOTE: Starting the most similar script ' + '{lightyellow}{}.py{default}\n' + ' in {} seconds; type CTRL-C to stop.', + script, wait_time)) + try: + sleep(wait_time) # Wait a bit to let it be cancelled + except KeyboardInterrupt: + return None + return scripts[script]
+ msg = '\nThe most similar scripts are:' + alternatives = ShowingListOption(similar_scripts, pre=msg, post='') try: prefix, script = input_choice('Which script to be run:', alternatives, default='1') except QuitKeyboardInterrupt: return None - print() return scripts[script[0]]
pywikibot-commits@lists.wikimedia.org