[PATCH 07/12] Use constants for password check failure messages

David Shea dshea at redhat.com
Fri Oct 4 18:28:13 UTC 2013


---
 pyanaconda/constants.py              | 11 +++++++++++
 pyanaconda/ui/gui/spokes/password.py | 24 +++++++++++-------------
 pyanaconda/ui/gui/spokes/user.py     | 36 +++++++++++++++---------------------
 pyanaconda/users.py                  |  4 ++--
 4 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/pyanaconda/constants.py b/pyanaconda/constants.py
index 0d1956b..73d2c86 100644
--- a/pyanaconda/constants.py
+++ b/pyanaconda/constants.py
@@ -130,3 +130,14 @@ FIRSTBOOT_ENVIRON = "firstboot"
 
 # Tainted hardware
 UNSUPPORTED_HW = 1 << 28
+
+# Password validation
+PASSWORD_EMPTY_ERROR = _("The password is empty.")
+PASSWORD_CONFIRM_ERROR_GUI = _("The passwords do not match.")
+PASSWORD_CONFIRM_ERROR_TUI = _("The passwords you entered were different.  Please try again.")
+PASSWORD_WEAK = _("The password you have provided is weak. You will have to press Done twice to confirm it.")
+PASSWORD_WEAK_WITH_ERROR = _("The password you have provided is weak: %s. You will have to press Done twice to confirm it.")
+PASSWORD_WEAK_CONFIRM = _("You have provided a weak password. Press Done again to use anyway.")
+PASSWORD_WEAK_CONFIRM_WITH_ERROR = _("You have provided a weak password: %s. Press Done again to use anyway.")
+
+PASSWORD_STRENGTH_DESC = [_("Empty"), _("Weak"), _("Fair"), _("Good"), _("Strong")]
diff --git a/pyanaconda/ui/gui/spokes/password.py b/pyanaconda/ui/gui/spokes/password.py
index dc0782d..022b287 100644
--- a/pyanaconda/ui/gui/spokes/password.py
+++ b/pyanaconda/ui/gui/spokes/password.py
@@ -27,6 +27,10 @@ from pyanaconda.ui.gui.spokes import NormalSpoke
 from pyanaconda.ui.gui.categories.user_settings import UserSettingsCategory
 from pyanaconda.ui.common import FirstbootSpokeMixIn
 
+from pyanaconda.constants import PASSWORD_EMPTY_ERROR, PASSWORD_CONFIRM_ERROR_GUI,\
+        PASSWORD_STRENGTH_DESC, PASSWORD_WEAK, PASSWORD_WEAK_WITH_ERROR,\
+        PASSWORD_WEAK_CONFIRM_WITH_ERROR
+
 __all__ = ["PasswordSpoke"]
 
 
@@ -120,32 +124,27 @@ class PasswordSpoke(FirstbootSpokeMixIn, NormalSpoke):
 
         if strength < 50:
             val = 1
-            text = _("Weak")
-            self._error = _("The password you have provided is weak")
             if _pwq_error:
-                self._error += ": %s. " % _pwq_error
+                self._error = PASSWORD_WEAK_WITH_ERROR % _pwq_error
             else:
-                self._error += ". "
-            self._error += _("You will have to press Done twice to confirm it.")
+                self._error = PASSWORD_WEAK
         elif strength < 75:
             val = 2
-            text = _("Fair")
             self._error = False
         elif strength < 90:
             val = 3
-            text = _("Good")
             self._error = False
         else:
             val = 4
-            text = _("Strong")
             self._error = False
 
         if not self.pw.get_text():
             val = 0
-            text = _("Empty")
-            self._error = _("The password is empty.")
+            self._error = PASSWORD_EMPTY_ERROR
         elif self.confirm.get_text() and self.pw.get_text() != self.confirm.get_text():
-            self._error = _("The passwords do not match.")
+            self._error = PASSWORD_CONFIRM_ERROR_GUI
+
+        text = PASSWORD_STRENGTH_DESC[val]
 
         self.pw_bar.set_value(val)
         self.pw_label.set_text(text)
@@ -180,8 +179,7 @@ class PasswordSpoke(FirstbootSpokeMixIn, NormalSpoke):
                 # We got a second attempt with the same weak password
                 pass
             else:
-                self._error = _("You have provided a weak password: %s. "
-                                " Press Done again to use anyway.") % e[1]
+                self._error = PASSWORD_WEAK_CONFIRM_WITH_ERROR % e[1]
                 self._oldweak = pw
                 return False
 
