jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
pwb.py: Add ability to display similar scripts when misspelled

Implemented the difflib.get_close_matches function to find the
similar scripts. The 'cutoff' and 'n' parameters are set as 0.7
and 10 respectively based on observations.

Bug: T217195
Change-Id: I23d5aa14b358ae9b13221f24f38f6091ad8698ed
---
M CREDITS
M pwb.py
2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/CREDITS b/CREDITS
index fb66ea8..6df9eab 100644
--- a/CREDITS
+++ b/CREDITS
@@ -116,6 +116,7 @@
murfel
MuhammadShuaib
Nicolas Dumazet
+Nikhil Prakash
Nikiwiki
notconfusing
Nullzero
diff --git a/pwb.py b/pwb.py
index 601fa44..1316bda 100755
--- a/pwb.py
+++ b/pwb.py
@@ -16,6 +16,7 @@
from __future__ import (absolute_import, division,
print_function, unicode_literals)

+from difflib import get_close_matches
from importlib import import_module
import os
import sys
@@ -195,6 +196,23 @@
else:
print('ERROR: {} not found! Misspelling?'.format(filename),
file=sys.stderr)
+
+ scripts = []
+ for file_package in script_paths:
+ path = file_package.split('.')
+ for script_name in os.listdir(os.path.join(*path)):
+ if script_name.endswith('.py'):
+ scripts.append(script_name)
+
+ similar_scripts = get_close_matches(filename, scripts,
+ n=10, cutoff=0.7)
+
+ if similar_scripts:
+ print(
+ '\nThe most similar {}:'
+ .format('script is' if len(similar_scripts) == 1
+ else 'scripts are'))
+ print('\t' + '\n\t'.join(similar_scripts))
return True

# When both pwb.py and the filename to run are within the current

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I23d5aa14b358ae9b13221f24f38f6091ad8698ed
Gerrit-Change-Number: 495457
Gerrit-PatchSet: 18
Gerrit-Owner: Nikhil <nikhil07prakash@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Nikhil <nikhil07prakash@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Welcome, new contributor! <ssethi@wikimedia.org>