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

Change subject: [bugfix] Enable choosing protect level with 
check_protection_level
......................................................................

[bugfix] Enable choosing protect level with check_protection_level

levels option passed to check_protection_level is a set
which cannot be indexed. Convert that set to a list first.

Also return if level is found in levels.
Dedent the other part.

Bug: T225448
Change-Id: I9c80f8663a86f5d6c80f7ac72db2268543564f88
---
M scripts/protect.py
1 file changed, 24 insertions(+), 21 deletions(-)

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



diff --git a/scripts/protect.py b/scripts/protect.py
index b2fd560..af8d779 100755
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -123,29 +123,32 @@
     @return: a valid protection level
     @rtype: str
     """
-    if level not in levels:
-        first_char = []
-        default_char = None
-        num = 1
-        for level in levels:
-            for c in level:
-                if c not in first_char:
-                    first_char.append(c)
-                    break
-            else:
-                first_char.append(str(num))
-                num += 1
-            if level == default:
-                default_char = first_char[-1]
-        choice = pywikibot.input_choice('Choice a protection level to {0}:'
-                                        .format(operation),
-                                        zip(levels, first_char),
-                                        default=default_char)
-
-        return levels[first_char.index(choice)]
-    else:
+    if level in levels:
         return level

+    # ask for a valid level
+    levels = sorted(levels)  # sort to be deterministic
+    first_char = []
+    default_char = None
+    num = 1
+    for level in levels:
+        for c in level:
+            if c not in first_char:
+                first_char.append(c)
+                break
+        else:
+            first_char.append(str(num))
+            num += 1
+        if level == default:
+            default_char = first_char[-1]
+
+    choice = pywikibot.input_choice('Choose a protection level to {0}:'
+                                    .format(operation),
+                                    zip(levels, first_char),
+                                    default=default_char)
+
+    return levels[first_char.index(choice)]
+

 def main(*args):
     """

--
To view, visit https://gerrit.wikimedia.org/r/516309
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: I9c80f8663a86f5d6c80f7ac72db2268543564f88
Gerrit-Change-Number: 516309
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Lokal Profil <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to