diff --git a/pyanaconda/ui/gui/spokes/user.py b/pyanaconda/ui/gui/spokes/user.py
index 47e7b6c..47c5588 100644
--- a/pyanaconda/ui/gui/spokes/user.py
+++ b/pyanaconda/ui/gui/spokes/user.py
@@ -29,7 +29,10 @@ from pyanaconda.ui.common import FirstbootSpokeMixIn
 from pyanaconda.ui.gui.utils import enlightbox
 
 from pykickstart.constants import FIRSTBOOT_RECONFIG
-from pyanaconda.constants import ANACONDA_ENVIRON, FIRSTBOOT_ENVIRON
+from pyanaconda.constants import ANACONDA_ENVIRON, FIRSTBOOT_ENVIRON,\
+        PASSWORD_EMPTY_ERROR, PASSWORD_CONFIRM_ERROR_GUI, PASSWORD_STRENGTH_DESC,\
+        PASSWORD_WEAK, PASSWORD_WEAK_WITH_ERROR, PASSWORD_WEAK_CONFIRM,\
+        PASSWORD_WEAK_CONFIRM_WITH_ERROR
 from pyanaconda.regexes import GECOS_VALID, USERNAME_VALID, GROUPNAME_VALID, GROUPLIST_FANCY_PARSE
 
 import pwquality
@@ -416,19 +419,15 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke):
 
         if not pwtext:
             val = 0
-            text = _("Empty")
         elif strength < 50:
             val = 1
-            text = _("Weak")
         elif strength < 75:
             val = 2
-            text = _("Fair")
         elif strength < 90:
             val = 3
-            text = _("Good")
         else:
             val = 4
-            text = _("Strong")
+        text = PASSWORD_STRENGTH_DESC[val]
 
         self.pw_bar.set_value(val)
         self.pw_label.set_text(text)
@@ -483,9 +482,9 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke):
             return GUICheck.CHECK_OK
         elif not editable.get_text():
             if editable == self.pw:
-                return _("The password is empty")
+                return PASSWORD_EMPTY_ERROR
             else:
-                return _("The passwords do not match.")
+                return PASSWORD_CONFIRM_ERROR_GUI
         else:
             return GUICheck.CHECK_OK
 
@@ -500,14 +499,14 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke):
         
         # Skip the check if no password is required
         if (not self.usepassword.get_active()) or self._user.password_kickstarted:
-            result = None
+            result = GUICheck.CHECK_OK
         elif self.confirm.get_text() and (self.pw.get_text() != self.confirm.get_text()):
-            result = _("The passwords do not match.")
+            result = PASSWORD_CONFIRM_ERROR_GUI
         else:
-            result = None
+            result = GUICheck.CHECK_OK
 
         # If the check succeeded, reset the status of the other check object
-        if result is None:
+        if result == GUICheck.CHECK_OK:
             if editable == self.confirm:
                 self._password_check.update_check_status(check_data=True)
             else:
@@ -546,19 +545,14 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke):
                 return GUICheck.CHECK_OK
             elif self._waivePasswordClicks == 1:
                 if self._pwq_error:
-                    return _("You have provided a weak password: %s. "
-                            " Press Done again to use anyway.") % self._pwq_error
+                    return PASSWORD_WEAK_CONFIRM_WITH_ERROR % self._pwq_error
                 else:
-                    return _("You have provided a weak password. "
-                            " Press Done again to use anyway.")
+                    return PASSWORD_WEAK_CONFIRM
             else:
-                error = _("The password you have provided is weak")
                 if self._pwq_error:
-                    error += ": %s. " % self._pwq_error
+                    return PASSWORD_WEAK_WITH_ERROR % self._pwq_error
                 else:
-                    error += ". "
-                error += _("You will have to press Done twice to confirm it.")
-                return error
+                    return PASSWORD_WEAK
         else:
             return GUICheck.CHECK_OK
 
diff --git a/pyanaconda/users.py b/pyanaconda/users.py
index 67baf72..0121bc1 100644
--- a/pyanaconda/users.py
+++ b/pyanaconda/users.py
@@ -30,6 +30,7 @@ from pyanaconda import iutil
 import pwquality
 from pyanaconda.iutil import strip_accents
 from pyanaconda.i18n import _
+from pyanaconda.constants import PASSWORD_CONFIRM_ERROR_TUI
 
 import logging
 log = logging.getLogger("anaconda")
@@ -125,8 +126,7 @@ def validatePassword(pw, confirm=None, minlen=6, user="root"):
         return error
 
     if confirm != None and pw != confirm:
-        error = _("The passwords you entered were "
-                  "different.  Please try again.")
+        error = PASSWORD_CONFIRM_ERROR_TUI
         return error
 
     legal = string.digits + string.ascii_letters + string.punctuation + " "
-- 
1.8.3.1



More information about the anaconda-patches mailing list