Re: [PATCH 02/10] Add osinfo_install_script_generate_for_media*()

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

 



Hey,

On Thu, May 07, 2015 at 05:36:37PM +0100, Zeeshan Ali (Khattak) wrote:
> Add API that allows apps to pass the media matched against the OS they
> are generating the script for. Scripts can use this information to make
> decisions about how installation should be setup. For example, we are
> going to use this in the Fedora installer script to decide whether to
> install from ISO or from network, based on whether or not media is a
> network installer.
> ---
>  osinfo/libosinfo.syms          |   4 +
>  osinfo/osinfo_install_script.c | 197 ++++++++++++++++++++++++++++++++++++-----
>  osinfo/osinfo_install_script.h |  16 ++++
>  3 files changed, 196 insertions(+), 21 deletions(-)
> 
> diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
> index 2dba411..ba4c020 100644
> --- a/osinfo/libosinfo.syms
> +++ b/osinfo/libosinfo.syms
> @@ -507,6 +507,10 @@ LIBOSINFO_0.2.11 {
>  
>  LIBOSINFO_0.2.12 {
>      global:
> +	osinfo_install_script_generate_for_media;
> +	osinfo_install_script_generate_for_media_async;
> +	osinfo_install_script_generate_for_media_finish;
> +
>  	osinfo_media_get_volume_size;
>  } LIBOSINFO_0.2.11;
>  
> diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
> index a6a5bab..621c56f 100644
> --- a/osinfo/osinfo_install_script.c
> +++ b/osinfo/osinfo_install_script.c
> @@ -533,6 +533,7 @@ OsinfoAvatarFormat *osinfo_install_script_get_avatar_format(OsinfoInstallScript
>  struct _OsinfoInstallScriptGenerateData {
>      GSimpleAsyncResult *res;
>      OsinfoOs *os;
> +    OsinfoMedia *media;
>      OsinfoInstallConfig *config;
>      OsinfoInstallScript *script;
>  };
> @@ -541,6 +542,8 @@ struct _OsinfoInstallScriptGenerateData {
>  static void osinfo_install_script_generate_data_free(OsinfoInstallScriptGenerateData *data)
>  {
>      g_object_unref(data->os);
> +    if (data->media != NULL)
> +        g_object_unref(data->media);
>      g_object_unref(data->config);
>      g_object_unref(data->script);
>      g_object_unref(data->res);
> @@ -731,6 +734,7 @@ static xmlNodePtr osinfo_install_script_generate_entity_xml(OsinfoInstallScript
>  
>  static xmlDocPtr osinfo_install_script_generate_config_xml(OsinfoInstallScript *script,
>                                                             OsinfoOs *os,
> +                                                           OsinfoMedia *media,
>                                                             OsinfoInstallConfig *config,
>                                                             const gchar *node_name,
>                                                             GError **error)
> @@ -767,6 +771,19 @@ static xmlDocPtr osinfo_install_script_generate_config_xml(OsinfoInstallScript *
>          goto error;
>      }
>  
> +    if (media != NULL) {
> +        if (!(node = osinfo_install_script_generate_entity_xml(script,
> +                                                               OSINFO_ENTITY(media),
> +                                                               "media",
> +                                                               error)))
> +            goto error;
> +        if (!(xmlAddChild(root, node))) {
> +            xmlErrorPtr err = xmlGetLastError();
> +            g_set_error(error, 0, 0, _("Unable to set XML root '%s'"), err ? err->message : "");

Error message could most likely be better, eg "Unable to set 'media' node: %s"

> +            goto error;
> +        }
> +    }
> +
>      if (!(node = osinfo_install_script_generate_entity_xml(script,
>                                                             OSINFO_ENTITY(config),
>                                                             "config",
> @@ -819,6 +836,7 @@ static gchar *osinfo_install_script_apply_xslt(xsltStylesheetPtr ss,
>  
>  static gboolean osinfo_install_script_apply_template(OsinfoInstallScript *script,
>                                                       OsinfoOs *os,
> +                                                     OsinfoMedia *media,
>                                                       const gchar *templateUri,
>                                                       const gchar *template,
>                                                       const gchar *node_name,
> @@ -828,7 +846,7 @@ static gboolean osinfo_install_script_apply_template(OsinfoInstallScript *script
>  {
>      gboolean ret = FALSE;
>      xsltStylesheetPtr templateXsl = osinfo_install_script_load_template(templateUri, template, error);
> -    xmlDocPtr configXml = osinfo_install_script_generate_config_xml(script, os, config, node_name, error);
> +    xmlDocPtr configXml = osinfo_install_script_generate_config_xml(script, os, media, config, node_name, error);
>  
>      if (!templateXsl || !configXml)
>          goto cleanup;
> @@ -871,6 +889,7 @@ static void osinfo_install_script_template_loaded(GObject *src,
>  
>      if (!osinfo_install_script_apply_template(data->script,
>                                                data->os,
> +                                              data->media,
>                                                uri,
>                                                input,
>                                                "install-script-config",
> @@ -891,43 +910,35 @@ static void osinfo_install_script_template_loaded(GObject *src,
>      g_free(uri);
>  }
>  
> -/**
> - * osinfo_install_script_generate_async:
> - * @script:     the install script
> - * @os:         the os
> - * @config:     the install script config
> - * @cancellable: (allow-none): a #GCancellable, or %NULL
> - * @callback: Function to call when result of this call is ready
> - * @user_data: The user data to pass to @callback, or %NULL
> - *
> - * Asynchronous variant of #osinfo_install_script_generate(). From the callback,
> - * call #osinfo_install_script_generate_finish() to conclude this call and get
> - * the generated script.
> - */
> -void osinfo_install_script_generate_async(OsinfoInstallScript *script,
> -                                          OsinfoOs *os,
> -                                          OsinfoInstallConfig *config,
> -                                          GCancellable *cancellable,
> -                                          GAsyncReadyCallback callback,
> -                                          gpointer user_data)
> +
> +static void osinfo_install_script_generate_async_common(OsinfoInstallScript *script,
> +                                                        OsinfoOs *os,
> +                                                        OsinfoMedia *media,
> +                                                        OsinfoInstallConfig *config,
> +                                                        GCancellable *cancellable,
> +                                                        GAsyncReadyCallback callback,
> +                                                        gpointer user_data)
>  {
>      OsinfoInstallScriptGenerateData *data = g_new0(OsinfoInstallScriptGenerateData, 1);
>      const gchar *templateData = osinfo_install_script_get_template_data(script);
>      const gchar *templateUri = osinfo_install_script_get_template_uri(script);
>  
>      data->os = g_object_ref(os);
> +    if (media != NULL)
> +        data->media = g_object_ref(media);
>      data->config = g_object_ref(config);
>      data->script = g_object_ref(script);
>      data->res = g_simple_async_result_new(G_OBJECT(script),
>                                            callback,
>                                            user_data,
> -                                          osinfo_install_script_generate_async);
> +                                          osinfo_install_script_generate_async_common);
>  
>      if (templateData) {
>          GError *error = NULL;
>          gchar *output;
>          if (!osinfo_install_script_apply_template(script,
>                                                    os,
> +                                                  media,
>                                                    "<data>",
>                                                    templateData,
>                                                    "install-script-config",
> @@ -954,6 +965,35 @@ void osinfo_install_script_generate_async(OsinfoInstallScript *script,
>      }
>  }
>  
> +/**
> + * osinfo_install_script_generate_async:
> + * @script:     the install script
> + * @os:         the os
> + * @config:     the install script config
> + * @cancellable: (allow-none): a #GCancellable, or %NULL
> + * @callback: Function to call when result of this call is ready
> + * @user_data: The user data to pass to @callback, or %NULL
> + *
> + * Asynchronous variant of #osinfo_install_script_generate(). From the callback,
> + * call #osinfo_install_script_generate_finish() to conclude this call and get
> + * the generated script.
> + */
> +void osinfo_install_script_generate_async(OsinfoInstallScript *script,
> +                                          OsinfoOs *os,
> +                                          OsinfoInstallConfig *config,
> +                                          GCancellable *cancellable,
> +                                          GAsyncReadyCallback callback,
> +                                          gpointer user_data)
> +{
> +    osinfo_install_script_generate_async_common(script,
> +                                                os,
> +                                                NULL,
> +                                                config,
> +                                                cancellable,
> +                                                callback,
> +                                                user_data);
> +}
> +
>  static gpointer osinfo_install_script_generate_finish_common(OsinfoInstallScript *script,
>                                                               GAsyncResult *res,
>                                                               GError **error)
> @@ -986,6 +1026,25 @@ gchar *osinfo_install_script_generate_finish(OsinfoInstallScript *script,
>  }
>  
>  /**
> + * osinfo_install_script_generate_for_media_finish:
> + * @script: the install script
> + * @res:    a #GAsyncResult
> + * @error:  The location where to store any error, or NULL
> + *
> + * Returns: (transfer full): the generated script, or NULL on error
> + *
> + * Since: 0.2.12
> + */
> +gchar *osinfo_install_script_generate_for_media_finish(OsinfoInstallScript *script,
> +                                                       GAsyncResult *res,
> +                                                       GError **error)
> +{
> +    return osinfo_install_script_generate_finish_common(script,
> +                                                        res,
> +                                                        error);
> +}
> +
> +/**
>   * osinfo_install_script_generate_output_finish:
>   * @script: the install script
>   * @res:    a #GAsyncResult
> @@ -1094,6 +1153,101 @@ gchar *osinfo_install_script_generate(OsinfoInstallScript *script,
>      return data.output;
>  }
>  
> +/**
> + * osinfo_install_script_generate_for_media_async:
> + * @script:     the install script
> + * @media:      the media
> + * @config:     the install script config
> + * @cancellable: (allow-none): a #GCancellable, or %NULL
> + * @callback: Function to call when result of this call is ready
> + * @user_data: The user data to pass to @callback, or %NULL
> + *
> + * Asynchronous variant of #osinfo_install_script_generate_for_media(). From the
> + * callback, call #osinfo_install_script_generate_for_media_finish() to
> + * conclude this call and get the generated script.
> + *
> + * Since: 0.2.12
> + */
> +void osinfo_install_script_generate_for_media_async(OsinfoInstallScript *script,
> +                                                    OsinfoMedia *media,
> +                                                    OsinfoInstallConfig *config,
> +                                                    GCancellable *cancellable,
> +                                                    GAsyncReadyCallback callback,
> +                                                    gpointer user_data) {
> +    OsinfoOs *os;
> +
> +    g_return_if_fail (media != NULL);
> +
> +    os = osinfo_media_get_os (media);
> +    g_return_if_fail (os != NULL);

This bit could go in _async_common?

> +
> +    osinfo_install_script_generate_async_common(script,
> +                                                os,
> +                                                media,
> +                                                config,
> +                                                cancellable,
> +                                                callback,
> +                                                user_data);
> +}
> +
> +static void osinfo_install_script_generate_for_media_done(GObject *src,
> +                                                          GAsyncResult *res,
> +                                                          gpointer user_data)
> +{
> +    OsinfoInstallScriptGenerateSyncData *data = user_data;
> +
> +    data->output =
> +        osinfo_install_script_generate_for_media_finish(OSINFO_INSTALL_SCRIPT(src),
> +                                                        res,
> +                                                        &data->error);
> +    g_main_loop_quit(data->loop);
> +}
> +
> +/**
> + * osinfo_install_script_generate_for_media:
> + * @script:     the install script
> + * @media:      the media
> + * @config:     the install script config
> + * @cancellable: (allow-none): a #GCancellable, or %NULL
> + * @error: The location where to store any error, or %NULL
> + *
> + * Creates an install script. The media @media must have been identified
> + * successfully using #osinfo_db_identify_media() before calling this function.
> + *
> + * Returns: (transfer full): the script as string.
> + *
> + * Since: 0.2.12
> + */
> +gchar *osinfo_install_script_generate_for_media(OsinfoInstallScript *script,
> +                                                OsinfoMedia *media,
> +                                                OsinfoInstallConfig *config,
> +                                                GCancellable *cancellable,
> +                                                GError **error)
> +{
> +    GMainLoop *loop = g_main_loop_new(g_main_context_get_thread_default(),
> +                                      TRUE);
> +    OsinfoInstallScriptGenerateSyncData data = {
> +        loop, NULL, NULL, NULL
> +    };
> +
> +    osinfo_install_script_generate_for_media_async(script,
> +                                                   media,
> +                                                   config,
> +                                                   cancellable,
> +                                                   osinfo_install_script_generate_for_media_done,
> +                                                   &data);
> +
> +    if (g_main_loop_is_running(loop))
> +        g_main_loop_run(loop);
> +
> +    if (data.error)
> +        g_propagate_error(error, data.error);
> +
> +    g_main_loop_unref(loop);
> +
> +    return data.output;

Any reason not to have a generate_for_media_common helper here?

Looks good apart from these small details/questions.

Christophe

Attachment: pgp0182QGWAiu.pgp
Description: PGP signature

_______________________________________________
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