[PATCH 2/4] Move a few constants and mappings to the storage_utils module
Vratislav Podzimek
vpodzime at redhat.com
Thu Apr 10 20:24:56 UTC 2014
All those constants and mappings are not GUI-specific and thus may live in a
place where they can be used from non-GUI code as well. Also the Custom spoke's
source file is long enough even without them.
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
pyanaconda/storage_utils.py | 46 +++++++++++++++++++++++++++++++++++++-
pyanaconda/ui/gui/spokes/custom.py | 43 +++++------------------------------
2 files changed, 50 insertions(+), 39 deletions(-)
diff --git a/pyanaconda/storage_utils.py b/pyanaconda/storage_utils.py
index 678c392..6f46aea 100644
--- a/pyanaconda/storage_utils.py
+++ b/pyanaconda/storage_utils.py
@@ -31,6 +31,11 @@ from blivet.devicefactory import DEVICE_TYPE_LVM
from blivet.devicefactory import DEVICE_TYPE_LVM_THINP
from blivet.devicefactory import DEVICE_TYPE_BTRFS
from blivet.devicefactory import DEVICE_TYPE_MD
+from blivet.devicefactory import DEVICE_TYPE_PARTITION
+
+from pyanaconda.i18n import N_
+from pykickstart.constants import AUTOPART_TYPE_PLAIN, AUTOPART_TYPE_BTRFS
+from pykickstart.constants import AUTOPART_TYPE_LVM, AUTOPART_TYPE_LVM_THINP
import logging
log = logging.getLogger("anaconda")
@@ -47,6 +52,41 @@ SUPPORTED_RAID_LEVELS = {DEVICE_TYPE_LVM: {"none", "raid0", "raid1"},
# "raid5", "raid6", "raid10"},
}
+# TODO: all those constants and mappings should go to blivet
+DEVICE_TEXT_LVM = N_("LVM")
+DEVICE_TEXT_LVM_THINP = N_("LVM Thin Provisioning")
+DEVICE_TEXT_MD = N_("RAID")
+DEVICE_TEXT_PARTITION = N_("Standard Partition")
+DEVICE_TEXT_BTRFS = N_("BTRFS")
+DEVICE_TEXT_DISK = N_("Disk")
+
+DEVICE_TEXT_MAP = {DEVICE_TYPE_LVM: DEVICE_TEXT_LVM,
+ DEVICE_TYPE_MD: DEVICE_TEXT_MD,
+ DEVICE_TYPE_PARTITION: DEVICE_TEXT_PARTITION,
+ DEVICE_TYPE_BTRFS: DEVICE_TEXT_BTRFS,
+ DEVICE_TYPE_LVM_THINP: DEVICE_TEXT_LVM_THINP}
+
+PARTITION_ONLY_FORMAT_TYPES = ("efi", "macefi", "prepboot", "biosboot", "appleboot")
+
+MOUNTPOINT_DESCRIPTIONS = {"Swap": N_("The 'swap' area on your computer is used by the operating\n"
+ "system when running low on memory."),
+ "Boot": N_("The 'boot' area on your computer is where files needed\n"
+ "to start the operating system are stored."),
+ "Root": N_("The 'root' area on your computer is where core system\n"
+ "files and applications are stored."),
+ "Home": N_("The 'home' area on your computer is where all your personal\n"
+ "data is stored."),
+ "BIOS Boot": N_("The BIOS boot partition is required to enable booting\n"
+ "from GPT-partitioned disks on BIOS hardware."),
+ "PReP Boot": N_("The PReP boot partition is required as part of the\n"
+ "bootloader configuration on some PPC platforms.")
+ }
+
+AUTOPART_DEVICE_TYPES = {AUTOPART_TYPE_LVM: DEVICE_TYPE_LVM,
+ AUTOPART_TYPE_LVM_THINP: DEVICE_TYPE_LVM_THINP,
+ AUTOPART_TYPE_PLAIN: DEVICE_TYPE_PARTITION,
+ AUTOPART_TYPE_BTRFS: DEVICE_TYPE_BTRFS}
+
def size_from_input(input_str):
"""Get size from user's input"""
@@ -75,6 +115,11 @@ def get_supported_raid_levels(device_type):
return SUPPORTED_RAID_LEVELS.get(device_type, set())
+def device_type_from_autopart(autopart_type):
+ """Get device type matching the given autopart type."""
+
+ return AUTOPART_DEVICE_TYPES.get(autopart_type, None)
+
class UIStorageFilter(logging.Filter):
"""Logging filter for UI storage events"""
@@ -91,4 +136,3 @@ def ui_storage_logger():
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 b3a9586..8834843 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -29,7 +29,7 @@
# - Implement striping and mirroring for LVM.
# - Activating reformat should always enable resize for existing devices.
-from pykickstart.constants import CLEARPART_TYPE_NONE, AUTOPART_TYPE_PLAIN, AUTOPART_TYPE_BTRFS, AUTOPART_TYPE_LVM, AUTOPART_TYPE_LVM_THINP
+from pykickstart.constants import CLEARPART_TYPE_NONE
from pyanaconda.i18n import _, N_, CP_
from pyanaconda.product import productName, productVersion, translated_new_install_name
@@ -64,6 +64,8 @@ from blivet.devicelibs import mdraid
from blivet.devices import LUKSDevice
from pyanaconda.storage_utils import get_supported_raid_levels, ui_storage_logger
+from pyanaconda.storage_utils import DEVICE_TEXT_PARTITION, DEVICE_TEXT_MD, DEVICE_TEXT_MAP
+from pyanaconda.storage_utils import PARTITION_ONLY_FORMAT_TYPES, MOUTPOINT_DESCRIPTIONS
from pyanaconda.ui.communication import hubQ
from pyanaconda.ui.gui.spokes import NormalSpoke
@@ -99,20 +101,6 @@ NOTEBOOK_LUKS_PAGE = 2
NOTEBOOK_UNEDITABLE_PAGE = 3
NOTEBOOK_INCOMPLETE_PAGE = 4
-
-DEVICE_TEXT_LVM = N_("LVM")
-DEVICE_TEXT_LVM_THINP = N_("LVM Thin Provisioning")
-DEVICE_TEXT_MD = N_("RAID")
-DEVICE_TEXT_PARTITION = N_("Standard Partition")
-DEVICE_TEXT_BTRFS = N_("BTRFS")
-DEVICE_TEXT_DISK = N_("Disk")
-
-DEVICE_TEXT_MAP = {DEVICE_TYPE_LVM: DEVICE_TEXT_LVM,
- DEVICE_TYPE_MD: DEVICE_TEXT_MD,
- DEVICE_TYPE_PARTITION: DEVICE_TEXT_PARTITION,
- DEVICE_TYPE_BTRFS: DEVICE_TEXT_BTRFS,
- DEVICE_TYPE_LVM_THINP: DEVICE_TEXT_LVM_THINP}
-
NEW_CONTAINER_TEXT = N_("Create a new %(container_type)s ...")
CONTAINER_TOOLTIP = N_("Create or select %(container_type)s")
@@ -121,23 +109,6 @@ DEVICE_CONFIGURATION_ERROR_MSG = N_("Device reconfiguration failed. Click for "
UNRECOVERABLE_ERROR_MSG = N_("Storage configuration reset due to unrecoverable "
"error. Click for details.")
-PARTITION_ONLY_FORMAT_TYPES = ["efi", "macefi", "prepboot", "biosboot",
- "appleboot"]
-
-MOUNTPOINT_DESCRIPTIONS = {"Swap": N_("The 'swap' area on your computer is used by the operating\n"
- "system when running low on memory."),
- "Boot": N_("The 'boot' area on your computer is where files needed\n"
- "to start the operating system are stored."),
- "Root": N_("The 'root' area on your computer is where core system\n"
- "files and applications are stored."),
- "Home": N_("The 'home' area on your computer is where all your personal\n"
- "data is stored."),
- "BIOS Boot": N_("The BIOS boot partition is required to enable booting\n"
- "from GPT-partitioned disks on BIOS hardware."),
- "PReP Boot": N_("The PReP boot partition is required as part of the\n"
- "bootloader configuration on some PPC platforms.")
- }
-
def dev_type_from_const(dev_type_const):
return getattr(devicefactory, dev_type_const, None)
@@ -1275,7 +1246,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
should_appear.add("DEVICE_TYPE_MD")
# if the format is swap the device type can't be btrfs
- if use_dev.format.type not in PARTITION_ONLY_FORMAT_TYPES + ["swap"]:
+ if use_dev.format.type not in PARTITION_ONLY_FORMAT_TYPES + ("swap"):
should_appear.add("DEVICE_TYPE_BTRFS")
# only include disk if the current device is a disk
@@ -1568,11 +1539,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
if lowerASCII(mountpoint) in ("swap", "biosboot", "prepboot"):
mountpoint = None
- device_type_from_autopart = {AUTOPART_TYPE_LVM: DEVICE_TYPE_LVM,
- AUTOPART_TYPE_LVM_THINP: DEVICE_TYPE_LVM_THINP,
- AUTOPART_TYPE_PLAIN: DEVICE_TYPE_PARTITION,
- AUTOPART_TYPE_BTRFS: DEVICE_TYPE_BTRFS}
- device_type = device_type_from_autopart[self.data.autopart.type]
+ device_type = device_type_from_autopart(self.data.autopart.type)
if (device_type != DEVICE_TYPE_PARTITION and
((mountpoint and mountpoint.startswith("/boot")) or
fstype in PARTITION_ONLY_FORMAT_TYPES)):
--
1.9.0
More information about the anaconda-patches
mailing list