[blivet:master 5/5] Change labelApp to a more concisely defined abstract property

mulhern amulhern at redhat.com
Tue Apr 1 17:26:13 UTC 2014


Change its name to label_app to be more consistent w/ property names.

Make fslabel classes into singleton objects.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/formats/fs.py                | 18 +++++++-------
 blivet/formats/fslabel.py           | 12 ++++++++++
 blivet/formats/fslabeling.py        | 48 +++++++------------------------------
 tests/formats_test/labeling_test.py |  6 ++---
 4 files changed, 33 insertions(+), 51 deletions(-)

diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 8c1163e..5cab436 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -161,7 +161,7 @@ class FS(DeviceFormat):
 
            :rtype: bool
         """
-        return cls._labelfs is not None and cls._labelfs.labelApp is not None
+        return cls._labelfs is not None and cls._labelfs.label_app is not None
 
     @classmethod
     def labelFormatOK(cls, label):
@@ -638,10 +638,10 @@ class FS(DeviceFormat):
         if not os.path.exists(self.device):
             raise FSError("device does not exist")
 
-        if not self._labelfs or not self._labelfs.labelApp or not self._labelfs.labelApp.reads:
+        if not self._labelfs or not self._labelfs.label_app or not self._labelfs.label_app.reads:
             raise FSError("no application to read label for filesystem %s" % self.type)
 
-        (rc, out) = util.run_program_and_capture_output(self._labelfs.labelApp.readLabelCommand(self))
+        (rc, out) = util.run_program_and_capture_output(self._labelfs.label_app.readLabelCommand(self))
         if rc:
             raise FSError("read label failed")
 
@@ -650,7 +650,7 @@ class FS(DeviceFormat):
         if label == "":
             return ""
         else:
-            return self._labelfs.labelApp.extractLabel(label)
+            return self._labelfs.label_app.extractLabel(label)
 
     def writeLabel(self):
         """ Create a label for this filesystem.
@@ -669,16 +669,16 @@ class FS(DeviceFormat):
         if not self.exists:
             raise FSError("filesystem has not been created")
 
-        if not self._labelfs or not self._labelfs.labelApp:
+        if not self._labelfs or not self._labelfs.label_app:
             raise FSError("no application to set label for filesystem %s" % self.type)
 
         if not self.labelFormatOK(self.label):
-            raise FSError("bad label format for labelling application %s" % self._labelfs.labelApp.name)
+            raise FSError("bad label format for labelling application %s" % self._labelfs.label_app.name)
 
         if not os.path.exists(self.device):
             raise FSError("device does not exist")
 
-        rc = util.run_program(self._labelfs.labelApp.setLabelCommand(self))
+        rc = util.run_program(self._labelfs.label_app.setLabelCommand(self))
         if rc:
             raise FSError("label failed")
 
