[Libosinfo] [libosinfo PATCH 3/5] media: Add _supports_installer_script()

Fabiano Fidêncio fidencio at redhat.com
Fri Nov 23 14:09:58 UTC 2018


Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 osinfo/libosinfo.syms |  2 ++
 osinfo/osinfo_media.c | 65 ++++++++++++++++++++++++++++++++++++++++++-
 osinfo/osinfo_media.h |  2 ++
 3 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 5396c72..6bccc1d 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -533,6 +533,8 @@ LIBOSINFO_1.3.0 {
     global:
 	osinfo_error_quark;
 
+	osinfo_media_supports_installer_script;
+
 	osinfo_os_add_maximum_resources;
 	osinfo_os_get_all_device_links;
 	osinfo_os_get_maximum_resources;
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 293732d..519f8ab 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -157,7 +157,8 @@ enum {
     PROP_OS,
     PROP_LANGUAGES,
     PROP_VOLUME_SIZE,
-    PROP_EJECT_AFTER_INSTALL
+    PROP_EJECT_AFTER_INSTALL,
+    PROP_INSTALLER_SCRIPT
 };
 
 static void
@@ -242,6 +243,11 @@ osinfo_media_get_property(GObject    *object,
                             osinfo_media_get_eject_after_install(media));
         break;
 
+    case PROP_INSTALLER_SCRIPT:
+        g_value_set_boolean(value,
+                            osinfo_media_supports_installer_script(media));
+        break;
+
     default:
         /* We don't have any other property... */
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -342,8 +348,14 @@ osinfo_media_set_property(GObject      *object,
         osinfo_entity_set_param_boolean(OSINFO_ENTITY(media),
                                         OSINFO_MEDIA_PROP_EJECT_AFTER_INSTALL,
                                         g_value_get_boolean(value));
+        break;
 
+    case PROP_INSTALLER_SCRIPT:
+        osinfo_entity_set_param_boolean(OSINFO_ENTITY(media),
+                                        OSINFO_MEDIA_PROP_INSTALLER_SCRIPT,
+                                        g_value_get_boolean(value));
         break;
+
     default:
         /* We don't have any other property... */
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -604,6 +616,22 @@ osinfo_media_class_init(OsinfoMediaClass *klass)
                                  G_PARAM_READWRITE |
                                  G_PARAM_STATIC_STRINGS);
     g_object_class_install_property(g_klass, PROP_EJECT_AFTER_INSTALL, pspec);
+
+    /**
+     * OsinfoMedia:installer-script:
+     *
+     * Whether the media supports installation via an install-script.
+     *
+     * Some distros provide a few different medias and not all the medias support
+     * installation via an install script.
+     */
+    pspec = g_param_spec_boolean("installer-script",
+                                 "InstallerScript",
+                                 _("Whether the media should be used for an installation using install scripts"),
+                                 TRUE /* default value */,
+                                 G_PARAM_READWRITE |
+                                 G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(g_klass, PROP_INSTALLER_SCRIPT, pspec);
 }
 
 static void
@@ -1312,6 +1340,41 @@ gboolean osinfo_media_get_eject_after_install(OsinfoMedia *media)
         (OSINFO_ENTITY(media), OSINFO_MEDIA_PROP_EJECT_AFTER_INSTALL, TRUE);
 }
 
+/**
+ * osinfo_media_supports_installer_script:
+ * @media: an #OsinfoMedia instance
+ *
+ * Whether @media supports installation using install scripts.
+ *
+ * Returns: #TRUE if install-scripts are supported by the media,
+ * #FALSE otherwise
+ */
+gboolean osinfo_media_supports_installer_script(OsinfoMedia *media)
+{
+    OsinfoOs *os;
+    OsinfoInstallScriptList *list;
+    gboolean ret;
+
+    g_return_val_if_fail(OSINFO_IS_MEDIA(media), FALSE);
+
+    os = osinfo_media_get_os(media);
+    list = osinfo_os_get_install_script_list(os);
+
+    if (osinfo_list_get_length(OSINFO_LIST(list)) == 0) {
+        ret = FALSE;
+        goto cleanup;
+    }
+
+    ret = osinfo_entity_get_param_value_boolean_with_default
+            (OSINFO_ENTITY(media), OSINFO_MEDIA_PROP_INSTALLER_SCRIPT, TRUE);
+
+ cleanup:
+    g_object_unref(list);
+    g_object_unref(os);
+
+    return ret;
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index 6df7b60..27d77ae 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -91,6 +91,7 @@ typedef struct _OsinfoMediaPrivate OsinfoMediaPrivate;
 #define OSINFO_MEDIA_PROP_VARIANT        "variant"
 #define OSINFO_MEDIA_PROP_VOLUME_SIZE    "volume-size"
 #define OSINFO_MEDIA_PROP_EJECT_AFTER_INSTALL "eject-after-install"
+#define OSINFO_MEDIA_PROP_INSTALLER_SCRIPT "installer-script"
 
 /* object */
 struct _OsinfoMedia
@@ -142,6 +143,7 @@ gboolean osinfo_media_get_live(OsinfoMedia *media);
 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);
 
 #endif /* __OSINFO_MEDIA_H__ */
 /*
-- 
2.19.1




More information about the Libosinfo mailing list