[virt-tools-list] [libosinfo 4/4] API to indicate media is live and/or installer

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Wed Nov 23 22:07:58 UTC 2011


From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>

Add live and installer boolean getters to Media.
---
 osinfo/libosinfo.syms  |    2 ++
 osinfo/osinfo_loader.c |   15 +++++++++++++++
 osinfo/osinfo_media.c  |   40 ++++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_media.h  |    4 ++++
 tools/osinfo-detect.c  |   25 +++++++++++++++++--------
 5 files changed, 78 insertions(+), 8 deletions(-)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 5b4113e..f1411f7 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -157,6 +157,8 @@ LIBOSINFO_0.0.1 {
 	osinfo_media_get_publisher_id;
         osinfo_media_get_kernel_path;
         osinfo_media_get_initrd_path;
+	osinfo_media_get_installer;
+	osinfo_media_get_live;
 	osinfo_medialist_get_type;
 	osinfo_medialist_new;
 	osinfo_medialist_new_copy;
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 8a3de6a..79cc815 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -489,6 +489,8 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader,
     guint i;
 
     gchar *arch = (gchar *)xmlGetProp(root, BAD_CAST "arch");
+    xmlChar *live = xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_LIVE);
+    xmlChar *installer = xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_INSTALLER);
     const gchar *const keys[] = {
         OSINFO_MEDIA_PROP_URL,
         OSINFO_MEDIA_PROP_KERNEL,
@@ -499,6 +501,19 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader,
     OsinfoMedia *media = osinfo_media_new(id, arch);
 
     osinfo_loader_entity(loader, OSINFO_ENTITY(media), keys, ctxt, root, err);
+    if (live) {
+        osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                OSINFO_MEDIA_PROP_LIVE,
+                                (gchar *)live);
+        xmlFree(live);
+    }
+
+    if (installer) {
+        osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                OSINFO_MEDIA_PROP_INSTALLER,
+                                (gchar *)installer);
+        xmlFree(installer);
+    }
 
     gint nnodes = osinfo_loader_nodeset("./iso/*", ctxt, &nodes, err);
     if (*err)
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 6c98ba7..db262c6 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -577,6 +577,46 @@ const gchar *osinfo_media_get_initrd_path(OsinfoMedia *media)
                                          OSINFO_MEDIA_PROP_INITRD);
 }
 
+static gboolean get_param_as_bool (OsinfoMedia *media,
+                                   const char *key,
+                                   gboolean default_value)
+{
+    const gchar *value;
+
+    value = osinfo_entity_get_param_value(OSINFO_ENTITY(media), key);
+    if (value == NULL)
+        return default_value;
+
+    return (g_strcmp0 ("true", value) == 0 ||
+            g_strcmp0 ("yes", value) == 0);
+}
+
+/**
+ * osinfo_media_get_installer:
+ * @media: a #OsinfoMedia instance
+ *
+ * Wether @media provides a installer for an OS.
+ *
+ * Returns: #TRUE if media is installer, #FALSE otherwise
+ */
+gboolean osinfo_media_get_installer(OsinfoMedia *media)
+{
+    return get_param_as_bool (media, OSINFO_MEDIA_PROP_INSTALLER, TRUE);
+}
+
+/**
+ * osinfo_media_get_live:
+ * @media: a #OsinfoMedia instance
+ *
+ * Wether @media can boot directly an OS without any installations.
+ *
+ * Returns: #TRUE if media is live, #FALSE otherwise
+ */
+gboolean osinfo_media_get_live(OsinfoMedia *media)
+{
+    return get_param_as_bool (media, OSINFO_MEDIA_PROP_LIVE, FALSE);
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index 4a82025..6b15861 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -77,6 +77,8 @@ typedef struct _OsinfoMediaPrivate OsinfoMediaPrivate;
 #define OSINFO_MEDIA_PROP_PUBLISHER_ID "publisher-id"
 #define OSINFO_MEDIA_PROP_KERNEL       "kernel"
 #define OSINFO_MEDIA_PROP_INITRD       "initrd"
+#define OSINFO_MEDIA_PROP_LIVE         "live"
+#define OSINFO_MEDIA_PROP_INSTALLER    "installer"
 
 /* object */
 struct _OsinfoMedia
@@ -118,6 +120,8 @@ const gchar *osinfo_media_get_system_id(OsinfoMedia *media);
 const gchar *osinfo_media_get_publisher_id(OsinfoMedia *media);
 const gchar *osinfo_media_get_kernel_path(OsinfoMedia *media);
 const gchar *osinfo_media_get_initrd_path(OsinfoMedia *media);
+gboolean osinfo_media_get_installer(OsinfoMedia *media);
+gboolean osinfo_media_get_live(OsinfoMedia *media);
 
 #endif /* __OSINFO_MEDIA_H__ */
 /*
diff --git a/tools/osinfo-detect.c b/tools/osinfo-detect.c
index 0051cf4..750f98f 100644
--- a/tools/osinfo-detect.c
+++ b/tools/osinfo-detect.c
@@ -79,17 +79,26 @@ static void print_bootable(gboolean bootable)
             g_print("Media is not bootable.\n");
 }
 
-static void print_os(OsinfoOs *os)
+static void print_os(OsinfoOs *os, OsinfoMedia *media)
 {
     if (os == NULL)
         return;
 
-    if (format == OUTPUT_FORMAT_ENV)
-        g_print("OSINFO_INSTALLER=%s\n",
-                osinfo_entity_get_id(OSINFO_ENTITY(os)));
-    else
-        g_print("Media is an installer for OS '%s'\n",
-                osinfo_product_get_name(OSINFO_PRODUCT(os)));
+    if (format == OUTPUT_FORMAT_ENV) {
+        const gchar *id = osinfo_entity_get_id(OSINFO_ENTITY(os));
+
+        if (osinfo_media_get_installer (media))
+            g_print("OSINFO_INSTALLER=%s\n", id);
+        if (osinfo_media_get_live (media))
+            g_print("OSINFO_LIVE=%s\n", id);
+    } else {
+        const gchar *name = osinfo_product_get_name(OSINFO_PRODUCT(os));
+
+        if (osinfo_media_get_installer (media))
+            g_print("Media is an installer for OS '%s'\n", name);
+        if (osinfo_media_get_live (media))
+            g_print("Media is live media for OS '%s'\n", name);
+    }
 }
 
 gint main(gint argc, gchar **argv)
@@ -148,7 +157,7 @@ gint main(gint argc, gchar **argv)
     db = osinfo_loader_get_db(loader);
     os = osinfo_db_guess_os_from_media(db, media, &matched_media);
 
-    print_os(os);
+    print_os(os, matched_media);
 
 EXIT:
     g_clear_error(&error);
-- 
1.7.7.1




More information about the virt-tools-list mailing list