[PATCH 18/21] Base auto-generated name prefixes on productName, not device type.

David Lehman dlehman at redhat.com
Thu Aug 9 21:22:37 UTC 2012


---
 pyanaconda/constants.py        |    5 +++++
 pyanaconda/storage/__init__.py |   29 +++++++++++++++--------------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/pyanaconda/constants.py b/pyanaconda/constants.py
index 1baf6bd..c2a4b2b 100644
--- a/pyanaconda/constants.py
+++ b/pyanaconda/constants.py
@@ -49,6 +49,11 @@ productArch = product.productArch
 bugzillaUrl = product.bugUrl
 isFinal = product.isFinal
 
+# for use in device names, eg: "fedora", "rhel"
+shortProductName = productName.lower()
+if productName.count(" "):
+    shortProductName = ''.join(s[0] for s in shortProductName.split())
+
 exceptionText = _("An unhandled exception has occurred.  This "
                   "is most likely a bug.  Please save a copy of "
                   "the detailed exception and file a bug report")
diff --git a/pyanaconda/storage/__init__.py b/pyanaconda/storage/__init__.py
index 881dc0c..0c1b10a 100644
--- a/pyanaconda/storage/__init__.py
+++ b/pyanaconda/storage/__init__.py
@@ -1140,7 +1140,7 @@ class Storage(object):
                         hostname = nd.hostname
                         break
 
-            name = self.suggestContainerName(hostname=hostname, prefix="vg")
+            name = self.suggestContainerName(hostname=hostname)
 
         if name in self.names:
             raise ValueError("name already in use")
@@ -1163,8 +1163,7 @@ class Storage(object):
                 swap = True
             else:
                 swap = False
-            name = self.suggestDeviceName(prefix="lv",
-                                          parent=vg,
+            name = self.suggestDeviceName(parent=vg,
                                           swap=swap,
                                           mountpoint=mountpoint)
 
@@ -1212,15 +1211,10 @@ class Storage(object):
                             hostname = nd.hostname
                             break
 
-                name = self.suggestContainerName(prefix="btrfs",
-                                                 hostname=hostname)
+                name = self.suggestContainerName(hostname=hostname)
             if "label" not in fmt_args:
                 fmt_args["label"] = name
 
-        # do we want to prevent a subvol with a name that matches another dev?
-        if name in self.names:
-            raise ValueError("name already in use")
-
         # discard fmt_type since it's btrfs always
         kwargs.pop("fmt_type", None)
 
@@ -1323,15 +1317,19 @@ class Storage(object):
 
     def suggestContainerName(self, hostname=None, prefix=""):
         """ Return a reasonable, unused device name. """
+        if not prefix:
+            prefix = shortProductName
+
         # try to create a device name incorporating the hostname
         if hostname not in (None, "", 'localhost', 'localhost.localdomain'):
             template = "%s_%s" % (prefix, hostname.split('.')[0].lower())
             template = self.safeDeviceName(template)
-        elif flags.imageInstall:
-            template = "%s_image" % prefix
         else:
             template = prefix
 
+        if flags.imageInstall:
+            template = "%s_image" % template
+
         names = self.names
         name = template
         if name in names:
@@ -1355,11 +1353,14 @@ class Storage(object):
         body = ""
         if mountpoint:
             if mountpoint == "/":
-                body = "_root"
+                body = "root"
             else:
-                body = mountpoint.replace("/", "_")
+                body = mountpoint[1:].replace("/", "_")
         elif swap:
-            body = "_swap"
+            body = "swap"
+
+        if prefix:
+            body = "_" + body
 
         template = self.safeDeviceName(prefix + body)
         names = self.names
-- 
1.7.7.6



More information about the anaconda-patches mailing list