osdict: If detecting fedora-unknown, convert to latest fedora

That's basically what it is internally for libosinfo, and it helps
us generate better names in virt-manager
This commit is contained in:
Cole Robinson 2015-04-13 17:05:25 -04:00
parent 10ad151d4b
commit dcfce5585a
2 changed files with 21 additions and 11 deletions

View File

@ -20,6 +20,7 @@
# MA 02110-1301 USA.
import datetime
import logging
import re
from gi.repository import Libosinfo as libosinfo
@ -228,9 +229,17 @@ class _OSDB(object):
def lookup_os_by_media(self, location):
media = libosinfo.Media.create_from_location(location, None)
ret = self._os_loader.get_db().guess_os_from_media(media)
if ret and len(ret) > 0 and ret[0]:
return ret[0].get_short_id()
return None
if not (ret and len(ret) > 0 and ret[0]):
return None
osname = ret[0].get_short_id()
if osname == "fedora-unknown":
osname = self.latest_fedora_version()
logging.debug("Detected location=%s as os=fedora-unknown. "
"Converting that to the latest fedora OS version=%s",
location, osname)
return osname
def list_types(self):
approved_types = ["linux", "windows", "unix",
@ -257,6 +266,13 @@ class _OSDB(object):
return _sort(sortmap, sortpref=sortpref,
limit_point_releases=only_supported)
def latest_fedora_version(self):
for osinfo in self.list_os():
if (osinfo.name.startswith("fedora") and
"unknown" not in osinfo.name):
# First fedora* occurrence should be the newest
return osinfo.name
#####################
# OsVariant classes #

View File

@ -666,14 +666,8 @@ class FedoraDistro(RedHatDistro):
"""
Search osdict list, find newest fedora version listed
"""
ret = None
for osinfo in OSDB.list_os(typename="linux"):
if osinfo.name.startswith("fedora") and "unknown" not in osinfo.name:
# First fedora* occurrence should be the newest
ret = osinfo.name
break
return ret, int(ret[6:])
latest = OSDB.latest_fedora_version()
return latest, int(latest[6:])
def isValidStore(self):
if not self._hasTreeinfo():