[PATCH 03/13] Simplify label validation and error reporting
Vratislav Podzimek
vpodzime at redhat.com
Mon Mar 10 13:22:09 UTC 2014
The validate_label function can simply return the error or "" in case of no
error. There's no need for having enums, messages and dicts mapping them.
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
pyanaconda/ui/gui/spokes/custom.py | 6 +++---
.../ui/gui/spokes/lib/custom_storage_helpers.py | 25 +++++-----------------
2 files changed, 8 insertions(+), 23 deletions(-)
diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 44f0c4d..887dc54 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -75,7 +75,7 @@ from pyanaconda.ui.gui.spokes.lib.summary import ActionSummaryDialog
from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import size_from_entry, ui_storage_logger
from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import validate_label, validate_mountpoint, selectedRaidLevel
from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import container_type_names
-from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import label_validation_msgs, mountpoint_validation_msgs, raid_level_not_enough_disks_msg, LABEL_OK # will go away soon
+from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import mountpoint_validation_msgs, raid_level_not_enough_disks_msg
from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import AddDialog, ConfirmDeleteDialog, DisksDialog, ContainerDialog, HelpDialog
from pyanaconda.ui.gui.utils import setViewportBackground, enlightbox, fancy_set_sensitive, ignoreEscape
@@ -688,7 +688,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
if changed_label or changed_fs_type:
error = validate_label(label, new_fs)
if error:
- self._error = _(label_validation_msgs[error])
+ self._error = error
self.set_warning(self._error)
self.window.show_all()
self._populate_right_side(selector)
@@ -1087,7 +1087,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
if not do_reformat:
# Set various attributes that do not require actions.
if old_label != label and hasattr(device.format, "label") and \
- validate_label(label, device.format) == LABEL_OK:
+ validate_label(label, device.format) == "":
self.clear_errors()
log.debug("updating label on %s to %s", device.name, label)
device.format.label = label
diff --git a/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py b/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
index 1608fa9..db8b257 100644
--- a/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
+++ b/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
@@ -47,10 +47,6 @@ from blivet.devicelibs import mdraid
import logging
log = logging.getLogger("anaconda")
-label_format_invalid_msg = N_("Unacceptable label format for filesystem.")
-label_application_unavailable_msg = N_("Can not set label on filesystem.")
-label_resetting_forbidden_msg = N_("Can not relabel already existing filesystem.")
-
empty_mountpoint_msg = N_("Please enter a valid mountpoint.")
invalid_mountpoint_msg = N_("That mount point is invalid. Try something else?")
mountpoint_in_use_msg = N_("That mount point is already in use. Try something else?")
@@ -60,17 +56,6 @@ raid_level_not_enough_disks_msg = N_("The RAID level you have selected (%(level)
"currently have selected (%(count)d).")
empty_name_msg = N_("Please enter a valid name.")
-LABEL_OK = 0
-LABEL_FORMAT_INVALID = 1
-LABEL_APPLICATION_UNAVAILABLE = 2
-LABEL_RESETTING_FORBIDDEN = 3
-
-label_validation_msgs = {
- LABEL_OK: "",
- LABEL_FORMAT_INVALID: label_format_invalid_msg,
- LABEL_APPLICATION_UNAVAILABLE: label_application_unavailable_msg,
- LABEL_RESETTING_FORBIDDEN: label_resetting_forbidden_msg}
-
MOUNTPOINT_OK = 0
MOUNTPOINT_INVALID = 1
MOUNTPOINT_IN_USE = 2
@@ -158,15 +143,15 @@ def validate_label(label, fmt):
"""
if fmt.exists:
- return LABEL_RESETTING_FORBIDDEN
+ return _("Can not relabel already existing filesystem.")
if not fmt.labeling():
if label == "":
- return LABEL_OK
+ return ""
else:
- return LABEL_APPLICATION_UNAVAILABLE
+ return _("Can not set label on filesystem.")
if not fmt.labelFormatOK(label):
- return LABEL_INVALID
- return LABEL_OK
+ return _("Unacceptable label format for filesystem.")
+ return ""
def validate_mountpoint(mountpoint, used_mountpoints, strict=True):
if strict:
--
1.8.5.3
More information about the anaconda-patches
mailing list