mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-08 21:18:04 +03:00
osdict: Drop explicit 'type' class
create.py is the only thing that cares about this nowadays, so we can work with things to make it all simpler.
This commit is contained in:
parent
647420ca90
commit
595b5b4bdf
@ -25,6 +25,7 @@ import sys
|
||||
import unittest
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from virtinst import OSDB
|
||||
from virtinst import URISplit
|
||||
|
||||
_badmodules = ["gi.repository.Gtk", "gi.repository.Gdk"]
|
||||
@ -123,15 +124,32 @@ class TestMisc(unittest.TestCase):
|
||||
"version of gtk-3.8, which is what we target:\n" +
|
||||
"\n".join([("%s version=%s" % tup) for tup in failures]))
|
||||
|
||||
def test_libosinfo_aliases_ro(self):
|
||||
from virtinst import OSDB
|
||||
|
||||
class TestOSDB(unittest.TestCase):
|
||||
"""
|
||||
Test osdict/OSDB
|
||||
"""
|
||||
def test_osdict_aliases_ro(self):
|
||||
aliases = getattr(OSDB, "_aliases")
|
||||
|
||||
if len(aliases) != 40:
|
||||
if len(aliases) != 42:
|
||||
raise AssertionError(_("OSDB._aliases changed size. It "
|
||||
"should never be extended, since it is only for back "
|
||||
"compat with pre-libosinfo osdict.py"))
|
||||
|
||||
def test_osdict_types_ro(self):
|
||||
# 'types' should rarely be altered, this check will make
|
||||
# doubly sure that a new type isn't accidentally added
|
||||
approved_types = OSDB.list_types()
|
||||
|
||||
for osobj in OSDB.list_os():
|
||||
if osobj.get_typename() not in approved_types:
|
||||
raise AssertionError("OS entry '%s' has OS type '%s'.\n"
|
||||
"The type list should NOT be extended without a lot of "
|
||||
"thought, please make sure you know what you are doing." %
|
||||
(osobj.name, osobj.get_typename()))
|
||||
|
||||
|
||||
|
||||
class TestURI(unittest.TestCase):
|
||||
"""
|
||||
|
@ -813,25 +813,29 @@ class vmmCreate(vmmGObjectUI):
|
||||
STABLE_OS_SUPPORT or
|
||||
None)
|
||||
|
||||
types = virtinst.OSDB.list_os(list_types=True)
|
||||
types = virtinst.OSDB.list_types()
|
||||
if not filtervars:
|
||||
# Kind of a hack, just show linux + windows by default since
|
||||
# that's all 98% of people care about
|
||||
supportl = ["linux", "windows"]
|
||||
else:
|
||||
supportl = []
|
||||
for t in types:
|
||||
l = virtinst.OSDB.list_os(typename=t.name,
|
||||
for typename in types:
|
||||
l = virtinst.OSDB.list_os(typename=typename,
|
||||
only_supported=True,
|
||||
filtervars=filtervars)
|
||||
if l:
|
||||
supportl.append(t.name)
|
||||
supportl.append(typename)
|
||||
|
||||
self._add_os_row(model, None, _("Generic"), True)
|
||||
|
||||
for t in types:
|
||||
supported = (t.name in supportl)
|
||||
self._add_os_row(model, t.name, t.label, supported)
|
||||
for typename in types:
|
||||
supported = (typename in supportl)
|
||||
typelabel = typename.capitalize()
|
||||
if typename in ["unix"]:
|
||||
typelabel = typename.upper()
|
||||
|
||||
self._add_os_row(model, typename, typelabel, supported)
|
||||
|
||||
# Add sep
|
||||
self._add_os_row(model, sep=True)
|
||||
|
@ -162,13 +162,16 @@ class _OSDB(object):
|
||||
"ubuntuquantal" : "ubuntu12.10",
|
||||
"ubunturaring" : "ubuntu13.04",
|
||||
"ubuntusaucy" : "ubuntu13.10",
|
||||
"virtio26": "fedora10",
|
||||
"vista" : "winvista",
|
||||
"winxp64" : "winxp",
|
||||
|
||||
# Old --os-type values
|
||||
"linux" : "generic",
|
||||
"windows" : "winxp",
|
||||
"solaris" : "solaris10",
|
||||
"virtio26": "fedora10",
|
||||
"unix": "freebsd9",
|
||||
"other": "generic",
|
||||
}
|
||||
|
||||
|
||||
@ -179,15 +182,6 @@ class _OSDB(object):
|
||||
def _make_default_variants(self):
|
||||
ret = {}
|
||||
|
||||
# Back compat 'types'
|
||||
for name, label in [
|
||||
("linux", "Linux"),
|
||||
("windows", "Windows"),
|
||||
("solaris", "Solaris"),
|
||||
("unix", "UNIX"),
|
||||
("other", "Other")]:
|
||||
ret[name] = _OsVariantType(name, label, None, None)
|
||||
|
||||
# Generic variant
|
||||
v = _OsVariant(None)
|
||||
ret[v.name] = v
|
||||
@ -224,7 +218,7 @@ class _OSDB(object):
|
||||
def lookup_os(self, key):
|
||||
key = self._aliases.get(key) or key
|
||||
ret = self._all_variants.get(key)
|
||||
if ret is None or ret.is_type():
|
||||
if ret is None:
|
||||
return None
|
||||
return ret
|
||||
|
||||
@ -235,19 +229,18 @@ class _OSDB(object):
|
||||
return ret[0].get_short_id()
|
||||
return None
|
||||
|
||||
def list_os(self, list_types=False, typename=None,
|
||||
filtervars=None, only_supported=False,
|
||||
**kwargs):
|
||||
def list_types(self):
|
||||
approved_types = ["linux", "windows", "unix",
|
||||
"solaris", "other", "generic"]
|
||||
return approved_types
|
||||
|
||||
def list_os(self, typename=None, filtervars=None,
|
||||
only_supported=False, **kwargs):
|
||||
sortmap = {}
|
||||
filtervars = filtervars or []
|
||||
|
||||
for key, osinfo in self._all_variants.items():
|
||||
is_type = osinfo.is_type()
|
||||
if list_types and not is_type:
|
||||
continue
|
||||
if not list_types and is_type:
|
||||
continue
|
||||
if typename and typename != osinfo.typename:
|
||||
if typename and typename != osinfo.get_typename():
|
||||
continue
|
||||
if filtervars:
|
||||
filtervars = [self.lookup_os(x).name for x in filtervars]
|
||||
@ -278,42 +271,16 @@ def _is_os_related_to(o, related_os_list):
|
||||
return False
|
||||
|
||||
|
||||
class _OsVariantType(object):
|
||||
def __init__(self, name, label, urldistro, sortby):
|
||||
self.name = name
|
||||
self.label = label
|
||||
self.urldistro = urldistro
|
||||
self.sortby = sortby
|
||||
|
||||
def is_type(self):
|
||||
return self.__class__ == _OsVariantType
|
||||
|
||||
|
||||
class _OsVariant(_OsVariantType):
|
||||
class _OsVariant(object):
|
||||
def __init__(self, o):
|
||||
self._os = o
|
||||
name = self._get_name()
|
||||
if name != name.lower():
|
||||
raise RuntimeError("OS dictionary wants lowercase name, not "
|
||||
"'%s'" % self.name)
|
||||
self.typename = self._get_typename()
|
||||
self._family = self._os and self._os.get_family() or None
|
||||
|
||||
# 'types' should rarely be altered, this check will make
|
||||
# doubly sure that a new type isn't accidentally added
|
||||
_approved_types = ["linux", "windows", "unix",
|
||||
"solaris", "other", "generic"]
|
||||
if self.typename not in _approved_types:
|
||||
raise RuntimeError("type '%s' for variant '%s' not in list "
|
||||
"of approved distro types %s" %
|
||||
(self.typename, self.name, _approved_types))
|
||||
|
||||
|
||||
label = self._get_label()
|
||||
sortby = self._get_sortby()
|
||||
urldistro = self._get_urldistro()
|
||||
|
||||
_OsVariantType.__init__(self, name, label, urldistro, sortby)
|
||||
self.name = self._os and self._os.get_short_id() or "generic"
|
||||
self.label = self._os and self._os.get_name() or "Generic"
|
||||
|
||||
self.sortby = self._get_sortby()
|
||||
self.urldistro = self._get_urldistro()
|
||||
self.supported = self._get_supported()
|
||||
|
||||
|
||||
@ -321,11 +288,6 @@ class _OsVariant(_OsVariantType):
|
||||
# Cached APIs #
|
||||
###############
|
||||
|
||||
def _get_label(self):
|
||||
if not self._os:
|
||||
return "Generic"
|
||||
return self._os.get_name()
|
||||
|
||||
def _get_sortby(self):
|
||||
if not self._os:
|
||||
return "1"
|
||||
@ -379,29 +341,6 @@ class _OsVariant(_OsVariantType):
|
||||
|
||||
return urldistro
|
||||
|
||||
def _get_name(self):
|
||||
if not self._os:
|
||||
return "generic"
|
||||
return self._os.get_short_id()
|
||||
|
||||
def _get_typename(self):
|
||||
if not self._os:
|
||||
return "generic"
|
||||
|
||||
if self._os.get_family() in ['linux']:
|
||||
return "linux"
|
||||
|
||||
if self._os.get_family() in ['win9x', 'winnt', 'win16']:
|
||||
return "windows"
|
||||
|
||||
if self._os.get_family() in ['solaris']:
|
||||
return "solaris"
|
||||
|
||||
if self._os.get_family() in ['openbsd', 'freebsd', 'netbsd']:
|
||||
return "unix"
|
||||
|
||||
return "other"
|
||||
|
||||
|
||||
########################
|
||||
# Internal helper APIs #
|
||||
@ -417,17 +356,36 @@ class _OsVariant(_OsVariantType):
|
||||
# Public APIs #
|
||||
###############
|
||||
|
||||
def get_typename(self):
|
||||
"""
|
||||
Streamline the family name for use in the virt-manager UI
|
||||
"""
|
||||
if not self._os:
|
||||
return "generic"
|
||||
|
||||
if self._family in ['linux']:
|
||||
return "linux"
|
||||
|
||||
if self._family in ['win9x', 'winnt', 'win16']:
|
||||
return "windows"
|
||||
|
||||
if self._family in ['solaris']:
|
||||
return "solaris"
|
||||
|
||||
if self._family in ['openbsd', 'freebsd', 'netbsd']:
|
||||
return "unix"
|
||||
|
||||
return "other"
|
||||
|
||||
def is_windows(self):
|
||||
return (self._os and
|
||||
self._os.get_family() in ['win9x', 'winnt', 'win16'])
|
||||
return self.get_typename() == "windows"
|
||||
|
||||
def need_old_xen_disable_acpi(self):
|
||||
return self._is_related_to(["winxp", "win2k"])
|
||||
|
||||
def get_clock(self):
|
||||
if self._os:
|
||||
if self.is_windows() or self._os.get_family() in ['solaris']:
|
||||
return "localtime"
|
||||
if self.is_windows() or self._family in ['solaris']:
|
||||
return "localtime"
|
||||
return "utc"
|
||||
|
||||
def supports_virtioconsole(self):
|
||||
@ -444,8 +402,7 @@ class _OsVariant(_OsVariantType):
|
||||
return self._is_related_to(["fedora19"])
|
||||
|
||||
def supports_acpi(self, default):
|
||||
if (self._os and
|
||||
self._os.get_family() in ['msdos']):
|
||||
if self._family in ['msdos']:
|
||||
return False
|
||||
return default
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user