[libosinfo PATCH 2/3] media: Add installer to the media

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

 



Having the installer tied to the OS is something that has been shown not
optimal, unfortunately.

An OS may have a few different medias and each media may support a
specific type of script or, even, not support an installer script at
all. With this in mind, let's have the installer scripts tied to the
medias themselves.

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 osinfo/libosinfo.syms  |  5 +++++
 osinfo/osinfo_loader.c | 26 ++++++++++++++++++++++++++
 osinfo/osinfo_media.c  | 36 ++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_media.h  |  2 ++
 4 files changed, 69 insertions(+)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 2a60689..dad0c3b 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -562,6 +562,11 @@ LIBOSINFO_1.3.0 {
 	osinfo_tree_has_treeinfo;
 } LIBOSINFO_0.2.13;
 
+LIBOSINFO_1.4.0 {
+	osinfo_media_add_install_script;
+	osinfo_media_get_install_script_list;
+} LIBOSINFO_1.3.0;
+
 /* Symbols in next release...
 
   LIBOSINFO_0.0.2 {
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index a6f111c..95d4424 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1192,6 +1192,32 @@ static OsinfoMedia *osinfo_loader_media(OsinfoLoader *loader,
 
     g_free(nodes);
 
+    nnodes = osinfo_loader_nodeset("./installer/script", loader, ctxt, &nodes,
+                                   err);
+    if (error_is_set(err)) {
+        g_object_unref(media);
+        return NULL;
+    }
+
+    for (i = 0; i < nnodes; i++) {
+        OsinfoInstallScript *script;
+        gchar *scriptid;
+
+        scriptid = (gchar *)xmlGetProp(nodes[i], BAD_CAST "id");
+        if (scriptid == NULL) {
+            OSINFO_LOADER_SET_ERROR(err, _("Missing Media install script property"));
+            g_object_unref(media);
+            return NULL;
+        }
+
+        script = osinfo_loader_get_install_script(loader, scriptid);
+        xmlFree(scriptid);
+
+        osinfo_media_add_install_script(media, script);
+    }
+
+    g_free(nodes);
+
     return media;
 }
 
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 6bd1f66..6720736 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -193,6 +193,7 @@ G_DEFINE_TYPE(OsinfoMedia, osinfo_media, OSINFO_TYPE_ENTITY);
 struct _OsinfoMediaPrivate
 {
     GWeakRef os;
+    OsinfoInstallScriptList *scripts;
 };
 
 enum {
@@ -421,6 +422,10 @@ osinfo_media_set_property(GObject      *object,
 static void
 osinfo_media_finalize(GObject *object)
 {
+    OsinfoMedia *media = OSINFO_MEDIA(object);
+
+    g_object_unref(media->priv->scripts);
+
     /* Chain up to the parent class */
     G_OBJECT_CLASS(osinfo_media_parent_class)->finalize(object);
 }
@@ -694,6 +699,7 @@ osinfo_media_init(OsinfoMedia *media)
 {
     media->priv = OSINFO_MEDIA_GET_PRIVATE(media);
     g_weak_ref_init(&media->priv->os, NULL);
+    media->priv->scripts = osinfo_install_scriptlist_new();
 }
 
 OsinfoMedia *osinfo_media_new(const gchar *id,
@@ -1670,6 +1676,36 @@ gboolean osinfo_media_supports_installer_script(OsinfoMedia *media)
     return ret;
 }
 
+/**
+ * osinfo_media_add_install_script:
+ * @media: an #OsinfoMedia instance
+ * @script: an #OsinfoInstallScript instance
+ *
+ * Adds an @script to the specified @media
+ */
+void osinfo_media_add_install_script(OsinfoMedia *media, OsinfoInstallScript *script)
+{
+    g_return_if_fail(OSINFO_IS_MEDIA(media));
+
+    osinfo_list_add(OSINFO_LIST(media->priv->scripts), OSINFO_ENTITY(script));
+}
+
+/**
+ * osinfo_media_get_install_script_list:
+ * @media: an #OsinfoMedia instance
+ *
+ * Returns: (transfer full): a list of the install scripts for the specified media
+ */
+OsinfoInstallScriptList *osinfo_media_get_install_script_list(OsinfoMedia *media)
+{
+    OsinfoList *new_list;
+
+    g_return_val_if_fail(OSINFO_IS_MEDIA(media), NULL);
+    new_list = osinfo_list_new_copy(OSINFO_LIST(media->priv->scripts));
+
+    return OSINFO_INSTALL_SCRIPTLIST(new_list);
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index 6adc4be..3cac587 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -145,6 +145,8 @@ gint osinfo_media_get_installer_reboots(OsinfoMedia *media);
 gint64 osinfo_media_get_volume_size(OsinfoMedia *media);
 gboolean osinfo_media_get_eject_after_install(OsinfoMedia *media);
 gboolean osinfo_media_supports_installer_script(OsinfoMedia *media);
+void osinfo_media_add_install_script(OsinfoMedia *media, OsinfoInstallScript *install_script);
+OsinfoInstallScriptList *osinfo_media_get_install_script_list(OsinfoMedia *media);
 
 #endif /* __OSINFO_MEDIA_H__ */
 /*
-- 
2.20.1

_______________________________________________
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