[master 27/30] Removed fslabel, now split into reading and writing.

mulkieran installerbot-noreply at redhat.com
Wed Mar 25 22:48:05 UTC 2015


From: mulhern <amulhern at redhat.com>

Removed functionality now split out into other classes out of fslabeling
classes.

Cleaned up FS so that it uses reading and writing where appropriate and
_labelfs almost not at all.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/formats/fs.py              |   2 +-
 blivet/tasks/fslabel.py           | 205 --------------------------------------
 blivet/tasks/fslabeling.py        |  48 ---------
 tests/tasks_test/labeling_test.py |   6 +-
 4 files changed, 4 insertions(+), 257 deletions(-)
 delete mode 100644 blivet/tasks/fslabel.py

diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 2ac8885..c5d39e9 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -165,7 +165,7 @@ def labeling(self):
 
            :rtype: bool
         """
-        return self._labelfs is not None
+        return (self._mkfs is not None and self._mkfs.labels) or self._writelabel is not None
 
     def relabels(self):
         """Returns True if it is possible to relabel this filesystem
diff --git a/blivet/tasks/fslabel.py b/blivet/tasks/fslabel.py
deleted file mode 100644
index 81c18e6..0000000
--- a/blivet/tasks/fslabel.py
+++ /dev/null
@@ -1,205 +0,0 @@
-# fslabel.py
-# Filesystem labeling classes for anaconda's storage configuration module.
-#
-# Copyright (C) 2013  Red Hat, Inc.
-#
-# This copyrighted material is made available to anyone wishing to use,
-# modify, copy, or redistribute it subject to the terms and conditions of
-# the GNU General Public License v.2, or (at your option) any later version.
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY expressed or implied, including the implied warranties of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
-# Public License for more details.  You should have received a copy of the
-# GNU General Public License along with this program; if not, write to the
-# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
-# source code or documentation are not subject to the GNU General Public
-# License and may only be used or replicated with the express permission of
-# Red Hat, Inc.
-#
-# Red Hat Author(s): Anne Mulhern <amulhern at redhat.com>
-
-import abc
-import re
-
-from six import add_metaclass
-
-from .. import errors
-
- at add_metaclass(abc.ABCMeta)
-class FSLabelApp(object):
-    """An abstract class that represents actions associated with a
-       filesystem's labeling application.
-    """
-
-    name = abc.abstractproperty(
-       doc="The name of the filesystem labeling application.")
-
-    reads = abc.abstractproperty(
-        doc="Whether this application can read a label as well as write one.")
-
-    _label_regex = abc.abstractproperty(
-        doc="Matches the string output by the label reading application.")
-
-    @abc.abstractmethod
-    def _writeLabelArgs(self, fs):
-        """Returns a list of the arguments for writing a label.
-
-           :param FS fs: a filesystem object
-
-           :return: the arguments
-           :rtype: list of str
-
-           It can be assumed in this function that fs.label is a str.
-        """
-        raise NotImplementedError
-
-    def setLabelCommand(self, fs):
-        """Get the command to label the filesystem.
-
-           :param FS fs: a filesystem object
-           :return: the command
-           :rtype: list of str
-
-           Raises an exception if fs.label is None.
-        """
-        if fs.label is None:
-            raise errors.FSError("makes no sense to write a label when accepting default label")
-        return [self.name] + self._writeLabelArgs(fs)
-
-    @abc.abstractmethod
-    def _readLabelArgs(self, fs):
-        """Returns a list of arguments for reading a label.
-
-           :param FS fs: a filesystem object
-           :return: the arguments
-           :rtype: list of str
-        """
-        raise NotImplementedError
-
-    def readLabelCommand(self, fs):
-        """Get the command to read the filesystem label.
-
-           :param FS fs: a filesystem object
-           :return: the command
-           :rtype: list of str
-
-           Raises an FSError if this application can not read the label.
-        """
-        if not self.reads:
-            raise errors.FSError("Application %s can not read the filesystem label." % self.name)
-        return [self.name] + self._readLabelArgs(fs)
-
-    def extractLabel(self, labelstr):
-        """Extract the label from an output string.
-
-           :param str labelstr: the string containing the label information
-
-           :return: the label
-           :rtype: str
-
-           Raises an FSError if the label can not be extracted.
-        """
-        if not self.reads or self._label_regex is None:
-            raise errors.FSError("Unknown format for application %s" % self.name)
-        match = re.match(self._label_regex, labelstr)
-        if match is None:
-            raise errors.FSError("Unknown format for application %s" % self.name)
-        return match.group('label')
-
-
-class E2Label(FSLabelApp):
-    """Application used by ext2 and its descendants."""
-
-    name = "e2label"
-    reads = True
-
-    _label_regex = r'(?P<label>.*)'
-
-    def _writeLabelArgs(self, fs):
-        return [fs.device, fs.label]
-
-    def _readLabelArgs(self, fs):
-        return [fs.device]
-
-E2Label = E2Label()
-
-class DosFsLabel(FSLabelApp):
-    """Application used by FATFS."""
-
-    name = "dosfslabel"
-    reads = True
-
-    _label_regex = r'(?P<label>.*)'
-
-    def _writeLabelArgs(self, fs):
-        return [fs.device, fs.label]
-
-    def _readLabelArgs(self, fs):
-        return [fs.device]
-
-DosFsLabel = DosFsLabel()
-
-class JFSTune(FSLabelApp):
-    """Application used by JFS."""
-
-    name = "jfs_tune"
-    reads = False
-
-    _label_regex = property(lambda s: None)
-
-    def _writeLabelArgs(self, fs):
-        return ["-L", fs.label, fs.device]
-
-    def _readLabelArgs(self, fs):
-        raise NotImplementedError
-
-JFSTune = JFSTune()
-
-class ReiserFSTune(FSLabelApp):
-    """Application used by ReiserFS."""
-
-    name = "reiserfstune"
-    reads = False
-
-    _label_regex = None
-
-    def _writeLabelArgs(self, fs):
-        return ["-l", fs.label, fs.device]
-
-    def _readLabelArgs(self, fs):
-        raise NotImplementedError
-
-ReiserFSTune = ReiserFSTune()
-
-class XFSAdmin(FSLabelApp):
-    """Application used by XFS."""
-
-    name = "xfs_admin"
-    reads = True
-
-    _label_regex = r'label = "(?P<label>.*)"'
-
-    def _writeLabelArgs(self, fs):
-        return ["-L", fs.label if fs.label != "" else "--", fs.device]
-
-    def _readLabelArgs(self, fs):
-        return ["-l", fs.device]
-
-XFSAdmin = XFSAdmin()
-
-class NTFSLabel(FSLabelApp):
-    """Application used by NTFS."""
-
-    name = "ntfslabel"
-    reads = True
-
-    _label_regex = r'(?P<label>.*)'
-
-    def _writeLabelArgs(self, fs):
-        return [fs.device, fs.label]
-
-    def _readLabelArgs(self, fs):
-        return [fs.device]
-
-NTFSLabel = NTFSLabel()
diff --git a/blivet/tasks/fslabeling.py b/blivet/tasks/fslabeling.py
index 0abeaf7..3d2faa3 100644
--- a/blivet/tasks/fslabeling.py
+++ b/blivet/tasks/fslabeling.py
@@ -23,8 +23,6 @@
 
 from six import add_metaclass
 
