[virt-tools-list] [libosinfo PATCHv3 3/9] Add osinfo_db_identify_media
Christophe Fergeau
cfergeau at redhat.com
Wed Dec 12 14:26:32 UTC 2012
---
osinfo/libosinfo.syms | 1 +
osinfo/osinfo_db.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
osinfo/osinfo_db.h | 2 ++
osinfo/osinfo_media.c | 5 +++-
test/test-isodetect.c | 10 ++++----
tools/osinfo-detect.c | 13 ++++++----
6 files changed, 91 insertions(+), 11 deletions(-)
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 95fde94..4d886f6 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -386,6 +386,7 @@ LIBOSINFO_0.2.3 {
osinfo_db_add_datamap;
osinfo_db_get_datamap;
osinfo_db_get_datamap_list;
+ osinfo_db_identify_media;
osinfo_install_config_new_for_script;
osinfo_install_config_get_valid_params;
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index dcda2fe..e236cad 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -25,6 +25,7 @@
#include <config.h>
#include <osinfo/osinfo.h>
+#include "osinfo_media_private.h"
#include <gio/gio.h>
#include <string.h>
#include <glib/gi18n-lib.h>
@@ -527,6 +528,76 @@ OsinfoOs *osinfo_db_guess_os_from_media(OsinfoDb *db,
return ret;
}
+static void fill_media (OsinfoMedia *media, OsinfoMedia *matched_media, OsinfoOs *os)
+{
+ gboolean is_installer;
+ gboolean is_live;
+ gint reboots;
+ const gchar *kernel_path;
+ const gchar *initrd_path;
+ const gchar *arch;
+ const gchar *url;
+
+ arch = osinfo_media_get_architecture(matched_media);
+ if (arch != NULL)
+ g_object_set(G_OBJECT(media), "architecture", arch, NULL);
+ url = osinfo_media_get_url(matched_media);
+ if (url != NULL)
+ g_object_set(G_OBJECT(media), "url", url, NULL);
+
+ kernel_path = osinfo_media_get_kernel_path(matched_media);
+ if (kernel_path != NULL)
+ g_object_set(G_OBJECT(media), "kernel_path", kernel_path, NULL);
+
+ initrd_path = osinfo_media_get_initrd_path(matched_media);
+ if (initrd_path != NULL)
+ g_object_set(G_OBJECT(media), "initrd_path", initrd_path, NULL);
+ is_installer = osinfo_media_get_installer(matched_media);
+ is_live = osinfo_media_get_live(matched_media);
+ g_object_set(G_OBJECT(media),
+ "installer", is_installer,
+ "live", is_live,
+ NULL);
+ if (is_installer) {
+ reboots = osinfo_media_get_installer_reboots(matched_media);
+ g_object_set(G_OBJECT(media), "installer-reboots", reboots, NULL);
+ }
+ if (os != NULL)
+ osinfo_media_set_os(media, os);
+}
+
+/**
+ * osinfo_db_identify_media:
+ * @db: a #OsinfoDb database
+ * @media: the installation media
+ * data
+ *
+ * Try to match a newly created @media with a media description from @db.
+ * If found, @media will be filled with the corresponding information
+ * stored in @db. In particular, after a call to
+ * osinfo_db_identify_media(), if the media could be identified, its
+ * OsinfoMedia::os property will be set.
+ *
+ * Returns: TRUE if @media was found in @db, FALSE otherwise
+ */
+gboolean osinfo_db_identify_media(OsinfoDb *db, OsinfoMedia *media)
+{
+ OsinfoMedia *matched_media;
+ OsinfoOs *matched_os;
+
+ g_return_val_if_fail(OSINFO_IS_MEDIA(media), FALSE);
+ g_return_val_if_fail(OSINFO_IS_DB(db), FALSE);
+
+ matched_os = osinfo_db_guess_os_from_media(db, media, &matched_media);
+ if (matched_os == NULL) {
+ return FALSE;
+ }
+
+ fill_media(media, matched_media, matched_os);
+
+ return TRUE;
+}
+
/**
* osinfo_db_guess_os_from_tree:
diff --git a/osinfo/osinfo_db.h b/osinfo/osinfo_db.h
index 824a224..09a58f0 100644
--- a/osinfo/osinfo_db.h
+++ b/osinfo/osinfo_db.h
@@ -103,6 +103,8 @@ void osinfo_db_add_install_script(OsinfoDb *db, OsinfoInstallScript *script);
OsinfoOs *osinfo_db_guess_os_from_media(OsinfoDb *db,
OsinfoMedia *media,
OsinfoMedia **matched_media);
+gboolean osinfo_db_identify_media(OsinfoDb *db,
+ OsinfoMedia *media);
OsinfoOs *osinfo_db_guess_os_from_tree(OsinfoDb *db,
OsinfoTree *tree,
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 1db374c..d891615 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -505,7 +505,10 @@ osinfo_media_class_init (OsinfoMediaClass *klass)
/**
* OsinfoMedia::os:
*
- * Os information for the current media.
+ * Os information for the current media. For media stored in an
+ * #OsinfoDB, it will be filled when the database is loaded, otherwise
+ * the property will be filled after a successful call to
+ * osinfo_db_identify_media().
*/
pspec = g_param_spec_object ("os",
"Os",
diff --git a/test/test-isodetect.c b/test/test-isodetect.c
index 9033b32..f627300 100644
--- a/test/test-isodetect.c
+++ b/test/test-isodetect.c
@@ -252,18 +252,18 @@ static void test_one(const gchar *vendor)
tmp = isos;
while (tmp) {
struct ISOInfo *info = tmp->data;
- OsinfoMedia *media = NULL;
- OsinfoOs *os = osinfo_db_guess_os_from_media(db,
- info->media,
- &media);
+ gboolean matched = osinfo_db_identify_media(db, info->media);
+ OsinfoOs *os;
- fail_unless(os != NULL, "ISO %s was not matched by OS %s",
+ fail_unless(matched, "ISO %s was not matched by OS %s",
info->filename, info->shortid);
+ g_object_get(info->media, "os", &os, NULL);
const gchar *shortid = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
fail_unless(g_str_equal(shortid, info->shortid),
"ISO %s matched OS %s instead of expected %s",
info->filename, shortid, info->shortid);
+ g_object_unref(G_OBJECT(os));
tmp = tmp->next;
}
diff --git a/tools/osinfo-detect.c b/tools/osinfo-detect.c
index 60aabba..0caa4ca 100644
--- a/tools/osinfo-detect.c
+++ b/tools/osinfo-detect.c
@@ -118,8 +118,11 @@ static void print_bootable(gboolean bootable)
g_print(_("Media is not bootable.\n"));
}
-static void print_os_media(OsinfoOs *os, OsinfoMedia *media)
+static void print_media(OsinfoMedia *media)
{
+ OsinfoOs *os;
+
+ g_object_get(G_OBJECT(media), "os", &os, NULL);
if (os == NULL)
return;
@@ -140,6 +143,7 @@ static void print_os_media(OsinfoOs *os, OsinfoMedia *media)
if (osinfo_media_get_live (media))
g_print(_("Media is live media for OS '%s'\n"), name);
}
+ g_object_unref(os);
}
static void print_os_tree(OsinfoOs *os, OsinfoTree *tree, OsinfoTree *matched_tree)
@@ -182,7 +186,6 @@ gint main(gint argc, gchar **argv)
GError *error = NULL;
OsinfoLoader *loader = NULL;
OsinfoDb *db = NULL;
- OsinfoOs *os = NULL;
gint ret = 0;
setlocale(LC_ALL, "");
@@ -227,7 +230,6 @@ gint main(gint argc, gchar **argv)
if (type == URL_TYPE_MEDIA) {
OsinfoMedia *media = NULL;
- OsinfoMedia *matched_media = NULL;
media = osinfo_media_create_from_location(argv[1], NULL, &error);
if (error != NULL) {
if (error->code != OSINFO_MEDIA_ERROR_NOT_BOOTABLE) {
@@ -241,9 +243,10 @@ gint main(gint argc, gchar **argv)
} else {
print_bootable(TRUE);
}
- os = osinfo_db_guess_os_from_media(db, media, &matched_media);
- print_os_media(os, matched_media);
+ osinfo_db_identify_media(db, media);
+ print_media(media);
} else if (type == URL_TYPE_TREE) {
+ OsinfoOs *os = NULL;
OsinfoTree *tree = NULL;
OsinfoTree *matched_tree = NULL;
tree = osinfo_tree_create_from_location(argv[1], NULL, &error);
--
1.8.0.1
More information about the virt-tools-list
mailing list