Skip to content
Snippets Groups Projects
Commit 75331849 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Canonicalize distro & osfamily params in os_cls()

If the distro name as returned by libguestfs's inspect_get_distro was
redhat-based, since hyphens are not allowed in module names, importing
module redhat-based would create an ImportError exception, even if file
redhat-based.py was present. Although we don't have any redhat-based.py
module and the code will still correctly fall back to importing
linux.py this can be considered as a bug. In order to overcome this, we
replace the hyphens with underscores in the distro and osfamily names.
In the future, if we have to create a module for redhat-based distros we
will name it redhat_based.py.
parent dd489072
No related branches found
No related tags found
No related merge requests found
......@@ -46,17 +46,27 @@ from functools import wraps
def os_cls(distro, osfamily):
"""Given the distro name and the osfamily, return the appropriate class"""
module = None
classname = None
"""Given the distro name and the osfamily, return the appropriate OSBase
derived class
"""
# hyphens are not allowed in module names
canonicalize = lambda x: x.replace('-', '_').lower()
distro = canonicalize(distro)
osfamily = canonicalize(osfamily)
try:
module = __import__("image_creator.os_type.%s" % distro,
fromlist=['image_creator.os_type'])
classname = distro.capitalize()
except ImportError:
module = __import__("image_creator.os_type.%s" % osfamily,
fromlist=['image_creator.os_type'])
classname = osfamily.capitalize()
try:
module = __import__("image_creator.os_type.%s" % osfamily,
fromlist=['image_creator.os_type'])
classname = osfamily.capitalize()
except ImportError:
raise FatalError("Unknown OS name: `%s'" % osfamily)
return getattr(module, classname)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment