Skip to content

Commit

Permalink
Make labeling(), relabels(), and labelFormatOK() instance methods.
Browse files Browse the repository at this point in the history
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@redhat.com>
  • Loading branch information
mulkieran committed May 12, 2015
1 parent bf8e88c commit e82aecd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 41 deletions.
8 changes: 3 additions & 5 deletions blivet/formats/__init__.py
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
15 changes: 6 additions & 9 deletions blivet/formats/fs.py
Expand Up @@ -151,33 +151,30 @@ 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.
: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")
Expand Down
6 changes: 2 additions & 4 deletions blivet/formats/swap.py
Expand Up @@ -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

Expand Down
46 changes: 23 additions & 23 deletions tests/formats_test/labeling_test.py
Expand Up @@ -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
Expand All @@ -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")


Expand All @@ -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):
Expand Down

0 comments on commit e82aecd

Please sign in to comment.