[blivet:rhel7/master 10/10] Move label setter and getter into DeviceFormat class (#1038590)

mulhern amulhern at redhat.com
Thu Jan 9 18:55:00 UTC 2014


Related: rhbz#1038590

DeviceFormat does not have a label but SwapSpace as well as FS does, and
it is better to put the same restrictions on the label for both.
Note that the restriction has been reduced to converting "" to None.
The comments on the setter explain why it is not possible to be more
restrictive.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/formats/__init__.py | 38 ++++++++++++++++++++++++++++++++++++++
 blivet/formats/fs.py       | 45 ++-------------------------------------------
 blivet/formats/swap.py     |  3 +++
 3 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index 2d7966d..23a824e 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -236,6 +236,44 @@ class DeviceFormat(object):
         """
         return cls.labeling()
 
+    def _setLabel(self, label):
+        """Sets the label for this format.
+
+           :param label: the label for this format
+           :type label: str or None
+
+           Note that some filesystems do not possess a label, so this method
+           always accept the value None for label as well as the empty string
+           which is considered to mean None.
+
+           Note also that some filesystems, even though they do not have a
+           labeling application may be already labeled, so we allow to set
+           the label of a filesystem even if a labeling application does not
+           exist. This can happen with the install media, for example, where
+           the filesystem on the CD has a label, but there is no labeling
+           application for the Iso9660FS format.
+
+           If a labeling application does exist, the label is not
+           required to have the correct format for that application.
+           The allowable format for the label may be more permissive than
+           the format allowed by the labeling application.
+
+           This method is not intended to be overridden.
+        """
+        if not label: 
+            self._label = None
+        else:
+            self._label = label
+
+    def _getLabel(self):
+        """The label for this filesystem.
+
+           :return: the label for this filesystsm
+           :rtype: str
+
+           This method is not intended to be overridden.
+        """
+        return self._label
     def _setOptions(self, options):
         self._options = options
 
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index bb78786..f62d904 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -164,49 +164,8 @@ class FS(DeviceFormat):
     def labelFormatOK(cls, label):
         return cls._labelfs is not None and cls._labelfs.labelFormatOK(label)
 
-    def _setLabel(self, label):
-        """Sets the label for this filesystem.
-
-           :param label: the label for this filesystem
-           :type label: str or None
-
-           Raises an FSError if the label is "".
-
-           Note that some filesystems do not possess a label, so this method
-           always accept the value None for label.
-
-           Note also that some filesystems, even though they do not have a
-           labeling application may be already labeled, so we allow to set
-           the label of a filesystem even if a labeling application does not
-           exist. This can happen with the install media, for example, where
-           the filesystem on the CD has a label, but there is no labeling
-           application for the Iso9660FS format.
-
-           If a labeling application does exist, the label is not
-           required to have the correct format for that application.
-           The allowable format for the label may be more permissive than
-           the format allowed by the labeling application.
-
-           This method is not intended to be overridden.
-        """
-        if label is None:
-            self._label = None
-        elif label == "":
-            raise FSError("Empty filesystem label not permitted.")
-        else:
-            self._label = label
-
-    def _getLabel(self):
-        """The label for this filesystem.
-
-           :return: the label for this filesystsm
-           :rtype: str
-
-           This method is not intended to be overridden.
-        """
-        return self._label
-
-    label = property(_getLabel, _setLabel, doc="this filesystem's label")
+    label = property(lambda s: s._getLabel(), lambda s,l: s._setLabel(l),
+       doc="this filesystem's label")
 
     def _setTargetSize(self, newsize):
         """ Set a target size for this filesystem. """
diff --git a/blivet/formats/swap.py b/blivet/formats/swap.py
index d7c948e..29b608a 100644
--- a/blivet/formats/swap.py
+++ b/blivet/formats/swap.py
@@ -88,6 +88,9 @@ class SwapSpace(DeviceFormat):
         """Returns True since no known restrictions on the label."""
         return True
 
+    label = property(lambda s: s._getLabel(), lambda s,l: s._setLabel(l),
+       doc="this filesystem's label")
+
     def _setPriority(self, priority):
         if priority is None:
             self._priority = None
-- 
1.8.3.1



More information about the anaconda-patches mailing list