[PATCH 13/13] Make the ui_storage_logger reusable
Vratislav Podzimek
vpodzime at redhat.com
Mon Mar 10 13:22:19 UTC 2014
It's not GUI-specific so it belongs to the storage_utils module.
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
pyanaconda/storage_utils.py | 23 ++++++++++++++++++++++
pyanaconda/ui/gui/spokes/custom.py | 4 ++--
.../ui/gui/spokes/lib/custom_storage_helpers.py | 14 -------------
3 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/pyanaconda/storage_utils.py b/pyanaconda/storage_utils.py
index 504f72d..3dcd406 100644
--- a/pyanaconda/storage_utils.py
+++ b/pyanaconda/storage_utils.py
@@ -23,12 +23,17 @@
import re
import locale
+from contextlib import contextmanager
+
from blivet.size import Size
from blivet.errors import SizeParamsError
from blivet.devicefactory import DEVICE_TYPE_LVM
from blivet.devicefactory import DEVICE_TYPE_BTRFS
from blivet.devicefactory import DEVICE_TYPE_MD
+import logging
+log = logging.getLogger("anaconda")
+
# should this and the get_supported_raid_levels go to blivet.devicefactory???
SUPPORTED_RAID_LEVELS = {DEVICE_TYPE_LVM: {"none", "raid0", "raid1"},
DEVICE_TYPE_MD: {"raid0", "raid1", "raid4", "raid5",
@@ -67,3 +72,21 @@ def get_supported_raid_levels(device_type):
"""Get supported RAID levels for the given device type."""
return SUPPORTED_RAID_LEVELS.get(device_type, set())
+
+class UIStorageFilter(logging.Filter):
+ """Logging filter for UI storage events"""
+
+ def filter(self, record):
+ record.name = "storage.ui"
+ return True
+
+ at contextmanager
+def ui_storage_logger():
+ """Context manager that applies the UIStorageFilter for its block"""
+
+ storage_log = logging.getLogger("blivet")
+ storage_filter = UIStorageFilter()
+ storage_log.addFilter(storage_filter)
+ yield
+ storage_log.removeFilter(storage_filter)
+
diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index afae999..87482fd 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -63,7 +63,7 @@ from blivet.errors import LUKSDeviceWithoutKeyError
from blivet.devicelibs import mdraid
from blivet.devices import LUKSDevice
-from pyanaconda.storage_utils import get_supported_raid_levels
+from pyanaconda.storage_utils import get_supported_raid_levels, ui_storage_logger
from pyanaconda.ui.communication import hubQ
from pyanaconda.ui.gui.spokes import NormalSpoke
@@ -74,7 +74,7 @@ from pyanaconda.ui.gui.spokes.lib.accordion import selectorFromDevice, Accordion
from pyanaconda.ui.gui.spokes.lib.refresh import RefreshDialog
from pyanaconda.ui.gui.spokes.lib.summary import ActionSummaryDialog
-from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import size_from_entry, ui_storage_logger
+from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import size_from_entry
from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import validate_label, validate_mountpoint, selectedRaidLevel
from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import get_container_type_name, RAID_NOT_ENOUGH_DISKS
from pyanaconda.ui.gui.spokes.lib.custom_storage_helpers import AddDialog, ConfirmDeleteDialog, DisksDialog, ContainerDialog, HelpDialog
diff --git a/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py b/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
index 5bdeea0..64a264e 100644
--- a/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
+++ b/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
@@ -24,7 +24,6 @@
"""Helper functions and classes for custom partitioning."""
-from contextlib import contextmanager
import re
from pyanaconda.product import productName
@@ -65,19 +64,6 @@ def size_from_entry(entry):
size_text = entry.get_text().decode("utf-8").strip()
return size_from_input(size_text)
-class UIStorageFilter(logging.Filter):
- def filter(self, record):
- record.name = "storage.ui"
- return True
-
- at contextmanager
-def ui_storage_logger():
- storage_log = logging.getLogger("blivet")
- f = UIStorageFilter()
- storage_log.addFilter(f)
- yield
- storage_log.removeFilter(f)
-
def populate_mountpoint_store(store, used_mountpoints):
# sure, add whatever you want to this list. this is just a start.
paths = ["/", "/boot", "/home", "/var"] + \
--
1.8.5.3
More information about the anaconda-patches
mailing list