[2.0-devel 3/3] Let Python import the formats for us
by dashea
From: Vratislav Podzimek <vpodzime(a)redhat.com>
This seems to be faster than our custom code which currently brings no real
advantage as we don't want to support some random formats given to us by
somebody else.
---
blivet/formats/__init__.py | 29 ++---------------------------
1 file changed, 2 insertions(+), 27 deletions(-)
diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index e15ad1f..07532af 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -50,7 +50,6 @@
import logging
log = logging.getLogger("blivet")
-
device_formats = {}
@@ -110,28 +109,6 @@ def get_format(fmt_type, *args, **kwargs):
return fmt
-def collect_device_format_classes():
- """ Pick up all device format classes from this directory.
-
- .. note::
-
- Modules must call :func:`register_device_format` to make format
- classes available to :func:`getFormat`.
- """
- mydir = os.path.dirname(__file__)
- myfile = os.path.basename(__file__)
- (myfile_name, _ext) = os.path.splitext(myfile)
- for module_file in os.listdir(mydir):
- (mod_name, ext) = os.path.splitext(module_file)
- if ext == ".py" and mod_name != myfile_name and not mod_name.startswith("."):
- try:
- globals()[mod_name] = importlib.import_module("." + mod_name, package=__package__)
- except ImportError:
- log.error("import of device format module '%s' failed", mod_name)
- from traceback import format_exc
- log.debug("%s", format_exc())
-
-
def get_device_format_class(fmt_type):
""" Return an appropriate format class.
@@ -142,9 +119,6 @@ def get_device_format_class(fmt_type):
Returns None if no class is found for fmt_type.
"""
- if not device_formats:
- collect_device_format_classes()
-
fmt = device_formats.get(fmt_type)
if not fmt:
for fmt_class in device_formats.values():
@@ -758,4 +732,5 @@ def populate_ksdata(self, data):
register_device_format(DeviceFormat)
-collect_device_format_classes()
+# import the format modules (which register their device formats)
+from . import biosboot, disklabel, dmraid, fslib, fs, luks, lvmpv, mdraid, multipath, prepboot, swap
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/1d5896b0b22525000aa9271f65d4...
8 years
[2.0-devel 1/3] Call is_mpath_member() only when it makes sense
by dashea
From: David Lehman <dlehman(a)redhat.com>
---
blivet/populator/helpers/disklabel.py | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/blivet/populator/helpers/disklabel.py b/blivet/populator/helpers/disklabel.py
index af2ae51..75e2be6 100644
--- a/blivet/populator/helpers/disklabel.py
+++ b/blivet/populator/helpers/disklabel.py
@@ -43,14 +43,11 @@ class DiskLabelFormatPopulator(FormatPopulator):
@classmethod
def match(cls, data, device):
- is_multipath_member = (device.is_disk and
- blockdev.mpath_is_mpath_member(device.path))
-
# XXX ignore disklabels on multipath or biosraid member disks
return (bool(udev.device_get_disklabel_type(data)) and
not udev.device_is_biosraid_member(data) and
- not is_multipath_member and
- udev.device_get_format(data) != "iso9660")
+ udev.device_get_format(data) != "iso9660" and
+ not (device.is_disk and blockdev.mpath_is_mpath_member(device.path)))
def _get_kwargs(self):
kwargs = super()._get_kwargs()
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/c10440d9e584882550c9c73c3c35...
8 years
[master 3/3] Let Python import the formats for us
by dashea
From: Vratislav Podzimek <vpodzime(a)redhat.com>
This seems to be faster than our custom code which currently brings no real
advantage as we don't want to support some random formats given to us by
somebody else.
---
blivet/formats/__init__.py | 29 ++---------------------------
1 file changed, 2 insertions(+), 27 deletions(-)
diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index e15ad1f..07532af 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -50,7 +50,6 @@
import logging
log = logging.getLogger("blivet")
-
device_formats = {}
@@ -110,28 +109,6 @@ def get_format(fmt_type, *args, **kwargs):
return fmt
-def collect_device_format_classes():
- """ Pick up all device format classes from this directory.
-
- .. note::
-
- Modules must call :func:`register_device_format` to make format
- classes available to :func:`getFormat`.
- """
- mydir = os.path.dirname(__file__)
- myfile = os.path.basename(__file__)
- (myfile_name, _ext) = os.path.splitext(myfile)
- for module_file in os.listdir(mydir):
- (mod_name, ext) = os.path.splitext(module_file)
- if ext == ".py" and mod_name != myfile_name and not mod_name.startswith("."):
- try:
- globals()[mod_name] = importlib.import_module("." + mod_name, package=__package__)
- except ImportError:
- log.error("import of device format module '%s' failed", mod_name)
- from traceback import format_exc
- log.debug("%s", format_exc())
-
-
def get_device_format_class(fmt_type):
""" Return an appropriate format class.
@@ -142,9 +119,6 @@ def get_device_format_class(fmt_type):
Returns None if no class is found for fmt_type.
"""
- if not device_formats:
- collect_device_format_classes()
-
fmt = device_formats.get(fmt_type)
if not fmt:
for fmt_class in device_formats.values():
@@ -758,4 +732,5 @@ def populate_ksdata(self, data):
register_device_format(DeviceFormat)
-collect_device_format_classes()
+# import the format modules (which register their device formats)
+from . import biosboot, disklabel, dmraid, fslib, fs, luks, lvmpv, mdraid, multipath, prepboot, swap
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/1d5896b0b22525000aa9271f65d4...
8 years
[master 2/3] Only call resolve_devspec() in _get_active_mounts() for
real
devices
by dashea
From: Vratislav Podzimek <vpodzime(a)redhat.com>
---
blivet/mounts.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/blivet/mounts.py b/blivet/mounts.py
index 6bb00d4..c787fde 100644
--- a/blivet/mounts.py
+++ b/blivet/mounts.py
@@ -151,7 +151,8 @@ def _get_active_mounts(self):
continue
# use the canonical device path (if available)
- devspec = resolve_devspec(devspec, sysname=True) or devspec
+ if devspec.startswith("/dev"):
+ devspec = resolve_devspec(devspec, sysname=True) or devspec
if fstype == "btrfs":
root = mountinfo.get_root(devspec, mountpoint)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/86bbc98fd7a728285d303f0494c4...
8 years