@@ -716,8 +716,8 @@ class FS(DeviceFormat):
 
             May be None if no such program exists.
         """
-        if self._labelfs and self._labelfs.labelApp:
-            return self._labelfs.labelApp.name
+        if self._labelfs and self._labelfs.label_app:
+            return self._labelfs.label_app.name
         else:
             return None
 
diff --git a/blivet/formats/fslabel.py b/blivet/formats/fslabel.py
index 685dec5..358ba82 100644
--- a/blivet/formats/fslabel.py
+++ b/blivet/formats/fslabel.py
@@ -120,6 +120,8 @@ class E2Label(FSLabelApp):
     def _readLabelArgs(self, fs):
         return [fs.device]
 
+E2Label = E2Label()
+
 class DosFsLabel(FSLabelApp):
     """Application used by FATFS."""
 
@@ -134,6 +136,8 @@ class DosFsLabel(FSLabelApp):
     def _readLabelArgs(self, fs):
         return [fs.device]
 
+DosFsLabel = DosFsLabel()
+
 class JFSTune(FSLabelApp):
     """Application used by JFS."""
 
@@ -148,6 +152,8 @@ class JFSTune(FSLabelApp):
     def _readLabelArgs(self, fs):
         raise NotImplementedError
 
+JFSTune = JFSTune()
+
 class ReiserFSTune(FSLabelApp):
     """Application used by ReiserFS."""
 
@@ -162,6 +168,8 @@ class ReiserFSTune(FSLabelApp):
     def _readLabelArgs(self, fs):
         raise NotImplementedError
 
+ReiserFSTune = ReiserFSTune()
+
 class XFSAdmin(FSLabelApp):
     """Application used by XFS."""
 
@@ -176,6 +184,8 @@ class XFSAdmin(FSLabelApp):
     def _readLabelArgs(self, fs):
         return ["-l", fs.device]
 
+XFSAdmin = XFSAdmin()
+
 class NTFSLabel(FSLabelApp):
     """Application used by NTFS."""
 
@@ -189,3 +199,5 @@ class NTFSLabel(FSLabelApp):
 
     def _readLabelArgs(self, fs):
         return [fs.device]
+
+NTFSLabel = NTFSLabel()
diff --git a/blivet/formats/fslabeling.py b/blivet/formats/fslabeling.py
index d5a7b09..e1fd016 100644
--- a/blivet/formats/fslabeling.py
+++ b/blivet/formats/fslabeling.py
@@ -32,16 +32,8 @@ class FSLabeling(object):
     default_label = abc.abstractproperty(lambda s: None,
        doc="Default label set on this filesystem at creation.")
 
-    @abc.abstractproperty
-    def labelApp(self):
-        """Application that may be used to label filesystem after the
-           filesystem has been created.
-
-           :rtype: object or None
-           :return: the object representing the labeling application or None
-           if no such object exists
-        """
-        raise NotImplementedError
+    label_app = abc.abstractproperty(lambda s: None,
+       doc="Post creation filesystem labeling application.")
 
     @abc.abstractmethod
     def labelFormatOK(self, label):
@@ -68,10 +60,7 @@ class FSLabeling(object):
 class Ext2FSLabeling(FSLabeling):
 
     default_label = property(lambda s: "")
-
-    @property
-    def labelApp(self):
-        return fslabel.E2Label()
+    label_app = property(lambda s: fslabel.E2Label)
 
     def labelFormatOK(self, label):
         return len(label) < 17
@@ -82,10 +71,7 @@ class Ext2FSLabeling(FSLabeling):
 class FATFSLabeling(FSLabeling):
 
     default_label = property(lambda s: "NO NAME")
-
-    @property
-    def labelApp(self):
-        return fslabel.DosFsLabel()
+    label_app = property(lambda s: fslabel.DosFsLabel)
 
     def labelFormatOK(self, label):
         return len(label) < 12
@@ -93,14 +79,10 @@ class FATFSLabeling(FSLabeling):
     def labelingArgs(self, label):
         return ["-n", label]
 
-
 class JFSLabeling(FSLabeling):
 
     default_label = property(lambda s: "")
-
-    @property
-    def labelApp(self):
-        return fslabel.JFSTune()
+    label_app = property(lambda s: fslabel.JFSTune)
 
     def labelFormatOK(self, label):
         return len(label) < 17
@@ -111,10 +93,7 @@ class JFSLabeling(FSLabeling):
 class ReiserFSLabeling(FSLabeling):
 
     default_label = property(lambda s: "")
-
-    @property
-    def labelApp(self):
-        return fslabel.ReiserFSTune()
+    label_app = property(lambda s: fslabel.ReiserFSTune)
 
     def labelFormatOK(self, label):
         return len(label) < 17
@@ -125,10 +104,7 @@ class ReiserFSLabeling(FSLabeling):
 class XFSLabeling(FSLabeling):
 
     default_label = property(lambda s: "")
-
-    @property
-    def labelApp(self):
-        return fslabel.XFSAdmin()
+    label_app = property(lambda s: fslabel.XFSAdmin)
 
     def labelFormatOK(self, label):
         return ' ' not in label and len(label) < 13
@@ -139,10 +115,7 @@ class XFSLabeling(FSLabeling):
 class HFSLabeling(FSLabeling):
 
     default_label = property(lambda s: "Untitled")
-
-    @property
-    def labelApp(self):
-        return None
+    label_app = property(lambda s: None)
 
     def labelFormatOK(self, label):
         return ':' not in label and len(label) < 28 and len(label) > 0
@@ -153,10 +126,7 @@ class HFSLabeling(FSLabeling):
 class NTFSLabeling(FSLabeling):
 
     default_label = property(lambda s: "")
-
-    @property
-    def labelApp(self):
-        return fslabel.NTFSLabel()
+    label_app = property(lambda s: fslabel.NTFSLabel)
 
     def labelFormatOK(self, label):
         return len(label) < 129
diff --git a/tests/formats_test/labeling_test.py b/tests/formats_test/labeling_test.py
index a560c39..d72c431 100755
--- a/tests/formats_test/labeling_test.py
+++ b/tests/formats_test/labeling_test.py
@@ -66,18 +66,18 @@ class MethodsTestCase(unittest.TestCase):
 
         # ReiserFS uses a -l flag
         reiserfs = self.fs["reiserfs"]
-        self.assertEqual(reiserfs._labelfs.labelApp.setLabelCommand(reiserfs),
+        self.assertEqual(reiserfs._labelfs.label_app.setLabelCommand(reiserfs),
            ["reiserfstune", "-l", "myfs", "/dev"], msg="reiserfs")
 
         # JFS, XFS use a -L flag
         lflag_classes = [fs.JFS, fs.XFS]
         for k, v in [(k, v) for k, v in self.fs.items() if any(isinstance(v, c) for c in lflag_classes)]:
-            self.assertEqual(v._labelfs.labelApp.setLabelCommand(v), [v._labelfs.labelApp.name, "-L", "myfs", "/dev"], msg=k)
+            self.assertEqual(v._labelfs.label_app.setLabelCommand(v), [v._labelfs.label_app.name, "-L", "myfs", "/dev"], msg=k)
 
         # Ext2FS and descendants and FATFS do not use a flag
         noflag_classes = [fs.Ext2FS, fs.FATFS]
         for k, v in [(k, v) for k, v in self.fs.items() if any(isinstance(v, c) for c in noflag_classes)]:
-            self.assertEqual(v._labelfs.labelApp.setLabelCommand(v), [v._labelfs.labelApp.name, "/dev", "myfs"], msg=k)
+            self.assertEqual(v._labelfs.label_app.setLabelCommand(v), [v._labelfs.label_app.name, "/dev", "myfs"], msg=k)
 
         # all of the remaining are non-labeling so will accept any label
         label = "Houston, we have a problem!"
-- 
1.8.3.1



More information about the anaconda-patches mailing list