[master 2/22] Make labeling(), relabels(), and labelFormatOK() instance methods.

mulkieran installerbot-noreply at redhat.com
Tue May 5 16:35:26 UTC 2015


From: mulhern <amulhern at redhat.com>

Related: #12

After a few more patches they will be required to access instance variables.

Does not affect downstream, which always uses instance when invoking,
anyway.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/formats/__init__.py          |  8 +++----
 blivet/formats/fs.py                | 15 +++++-------
 blivet/formats/swap.py              |  6 ++---
 tests/formats_test/labeling_test.py | 46 ++++++++++++++++++-------------------
 4 files changed, 34 insertions(+), 41 deletions(-)

diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index d68f8ba..2acca22 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -221,13 +221,11 @@ def dict(self):
              "resizable": self.resizable}
         return d
 
-    @classmethod
-    def labeling(cls):
+    def labeling(self):
         """Returns False by default since most formats are non-labeling."""
         return False
 
-    @classmethod
-    def labelFormatOK(cls, label):
+    def labelFormatOK(self, label):
         """Checks whether the format of the label is OK for whatever
            application is used by blivet to write a label for this format.
            If there is no application that blivet uses to write a label,
@@ -239,7 +237,7 @@ def labelFormatOK(cls, label):
            :return: True if the format of the label is OK, otherwise False
         """
         # pylint: disable=unused-argument
-        return cls.labeling()
+        return self.labeling()
 
     def _setLabel(self, label):
         """Sets the label for this format.
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index dd282eb..a8b9558 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -151,25 +151,22 @@ def dict(self):
                   "mountable": self.mountable})
         return d
 
-    @classmethod
-    def labeling(cls):
+    def labeling(self):
         """Returns True if this filesystem uses labels, otherwise False.
 
            :rtype: bool
         """
-        return cls._labelfs is not None
+        return self._labelfs is not None
 
-    @classmethod
-    def relabels(cls):
+    def relabels(self):
         """Returns True if it is possible to relabel this filesystem
            after creation, otherwise False.
 
            :rtype: bool
         """
-        return cls._labelfs is not None and cls._labelfs.label_app is not None
+        return self._labelfs is not None and self._labelfs.label_app is not None
 
-    @classmethod
-    def labelFormatOK(cls, label):
+    def labelFormatOK(self, label):
         """Return True if the label has an acceptable format for this
            filesystem. None, which represents accepting the default for this
            device, is always acceptable.
