[[PATCH v3] 4/6] media: Add variant info API/XML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add:

* ability to associate media to one or more variants of the OS in the
  'media' XML node. For example:

  <os id="http://microsoft.com/win/7";>
    <short-id>win7</short-id>
    <name>Microsoft Windows 7</name>
    ..

    <variant id="starter">
      <name>Microsoft Windows 7 Starter</name>
    </variant>
    <variant id="home-basic">
      <name>Microsoft Windows 7 Home Basic</name>
    </variant>
    <variant id="home-premium">
      <name>Microsoft Windows 7 Home Premium</name>
    </variant>
    ..

    <media installer-reboots="2" arch="x86_64">
      <variant id="home-premium"/>
      <iso>
        ..
      </iso>
    </media>
  </os>

* API to query variants of the OS, media is associated with.
---
 data/schemas/libosinfo.rng |  6 ++++++
 osinfo/libosinfo.syms      |  2 ++
 osinfo/osinfo_db.c         |  8 +++++++-
 osinfo/osinfo_loader.c     | 18 ++++++++++++++++--
 osinfo/osinfo_media.c      | 39 +++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_media.h      |  3 +++
 6 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng
index cc13982..0675217 100644
--- a/data/schemas/libosinfo.rng
+++ b/data/schemas/libosinfo.rng
@@ -338,6 +338,12 @@
         </attribute>
       </optional>
       <optional>
+        <element name='variant'>
+          <attribute name='id'>
+          </attribute>
+        </element>
+      </optional>
+      <optional>
         <element name='url'>
           <ref name='url'/>
         </element>
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 21d80f4..637ad09 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -448,6 +448,8 @@ LIBOSINFO_0.2.9 {
 	osinfo_os_get_release_status;
 	osinfo_release_status_get_type;
 
+	osinfo_media_get_os_variants;
+
 	osinfo_os_add_variant;
 	osinfo_os_get_variant_list;
 
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index f19d9b4..db04033 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -627,6 +627,7 @@ static void fill_media (OsinfoDb *db, OsinfoMedia *media,
     const gchar *initrd_path;
     const gchar *arch;
     const gchar *url;
+    GList *variants, *node;
 
     languages = match_languages(db, media, matched_media);
     if (languages != NULL)
@@ -642,7 +643,12 @@ static void fill_media (OsinfoDb *db, OsinfoMedia *media,
     url = osinfo_media_get_url(matched_media);
     if (url != NULL)
         g_object_set(G_OBJECT(media), "url", url, NULL);
-
+    variants = osinfo_entity_get_param_value_list(OSINFO_ENTITY(matched_media),
+                                                  "variant");
+    for (node = variants; node != NULL; node = node->next)
+        osinfo_entity_add_param(OSINFO_ENTITY(media),
+                                "variant",
+                                (gchar *) node->data);
     kernel_path = osinfo_media_get_kernel_path(matched_media);
     if (kernel_path != NULL)
         g_object_set(G_OBJECT(media), "kernel_path", kernel_path, NULL);
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index affc49b..e9ce8e1 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -859,7 +859,6 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader,
     xmlChar *installer = xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_INSTALLER);
     xmlChar *installer_reboots =
             xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_INSTALLER_REBOOTS);
-    xmlChar *variant = xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_VARIANT);
     const OsinfoEntityKey keys[] = {
         { OSINFO_MEDIA_PROP_URL, G_TYPE_STRING },
         { OSINFO_MEDIA_PROP_KERNEL, G_TYPE_STRING },
@@ -892,7 +891,22 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader,
         xmlFree(installer_reboots);
     }
 
