osdict: add get_location()

get_location() is a new method that returns the osinfo-db tree URL of an
OS, according to the passed architecture.

This method will need some improvement later on once we start having a
specific set of definitions on osinfo-db about what's the type of the OS
we're dealing with (like Server, Desktop, ...).

For now, the new method returns the first URL found without taking into
the consideration the types speficied above.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
This commit is contained in:
Fabiano Fidêncio 2019-02-08 16:23:56 +01:00 committed by Cole Robinson
parent e103aab7cc
commit 08d3a5786c

View File

@ -477,5 +477,30 @@ class _OsVariant(object):
return None
def get_location(self, arch):
if not self._os:
return None
treefilter = libosinfo.Filter()
treefilter.add_constraint(libosinfo.TREE_PROP_ARCHITECTURE, arch)
treelist = self._os.get_tree_list()
if treelist.get_length() < 1:
logging.error(
_("%s does not have a URL location"), self.name)
return None
filtered_treelist = treelist.new_filtered(treefilter)
if filtered_treelist.get_length() < 1:
logging.error(
_("%s does not have a URL location for the %s architecture"),
self.name, arch)
return None
# Some distros have more than one URL for a specific architecture,
# which is the case for Fedora and different variants (Server,
# Workstation). Later on, we'll have to differentiate that and return
# the right one.
return filtered_treelist.get_nth(0).get_url()
OSDB = _OSDB()