-from . import fslabel
-
 @add_metaclass(abc.ABCMeta)
 class FSLabeling(object):
     """An abstract class that represents filesystem labeling actions.
@@ -33,9 +31,6 @@ class FSLabeling(object):
     default_label = abc.abstractproperty(
        doc="Default label set on this filesystem at creation.")
 
-    label_app = abc.abstractproperty(
-       doc="Post creation filesystem labeling application.")
-
     @abc.abstractmethod
     def labelFormatOK(self, label):
         """Returns True if this label is correctly formatted for this
@@ -46,74 +41,41 @@ def labelFormatOK(self, label):
         """
         raise NotImplementedError
 
-    @abc.abstractmethod
-    def labelingArgs(self, label):
-        """Returns the arguments for writing the label during filesystem
-           creation. These arguments are intended to be passed to the
-           appropriate mkfs application.
-
-           :param str label: the label to use
-           :return: the arguments
-           :rtype: list of str
-        """
-        raise NotImplementedError
-
-
 class Ext2FSLabeling(FSLabeling):
 
     default_label = ""
-    label_app = fslabel.E2Label
 
     def labelFormatOK(self, label):
         return len(label) < 17
 
-    def labelingArgs(self, label):
-        return ["-L", label]
-
 class FATFSLabeling(FSLabeling):
 
     default_label = "NO NAME"
-    label_app = fslabel.DosFsLabel
 
     def labelFormatOK(self, label):
         return len(label) < 12
 
-    def labelingArgs(self, label):
-        return ["-n", label]
-
 class JFSLabeling(FSLabeling):
 
     default_label = ""
-    label_app = fslabel.JFSTune
 
     def labelFormatOK(self, label):
         return len(label) < 17
 
-    def labelingArgs(self, label):
-        return ["-L", label]
-
 class ReiserFSLabeling(FSLabeling):
 
     default_label = ""
-    label_app = fslabel.ReiserFSTune
 
     def labelFormatOK(self, label):
         return len(label) < 17
 
-    def labelingArgs(self, label):
-        return ["-l", label]
-
 class XFSLabeling(FSLabeling):
 
     default_label = ""
-    label_app = fslabel.XFSAdmin
 
     def labelFormatOK(self, label):
         return ' ' not in label and len(label) < 13
 
-    def labelingArgs(self, label):
-        return ["-L", label]
-
 class HFSLabeling(FSLabeling):
 
     default_label = "Untitled"
@@ -122,9 +84,6 @@ class HFSLabeling(FSLabeling):
     def labelFormatOK(self, label):
         return ':' not in label and len(label) < 28 and len(label) > 0
 
-    def labelingArgs(self, label):
-        return ["-l", label]
-
 class HFSPlusLabeling(FSLabeling):
 
     default_label = "Untitled"
@@ -133,16 +92,9 @@ class HFSPlusLabeling(FSLabeling):
     def labelFormatOK(self, label):
         return ':' not in label and 0 < len(label) < 129
 
-    def labelingArgs(self, label):
-        return ["-v", label]
-
 class NTFSLabeling(FSLabeling):
 
     default_label = ""
-    label_app = fslabel.NTFSLabel
 
     def labelFormatOK(self, label):
         return len(label) < 129
-
-    def labelingArgs(self, label):
-        return ["-L", label]
diff --git a/tests/tasks_test/labeling_test.py b/tests/tasks_test/labeling_test.py
index c1945d3..f3d489f 100755
--- a/tests/tasks_test/labeling_test.py
+++ b/tests/tasks_test/labeling_test.py
@@ -71,18 +71,18 @@ def testGetLabelArgs(self):
 
         # ReiserFS uses a -l flag
         reiserfs = self.fs["reiserfs"]
-        self.assertEqual(reiserfs._labelfs.label_app.setLabelCommand(reiserfs),
+        self.assertEqual(reiserfs._writelabel._setCommand(),
            ["reiserfstune", "-l", "myfs", "/dev"], msg="reiserfs")
 
         # JFS, XFS use a -L flag
         lflag_classes = [fs.JFS, fs.XFS]
         for name, klass in [(k, v) for k, v in self.fs.items() if any(isinstance(v, c) for c in lflag_classes)]:
-            self.assertEqual(klass._labelfs.label_app.setLabelCommand(v), [klass._labelfs.label_app.name, "-L", "myfs", "/dev"], msg=name)
+            self.assertEqual(klass._writelabel._setCommand(), [klass._writelabel.app_name, "-L", "myfs", "/dev"], msg=name)
 
         # Ext2FS and descendants and FATFS do not use a flag
         noflag_classes = [fs.Ext2FS, fs.FATFS]
         for name, klass in [(k, v) for k, v in self.fs.items() if any(isinstance(v, c) for c in noflag_classes)]:
-            self.assertEqual(klass._labelfs.label_app.setLabelCommand(klass), [klass._labelfs.label_app.name, "/dev", "myfs"], msg=name)
+            self.assertEqual(klass._writelabel._setCommand(), [klass._writelabel.app_name, "/dev", "myfs"], msg=name)
 
         # all of the remaining are non-labeling so will accept any label
         label = "Houston, we have a problem!"


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/e5c5876a3fe2203d72818bd4d5f369f3b4d76454


More information about the anaconda-patches mailing list