jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/495457 )

Change subject: pwb.py: Add ability to display similar scripts when misspelled
......................................................................

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(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



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 https://gerrit.wikimedia.org/r/495457
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/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 <[email protected]>
Gerrit-Reviewer: Dvorapa <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Nikhil <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Welcome, new contributor! <[email protected]>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to