[PATCH 2/20] First little step towards libblockdev

vpodzime installerbot-noreply at redhat.com
Fri Feb 27 15:31:52 UTC 2015


From: Vratislav Podzimek <vpodzime at redhat.com>

We need to import and init the library first and give it the logging function
for utils execution.
---
 blivet/__init__.py | 17 +++++++++++++++++
 python-blivet.spec |  3 +++
 2 files changed, 20 insertions(+)

diff --git a/blivet/__init__.py b/blivet/__init__.py
index 5b95ce5..56576e6 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -57,6 +57,23 @@ def cb(self, exn):
 
 import logging
 log = logging.getLogger("blivet")
+program_log = logging.getLogger("program")
+
+# XXX: respect the level? Need to translate between C and Python log levels.
+log_bd_message = lambda level, msg: program_log.info(msg)
+
+# initialize the libblockdev library
+from gi.repository import BlockDev as blockdev
+_REQUIRED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm"))
+_required_plugins = blockdev.plugin_specs_from_names(_REQUIRED_PLUGIN_NAMES)
+if not blockdev.is_initialized():
+    if not blockdev.try_init(require_plugins=_required_plugins, log_func=log_bd_message):
+        raise RuntimeError("Failed to initialize the libblockdev library with all required plugins")
+else:
+    avail_plugs = set(blockdev.get_available_plugin_names())
+    if avail_plugs != _REQUIRED_PLUGIN_NAMES:
+        if not blockdev.reinit(require_plugins=_required_plugins, reload=False, log_func=log_bd_message):
+            raise RuntimeError("Failed to initialize the libblockdev library with all required plugins")
 
 def enable_installer_mode():
     """ Configure the module for use by anaconda (OS installer). """
diff --git a/python-blivet.spec b/python-blivet.spec
index 12ae4aa..a41088e 100644
--- a/python-blivet.spec
+++ b/python-blivet.spec
@@ -20,6 +20,7 @@ Source0: http://github.com/dwlehman/blivet/archive/%{realname}-%{version}.tar.gz
 %define pythoncryptsetupver 0.1.1
 %define utillinuxver 2.15.1
 %define lvm2ver 2.02.99
+%define libblockdevver 0.6
 
 BuildArch: noarch
 BuildRequires: gettext
@@ -43,6 +44,8 @@ Requires: btrfs-progs
 Requires: python-pyblock >= %{pythonpyblockver}
 Requires: device-mapper-multipath
 Requires: lsof
+Requires: libblockdev >= %{libblockdevver}
+Requires: libblockdev-plugins-all >= %{libblockdevver}
 
 %description
 The python-blivet package is a python module for examining and modifying


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


More information about the anaconda-patches mailing list