From 9d9640430c87db584ffcb1b71859bdd25dd322b5 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Wed, 30 May 2012 10:57:26 -0500 Subject: [PATCH] Add class methods for type, name, supported, &c. The properties now just call the class methods, allowing callers to use the property for instances or the class method without an instance. --- pyanaconda/storage/formats/__init__.py | 37 ++++++++++++++++++------- pyanaconda/storage/formats/biosboot.py | 4 +- pyanaconda/storage/formats/fs.py | 46 ++++++++++++++++---------------- pyanaconda/storage/formats/prepboot.py | 4 +- 4 files changed, 53 insertions(+), 38 deletions(-) diff --git a/pyanaconda/storage/formats/__init__.py b/pyanaconda/storage/formats/__init__.py index 3df470e..3255773 100644 --- a/pyanaconda/storage/formats/__init__.py +++ b/pyanaconda/storage/formats/__init__.py @@ -50,13 +50,9 @@ def register_device_format(fmt_class): default_fstypes = ("ext4", "ext3", "ext2") def get_default_filesystem_type(): for fstype in default_fstypes: - try: - supported = get_device_format_class(fstype).supported - except AttributeError: - supported = None - - if supported: - return fstype + cls = get_device_format_class(fstype) + if cls.getSupported() and cls.getFormattable() and cls.getMountable(): + return cls raise DeviceFormatError("None of %s is supported by your kernel" % ",".join(default_fstypes)) @@ -231,6 +227,10 @@ class DeviceFormat(object): @property def name(self): + return self.getName() + + @classmethod + def getName(self): if self._name: name = self._name else: @@ -239,6 +239,10 @@ class DeviceFormat(object): @property def type(self): + return self.getType() + + @classmethod + def getType(self): return self._type def probe(self): @@ -346,15 +350,22 @@ class DeviceFormat(object): self.device and os.path.exists(self.device)) + @classmethod + def getFormattable(self): + return self._formattable + @property def formattable(self): """ Can we create formats of this type? """ - return self._formattable + return self.getFormattable() + + @classmethod + def getSupported(self): + return self._supported @property def supported(self): - """ Is this format a supported type? """ - return self._supported + return self.getSupported() @property def packages(self): @@ -385,10 +396,14 @@ class DeviceFormat(object): """ Is this format type native to linux? """ return self._linuxNative + @classmethod + def getMountable(self): + return False + @property def mountable(self): """ Is this something we can mount? """ - return False + return self.getMountable() @property def dump(self): diff --git a/pyanaconda/storage/formats/biosboot.py b/pyanaconda/storage/formats/biosboot.py index 93e1de7..23c19a8 100644 --- a/pyanaconda/storage/formats/biosboot.py +++ b/pyanaconda/storage/formats/biosboot.py @@ -51,8 +51,8 @@ class BIOSBoot(DeviceFormat): def status(self): return False - @property - def supported(self): + @classmethod + def getSupported(self): from pyanaconda import platform return isinstance(platform.getPlatform(None), platform.X86) diff --git a/pyanaconda/storage/formats/fs.py b/pyanaconda/storage/formats/fs.py index a9abe1a..5e3cfbd 100644 --- a/pyanaconda/storage/formats/fs.py +++ b/pyanaconda/storage/formats/fs.py @@ -770,13 +770,13 @@ class FS(DeviceFormat): return True - @property - def supported(self): + @classmethod + def getSupported(self): log_method_call(self, supported=self._supported) return self._supported and self.utilsAvailable - @property - def mountable(self): + @classmethod + def getMountable(self): canmount = (self.mountType in kernel_filesystems) or \ (os.access("/sbin/mount.%s" % (self.mountType,), os.X_OK)) modpath = os.path.realpath(os.path.join("/lib/modules", os.uname()[2])) @@ -1117,8 +1117,8 @@ class EFIFS(FATFS): _name = "EFI System Partition" _minSize = 50 - @property - def supported(self): + @classmethod + def getSupported(self): from pyanaconda import platform p = platform.getPlatform(None) return (isinstance(p, platform.EFI) and @@ -1198,8 +1198,8 @@ class GFS2(FS): # partition table type correctly for btrfs partitions # partedSystem = fileSystemType["gfs2"] - @property - def supported(self): + @classmethod + def getSupported(self): """ Is this filesystem a supported type? """ supported = self._supported if flags.cmdline.has_key("gfs2"): @@ -1230,8 +1230,8 @@ class JFS(FS): _existingSizeFields = ["Aggregate block size:", "Aggregate size:"] partedSystem = fileSystemType["jfs"] - @property - def supported(self): + @classmethod + def getSupported(self): """ Is this filesystem a supported type? """ supported = self._supported if flags.cmdline.has_key("jfs"): @@ -1264,8 +1264,8 @@ class ReiserFS(FS): _existingSizeFields = ["Count of blocks on the device:", "Blocksize:"] partedSystem = fileSystemType["reiserfs"] - @property - def supported(self): + @classmethod + def getSupported(self): """ Is this filesystem a supported type? """ supported = self._supported if flags.cmdline.has_key("reiserfs"): @@ -1352,8 +1352,8 @@ class AppleBootstrapFS(HFS): _minSize = 800.00 / 1024.00 _maxSize = 1 - @property - def supported(self): + @classmethod + def getSupported(self): from pyanaconda import platform return (isinstance(platform.getPlatform(None), platform.NewWorldPPC) and self.utilsAvailable) @@ -1397,8 +1397,8 @@ class NTFS(FS): _existingSizeFields = ["Cluster Size:", "Volume Size in Clusters:"] partedSystem = fileSystemType["ntfs"] - @property - def mountable(self): + @classmethod + def getMountable(self): return False def _fsckFailed(self, rc): @@ -1458,8 +1458,8 @@ class NFS(FS): if devspec is not None and ":" not in devspec: raise ValueError("device must be of the form :") - @property - def mountable(self): + @classmethod + def getMountable(self): return False def _setDevice(self, devspec): @@ -1553,8 +1553,8 @@ register_device_format(TmpFS) class BindFS(FS): _type = "bind" - @property - def mountable(self): + @classmethod + def getMountable(self): return True def _getExistingSize(self): @@ -1569,9 +1569,9 @@ register_device_format(BindFS) class SELinuxFS(NoDevFS): _type = "selinuxfs" - @property - def mountable(self): - return flags.selinux and super(SELinuxFS, self).mountable + @classmethod + def getMountable(self): + return flags.selinux and super(SELinuxFS, self).getMountable() register_device_format(SELinuxFS) diff --git a/pyanaconda/storage/formats/prepboot.py b/pyanaconda/storage/formats/prepboot.py index 9b65a4d..ddef09d 100644 --- a/pyanaconda/storage/formats/prepboot.py +++ b/pyanaconda/storage/formats/prepboot.py @@ -78,8 +78,8 @@ class PPCPRePBoot(DeviceFormat): def status(self): return False - @property - def supported(self): + @classmethod + def getSupported(self): from pyanaconda import platform return isinstance(platform.getPlatform(None), platform.IPSeriesPPC) -- 1.7.6.5