-    gint nnodes = osinfo_loader_nodeset("./iso/*", ctxt, &nodes, err);
+    gint nnodes = osinfo_loader_nodeset("./variant", ctxt, &nodes, err);
+    if (error_is_set(err)) {
+        g_object_unref(media);
+        return NULL;
+    }
+
+    for (i = 0 ; i < nnodes ; i++) {
+        gchar *variant_id = (gchar *)xmlGetProp(nodes[i], BAD_CAST "id");
+        osinfo_entity_add_param(OSINFO_ENTITY(media),
+                                OSINFO_MEDIA_PROP_VARIANT,
+                                variant_id);
+        xmlFree(variant_id);
+    }
+    g_free(nodes);
+
+    nnodes = osinfo_loader_nodeset("./iso/*", ctxt, &nodes, err);
     if (error_is_set(err)) {
         g_object_unref(media);
         return NULL;
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 118ff8b..0d6b96a 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -1136,6 +1136,45 @@ void osinfo_media_set_os(OsinfoMedia *media, OsinfoOs *os)
 }
 
 /**
+ * osinfo_media_get_os_variants:
+ * @media: an #OsinfoMedia instance
+ *
+ * Gets the variants of the associated operating system.
+ *
+ * Returns: (transfer full): the operating system variant, or NULL
+ */
+OsinfoOsVariantList *osinfo_media_get_os_variants(OsinfoMedia *media)
+{
+    OsinfoOs *os;
+    OsinfoOsVariantList *os_variants;
+    OsinfoOsVariantList *media_variants;
+    GList *ids, *node;
+    OsinfoFilter *filter;
+
+    g_return_val_if_fail(OSINFO_IS_MEDIA(media), NULL);
+    os = g_weak_ref_get(&media->priv->os);
+    os_variants = osinfo_os_get_variant_list(os);
+    g_object_unref (os);
+
+    ids = osinfo_entity_get_param_value_list(OSINFO_ENTITY(media),
+                                             OSINFO_MEDIA_PROP_VARIANT);
+    filter = osinfo_filter_new();
+    media_variants = osinfo_os_variantlist_new();
+    for (node = ids; node != NULL; node = node->next) {
+        osinfo_filter_clear_constraints(filter);
+        osinfo_filter_add_constraint(filter,
+                                     OSINFO_ENTITY_PROP_ID,
+                                     (const char *) node->data);
+        osinfo_list_add_filtered(OSINFO_LIST(media_variants),
+                                 OSINFO_LIST(os_variants),
+                                 filter);
+    }
+    g_object_unref (os_variants);
+
+    return media_variants;
+}
+
+/**
  * osinfo_media_get_languages:
  * @media: an #OsinfoMedia instance
  *
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index 308f75e..8cf3e05 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -26,6 +26,7 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 #include <osinfo/osinfo_entity.h>
+#include <osinfo/osinfo_os_variantlist.h>
 
 #ifndef __OSINFO_MEDIA_H__
 #define __OSINFO_MEDIA_H__
@@ -84,6 +85,7 @@ typedef struct _OsinfoMediaPrivate OsinfoMediaPrivate;
 #define OSINFO_MEDIA_PROP_LANG           "l10n-language"
 #define OSINFO_MEDIA_PROP_LANG_REGEX     "l10n-language-regex"
 #define OSINFO_MEDIA_PROP_LANG_MAP       "l10n-language-map"
+#define OSINFO_MEDIA_PROP_VARIANT        "variant"
 
 /* object */
 struct _OsinfoMedia
@@ -128,6 +130,7 @@ const gchar *osinfo_media_get_application_id(OsinfoMedia *media);
 const gchar *osinfo_media_get_kernel_path(OsinfoMedia *media);
 const gchar *osinfo_media_get_initrd_path(OsinfoMedia *media);
 OsinfoOs *osinfo_media_get_os(OsinfoMedia *media);
+OsinfoOsVariantList *osinfo_media_get_os_variants(OsinfoMedia *media);
 GList *osinfo_media_get_languages(OsinfoMedia *media);
 gboolean osinfo_media_get_installer(OsinfoMedia *media);
 gboolean osinfo_media_get_live(OsinfoMedia *media);
-- 
1.8.4.2

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux