[Libosinfo] [PATCH 02/10] Add osinfo_install_script_generate_for_media*()

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue May 12 12:55:45 UTC 2015


On Tue, May 12, 2015 at 12:31 PM, Christophe Fergeau
<cfergeau at redhat.com> wrote:
> 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"

Yeah, I just copied the existing error handers around it.

>> +/**
>> + * 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?

Just that it wasn't a lot of code so I was being lazy. :)

-- 
Regards,

Zeeshan Ali (Khattak)
________________________________________
Befriend GNOME: http://www.gnome.org/friends/




More information about the Libosinfo mailing list