Skip to content

Commit

Permalink
Enable Modulemd.read_packager_file/string() to specify module and str…
Browse files Browse the repository at this point in the history
…eam name overrides

Signed-off-by: Merlin Mathesius <[email protected]>
  • Loading branch information
mmathesius authored and sgallagher committed Jan 5, 2021
1 parent b2a2393 commit 4939077
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 3 deletions.
54 changes: 54 additions & 0 deletions modulemd/include/modulemd-2.0/modulemd.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,33 @@ modulemd_read_packager_file (const gchar *yaml_path,
GObject **object,
GError **error);

/**
* modulemd_read_packager_file_ext:
* @yaml_path: (in): A path to a YAML file containing a packager document.
* @object: (out): (transfer full): A newly allocated #ModulemdModuleStreamV2 or
* #ModulemdPackagerV3 object initialized with the content from @yaml_path.
* @module_name: (in) (nullable): An optional module name to override the
* document on disk. Mostly useful in cases where the name is being
* auto-detected from git.
* @module_stream: (in) (nullable): An optional module stream name to override
* the document on disk. Mostly useful in cases where the name is being
* auto-detected from git.
* @error: (out): A #GError containing additional information if this function
* fails in a way that prevents program continuation.
*
* Returns: @MODULEMD_TYPE_MODULE_STREAM_V2, @MODULEMD_TYPE_PACKAGER_V3, or
* @G_TYPE_INVALID. Returns the matching GObject through the @object parameter.
* If the return value is @G_TYPE_INVALID, returns the reason as @error.
*
* Since: 2.11
*/
GType
modulemd_read_packager_file_ext (const gchar *yaml_path,
GObject **object,
const gchar *module_name,
const gchar *module_stream,
GError **error);

/**
* modulemd_read_packager_string:
* @yaml_string: (in): A YAML string containing a packager document.
Expand All @@ -380,4 +407,31 @@ modulemd_read_packager_string (const gchar *yaml_string,
GObject **object,
GError **error);

/**
* modulemd_read_packager_string_ext:
* @yaml_string: (in): A YAML string containing a packager document.
* @object: (out): (transfer full): A newly allocated #ModulemdModuleStreamV2 or
* #ModulemdPackagerV3 object initialized with the content from @yaml_string.
* @module_name: (in) (nullable): An optional module name to override the
* document on disk. Mostly useful in cases where the name is being
* auto-detected from git.
* @module_stream: (in) (nullable): An optional module stream name to override
* the document on disk. Mostly useful in cases where the name is being
* auto-detected from git.
* @error: (out): A #GError containing additional information if this function
* fails in a way that prevents program continuation.
*
* Returns: @MODULEMD_TYPE_MODULE_STREAM_V2, @MODULEMD_TYPE_PACKAGER_V3, or
* @G_TYPE_INVALID. Returns the matching GObject through the @object parameter.
* If the return value is @G_TYPE_INVALID, returns the reason as @error.
*
* Since: 2.11
*/
GType
modulemd_read_packager_string_ext (const gchar *yaml_string,
GObject **object,
const gchar *module_name,
const gchar *module_stream,
GError **error);

G_END_DECLS
67 changes: 65 additions & 2 deletions modulemd/modulemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,25 @@ verify_load (gboolean ret,
static GType
modulemd_read_packager_from_parser (yaml_parser_t *parser,
GObject **object,
const gchar *module_name,
const gchar *module_stream,
GError **error);

GType
modulemd_read_packager_file (const gchar *yaml_path,
GObject **object,
GError **error)
{
return modulemd_read_packager_file_ext (
yaml_path, object, NULL, NULL, error);
}

GType
modulemd_read_packager_file_ext (const gchar *yaml_path,
GObject **object,
const gchar *module_name,
const gchar *module_stream,
GError **error)
{
MMD_INIT_YAML_PARSER (parser);
g_autoptr (FILE) yaml_stream = NULL;
Expand All @@ -142,13 +155,25 @@ modulemd_read_packager_file (const gchar *yaml_path,

yaml_parser_set_input_file (&parser, yaml_stream);

return modulemd_read_packager_from_parser (&parser, object, error);
return modulemd_read_packager_from_parser (
&parser, object, module_name, module_stream, error);
}

GType
modulemd_read_packager_string (const gchar *yaml_string,
GObject **object,
GError **error)
{
return modulemd_read_packager_string_ext (
yaml_string, object, NULL, NULL, error);
}

GType
modulemd_read_packager_string_ext (const gchar *yaml_string,
GObject **object,
const gchar *module_name,
const gchar *module_stream,
GError **error)
{
MMD_INIT_YAML_PARSER (parser);

Expand All @@ -159,12 +184,15 @@ modulemd_read_packager_string (const gchar *yaml_string,
yaml_parser_set_input_string (
&parser, (const unsigned char *)yaml_string, strlen (yaml_string));

return modulemd_read_packager_from_parser (&parser, object, error);
return modulemd_read_packager_from_parser (
&parser, object, module_name, module_stream, error);
}

static GType
modulemd_read_packager_from_parser (yaml_parser_t *parser,
GObject **object,
const gchar *module_name,
const gchar *module_stream,
GError **error)
{
MMD_INIT_YAML_EVENT (event);
Expand Down Expand Up @@ -252,6 +280,17 @@ modulemd_read_packager_from_parser (yaml_parser_t *parser,
return G_TYPE_INVALID;
}

if (module_name)
{
modulemd_packager_v3_set_module_name (packager_v3, module_name);
}

if (module_stream)
{
modulemd_packager_v3_set_stream_name (packager_v3,
module_stream);
}

return_object = (GObject *)g_steal_pointer (&packager_v3);
return_type = MODULEMD_TYPE_PACKAGER_V3;
break;
Expand Down Expand Up @@ -285,6 +324,18 @@ modulemd_read_packager_from_parser (yaml_parser_t *parser,
return G_TYPE_INVALID;
}

if (module_name)
{
modulemd_module_stream_set_module_name (
MODULEMD_MODULE_STREAM (stream_v2), module_name);
}

if (module_stream)
{
modulemd_module_stream_set_stream_name (
MODULEMD_MODULE_STREAM (stream_v2), module_stream);
}

return_object = (GObject *)g_steal_pointer (&stream_v2);
return_type = MODULEMD_TYPE_MODULE_STREAM_V2;
break;
Expand All @@ -297,6 +348,18 @@ modulemd_read_packager_from_parser (yaml_parser_t *parser,
return G_TYPE_INVALID;
}

if (module_name)
{
modulemd_module_stream_set_module_name (
MODULEMD_MODULE_STREAM (stream_v2), module_name);
}

if (module_stream)
{
modulemd_module_stream_set_stream_name (
MODULEMD_MODULE_STREAM (stream_v2), module_stream);
}

return_object = (GObject *)g_steal_pointer (&stream_v2);
return_type = MODULEMD_TYPE_MODULE_STREAM_V2;
break;
Expand Down
Loading

0 comments on commit 4939077

Please sign in to comment.