python-blivet/0002-Avoid-AttributeError-f...

39 lines
1.4 KiB
Diff

From bf70f3625e517b73ed45c0d5d40c210124ccd4bc Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Tue, 6 Apr 2021 14:59:41 +0200
Subject: [PATCH] Avoid AttributeError for DiskLabel formats without disklabel
type
Simple instance of DiskLabel without label_type specified in the
constructor results in a AttributeError when trying to print the
format name. This makes sure the name is always valid.
Resolves: rhbz#1945914
---
blivet/formats/disklabel.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index 7102457b..c8148309 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -313,13 +313,13 @@ def sector_size(self):
@property
def name(self):
- if self.supported:
- _str = "%(name)s (%(type)s)"
+ if self.label_type is None:
+ return "%(name)s" % {"name": _(self._name)}
+ elif self.supported:
+ return "%(name)s (%(type)s)" % {"name": _(self._name), "type": self.label_type.upper()}
else:
# Translators: Name for an unsupported disklabel; e.g. "Unsupported partition table"
- _str = _("Unsupported %(name)s")
-
- return _str % {"name": _(self._name), "type": self.label_type.upper()}
+ return _("Unsupported %(name)s") % {"name": _(self._name)}
@property
def size(self):