Ricordisamoa has uploaded a new change for review. https://gerrit.wikimedia.org/r/179780
Change subject: small improvements to solve_disambiguation.py ...................................................................... small improvements to solve_disambiguation.py * run also on sites with dn_template not defined * use a list of options with textwrap.fill() for pywikibot.input() * replace `find` with `in`, which is prettier and faster: * http://stackoverflow.com/a/4901653 * http://stackoverflow.com/a/18437853 * use dn_template_str[:-2] instead of dn_template_str[:4] to support floating-length templates Change-Id: Iade765b402498876b8ea6ebbd31649f17c67f9eb --- M scripts/solve_disambiguation.py 1 file changed, 17 insertions(+), 11 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/80/179780/1 diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index 0374f5c..d874483 100644 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -80,6 +80,7 @@ import re import codecs +from textwrap import fill import pywikibot from pywikibot import editor as editarticle @@ -644,8 +645,8 @@ # how many bytes should be displayed around the current link context = 60 # check if there's a {{dn}} here already - already_dn = text[m.end():m.end() + 8].find(dn_template_str[:4]) > -1 - if already_dn and self.dnSkip: + if self.dnSkip and dn_template_str and \ + dn_template_str[:-2] in text[m.end():m.end() + 8]: continue # This loop will run while the user doesn't choose an option @@ -662,16 +663,21 @@ + text[m.start():m.end()] + '\03{default}' + text[m.end():m.end() + context]) + options = ['#', 'r#', '[s]kip link', '[e]dit page', + '[n]ext page', '[u]nlink', '[q]uit'] + if dn_template_str: + options.append(u'[t]ag template %s' % dn_template_str) + options.append('[m]ore context') if edited: - choice = pywikibot.input( -u"Option (#, r#, [s]kip link, [e]dit page, [n]ext page, [u]nlink, [q]uit,\n" -u" [t]ag template " + dn_template_str + ",\n" -u" [m]ore context, [l]ist, [a]dd new, x=save in this form):") + options += ['[l]ist', '[a]dd new', + 'x=save in this form'] else: - choice = pywikibot.input( -u"Option (#, r#, [s]kip link, [e]dit page, [n]ext page, [u]nlink, [q]uit,\n" -u" [t]ag template " + dn_template_str + ",\n" -u" [m]ore context, show [d]isambiguation page, [l]ist, [a]dd new):") + options += ['show [d]isambiguation page', + '[l]ist', '[a]dd new'] + msg = u'Option (' + options = fill(u', '.join(options), width=72, + subsequent_indent=u' ' * len(msg)) + choice = pywikibot.input(u'%s%s):' % (msg, options)) else: choice = self.always if choice in ['a', 'A']: @@ -746,7 +752,7 @@ if trailing_chars: link_text += trailing_chars # '?', '/' for old choice - if choice in ['t', 'T', '?', '/']: + if choice in ['t', 'T', '?', '/'] and dn_template_str: # small chunk of text to search search_text = text[m.end():m.end() + context] # figure out where the link (and sentance) ends, put note -- To view, visit https://gerrit.wikimedia.org/r/179780 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iade765b402498876b8ea6ebbd31649f17c67f9eb Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Ricordisamoa <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
