osdict: add new function lookup_os_by_media

"lookup_os_by_media" fetches the OS of the installation media by
querying libosinfo.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2014-03-25 13:47:54 +01:00
parent c6a48c5123
commit af216ebaf6
1 changed files with 10 additions and 2 deletions

View File

@ -24,6 +24,8 @@ _allvariants = {}
from datetime import datetime
from gi.repository import Libosinfo as libosinfo # pylint: disable=E0611
loader = libosinfo.Loader()
loader.process_default_path()
_aliases = {
"altlinux" : "altlinux1.0",
@ -162,6 +164,14 @@ def get_recommended_resources(variant, arch):
return v.get_recommended_resources(arch)
def lookup_os_by_media(location):
media = libosinfo.Media.create_from_location(location, None)
ret = loader.get_db().guess_os_from_media(media)
if len(ret) > 0:
return ret[0].get_short_id()
return None
class _OSVariant(object):
"""
Object tracking guest OS specific configuration bits.
@ -559,8 +569,6 @@ _add_type("unix", "UNIX")
_add_type("other", "Other")
_add_var("generic", "Generic", supported=True, parent="other")
loader = libosinfo.Loader()
loader.process_default_path()
db = loader.get_db()
oslist = db.get_os_list()