jenkins-bot merged this change.
[IMPR] Make similar script search configurable
Change-Id: I92d79c82ac7fc4f5983be35d6993eb0186bc0c81
---
M pwb.py
M pywikibot/config2.py
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/pwb.py b/pwb.py
index d21d2d4..cd0324a 100755
--- a/pwb.py
+++ b/pwb.py
@@ -171,10 +171,15 @@
def find_alternates(filename, script_paths):
"""Search for similar filenames in the given script paths."""
- from pywikibot import input_choice, output
+ from pywikibot import config, input_choice, output
from pywikibot.bot import ShowingListOption, QuitKeyboardInterrupt
from pywikibot.tools.formatter import color_format
+ assert config.pwb_close_matches > 0, \
+ 'config.pwb_close_matches must be greater than 0'
+ assert 0.0 < config.pwb_cut_off < 1.0, \
+ 'config.pwb_cut_off must be a float in range [0, 1]'
+
print('ERROR: {} not found! Misspelling?'.format(filename),
file=sys.stderr)
@@ -188,13 +193,15 @@
scripts[name] = os.path.join(*(path + [script_name]))
filename = filename[:-3]
- similar_scripts = get_close_matches(filename, scripts, n=10, cutoff=0.7)
+ similar_scripts = get_close_matches(filename, scripts,
+ config.pwb_close_matches,
+ config.pwb_cut_off)
if not similar_scripts:
return None
if len(similar_scripts) == 1:
script = similar_scripts[0]
- wait_time = 5
+ wait_time = config.pwb_autostart_waittime
output(color_format(
'NOTE: Starting the most similar script '
'{lightyellow}{}.py{default}\n'
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index e155e60..1540dfe 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -482,6 +482,19 @@
# Currently only works if interface 'terminal' is set.
transliterate = True
+# The pwb.py wrapper calls the script given as parameter in this way
+# python pwb.py <name_of_script> <options>
+# If there is a misspelling in <name_of_script> the most similar script
+# scripts are displayed or if only one is found, it will be started.
+# There are some configuration values to change the behavior
+#
+# pwb_close_matches: the maximum number of simular scripts to be found
+pwb_close_matches = 10 # must be greater than 0
+# pwb_cut_off: similarity of scripts to be found
+pwb_cut_off = 0.7 # must be a float in the range [0, 1]
+# pwb_autostart_waittime: wait time until the most similar script starts
+pwb_autostart_waittime = 5.0
+
# Should the system bell ring if the bot expects user input?
ring_bell = False
To view, visit change 510165. To unsubscribe, or for help writing mail filters, visit settings.