@@ -177,7 +174,7 @@ def labelFormatOK(cls, label):
            :param label: A possible label
            :type label: str or None
         """
-        return label is None or (cls._labelfs is not None and cls._labelfs.labelFormatOK(label))
+        return label is None or (self._labelfs is not None and self._labelfs.labelFormatOK(label))
 
     label = property(lambda s: s._getLabel(), lambda s,l: s._setLabel(l),
        doc="this filesystem's label")
diff --git a/blivet/formats/swap.py b/blivet/formats/swap.py
index 264aa2f..26ebd4f 100644
--- a/blivet/formats/swap.py
+++ b/blivet/formats/swap.py
@@ -80,13 +80,11 @@ def dict(self):
         d.update({"priority": self.priority, "label": self.label})
         return d
 
-    @classmethod
-    def labeling(cls):
+    def labeling(self):
         """Returns True as mkswap can write a label to the swap space."""
         return True
 
-    @classmethod
-    def labelFormatOK(cls, label):
+    def labelFormatOK(self, label):
         """Returns True since no known restrictions on the label."""
         return True
 
diff --git a/tests/formats_test/labeling_test.py b/tests/formats_test/labeling_test.py
index 82a61b7..dfa6e79 100755
--- a/tests/formats_test/labeling_test.py
+++ b/tests/formats_test/labeling_test.py
@@ -15,41 +15,41 @@ def testLabels(self):
         """Initialize some filesystems with valid and invalid labels."""
 
         # Ext2FS has a maximum length of 16
-        self.assertFalse(fs.Ext2FS.labelFormatOK("root___filesystem"))
-        self.assertTrue(fs.Ext2FS.labelFormatOK("root__filesystem"))
+        self.assertFalse(fs.Ext2FS().labelFormatOK("root___filesystem"))
+        self.assertTrue(fs.Ext2FS().labelFormatOK("root__filesystem"))
 
         # FATFS has a maximum length of 11
-        self.assertFalse(fs.FATFS.labelFormatOK("rtfilesystem"))
-        self.assertTrue(fs.FATFS.labelFormatOK("rfilesystem"))
+        self.assertFalse(fs.FATFS().labelFormatOK("rtfilesystem"))
+        self.assertTrue(fs.FATFS().labelFormatOK("rfilesystem"))
 
         # JFS has a maximum length of 16
-        self.assertFalse(fs.JFS.labelFormatOK("root___filesystem"))
-        self.assertTrue(fs.JFS.labelFormatOK("root__filesystem"))
+        self.assertFalse(fs.JFS().labelFormatOK("root___filesystem"))
+        self.assertTrue(fs.JFS().labelFormatOK("root__filesystem"))
 
         # ReiserFS has a maximum length of 16
-        self.assertFalse(fs.ReiserFS.labelFormatOK("root___filesystem"))
-        self.assertTrue(fs.ReiserFS.labelFormatOK("root__filesystem"))
+        self.assertFalse(fs.ReiserFS().labelFormatOK("root___filesystem"))
+        self.assertTrue(fs.ReiserFS().labelFormatOK("root__filesystem"))
 
         #XFS has a maximum length 12 and does not allow spaces
-        self.assertFalse(fs.XFS.labelFormatOK("root_filesyst"))
-        self.assertFalse(fs.XFS.labelFormatOK("root file"))
-        self.assertTrue(fs.XFS.labelFormatOK("root_filesys"))
+        self.assertFalse(fs.XFS().labelFormatOK("root_filesyst"))
+        self.assertFalse(fs.XFS().labelFormatOK("root file"))
+        self.assertTrue(fs.XFS().labelFormatOK("root_filesys"))
 
         #HFS has a maximum length of 27, minimum length of 1, and does not allow colons
-        self.assertFalse(fs.HFS.labelFormatOK("n" * 28))
-        self.assertFalse(fs.HFS.labelFormatOK("root:file"))
-        self.assertFalse(fs.HFS.labelFormatOK(""))
-        self.assertTrue(fs.HFS.labelFormatOK("n" * 27))
+        self.assertFalse(fs.HFS().labelFormatOK("n" * 28))
+        self.assertFalse(fs.HFS().labelFormatOK("root:file"))
+        self.assertFalse(fs.HFS().labelFormatOK(""))
+        self.assertTrue(fs.HFS().labelFormatOK("n" * 27))
 
         #HFSPlus has a maximum length of 128, minimum length of 1, and does not allow colons
-        self.assertFalse(fs.HFSPlus.labelFormatOK("n" * 129))
-        self.assertFalse(fs.HFSPlus.labelFormatOK("root:file"))
-        self.assertFalse(fs.HFSPlus.labelFormatOK(""))
-        self.assertTrue(fs.HFSPlus.labelFormatOK("n" * 128))
+        self.assertFalse(fs.HFSPlus().labelFormatOK("n" * 129))
+        self.assertFalse(fs.HFSPlus().labelFormatOK("root:file"))
+        self.assertFalse(fs.HFSPlus().labelFormatOK(""))
+        self.assertTrue(fs.HFSPlus().labelFormatOK("n" * 128))
 
         # NTFS has a maximum length of 128
-        self.assertFalse(fs.NTFS.labelFormatOK("n" * 129))
-        self.assertTrue(fs.NTFS.labelFormatOK("n" * 128))
+        self.assertFalse(fs.NTFS().labelFormatOK("n" * 129))
+        self.assertTrue(fs.NTFS().labelFormatOK("n" * 128))
 
         # all devices are permitted to be passed a label argument of None
         # some will ignore it completely
@@ -62,7 +62,7 @@ class MethodsTestCase(unittest.TestCase):
     def setUp(self):
         self.fs = {}
         for k, v  in device_formats.items():
-            if issubclass(v, fs.FS) and v.labeling():
+            if issubclass(v, fs.FS) and v().labeling():
                 self.fs[k] = v(device="/dev", label="myfs")
 
 
@@ -87,7 +87,7 @@ def testGetLabelArgs(self):
         # all of the remaining are non-labeling so will accept any label
         label = "Houston, we have a problem!"
         for name, klass in device_formats.items():
-            if issubclass(klass, fs.FS) and not klass.labeling() and not issubclass(klass, fs.NFS):
+            if issubclass(klass, fs.FS) and not klass().labeling() and not issubclass(klass, fs.NFS):
                 self.assertEqual(klass(device="/dev", label=label).label, label, msg=name)
 
 class XFSTestCase(fslabeling.CompleteLabelingAsRoot):


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


More information about the anaconda-patches mailing list