Skip to content

Commit 4939077

Browse files
mmathesiussgallagher
authored andcommitted
Enable Modulemd.read_packager_file/string() to specify module and stream name overrides
Signed-off-by: Merlin Mathesius <[email protected]>
1 parent b2a2393 commit 4939077

File tree

3 files changed

+289
-3
lines changed

3 files changed

+289
-3
lines changed

modulemd/include/modulemd-2.0/modulemd.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,33 @@ modulemd_read_packager_file (const gchar *yaml_path,
361361
GObject **object,
362362
GError **error);
363363

364+
/**
365+
* modulemd_read_packager_file_ext:
366+
* @yaml_path: (in): A path to a YAML file containing a packager document.
367+
* @object: (out): (transfer full): A newly allocated #ModulemdModuleStreamV2 or
368+
* #ModulemdPackagerV3 object initialized with the content from @yaml_path.
369+
* @module_name: (in) (nullable): An optional module name to override the
370+
* document on disk. Mostly useful in cases where the name is being
371+
* auto-detected from git.
372+
* @module_stream: (in) (nullable): An optional module stream name to override
373+
* the document on disk. Mostly useful in cases where the name is being
374+
* auto-detected from git.
375+
* @error: (out): A #GError containing additional information if this function
376+
* fails in a way that prevents program continuation.
377+
*
378+
* Returns: @MODULEMD_TYPE_MODULE_STREAM_V2, @MODULEMD_TYPE_PACKAGER_V3, or
379+
* @G_TYPE_INVALID. Returns the matching GObject through the @object parameter.
380+
* If the return value is @G_TYPE_INVALID, returns the reason as @error.
381+
*
382+
* Since: 2.11
383+
*/
384+
GType
385+
modulemd_read_packager_file_ext (const gchar *yaml_path,
386+
GObject **object,
387+
const gchar *module_name,
388+
const gchar *module_stream,
389+
GError **error);
390+
364391
/**
365392
* modulemd_read_packager_string:
366393
* @yaml_string: (in): A YAML string containing a packager document.
@@ -380,4 +407,31 @@ modulemd_read_packager_string (const gchar *yaml_string,
380407
GObject **object,
381408
GError **error);
382409

410+
/**
411+
* modulemd_read_packager_string_ext:
412+
* @yaml_string: (in): A YAML string containing a packager document.
413+
* @object: (out): (transfer full): A newly allocated #ModulemdModuleStreamV2 or
414+
* #ModulemdPackagerV3 object initialized with the content from @yaml_string.
415+
* @module_name: (in) (nullable): An optional module name to override the
416+
* document on disk. Mostly useful in cases where the name is being
417+
* auto-detected from git.
418+
* @module_stream: (in) (nullable): An optional module stream name to override
419+
* the document on disk. Mostly useful in cases where the name is being
420+
* auto-detected from git.
421+
* @error: (out): A #GError containing additional information if this function
422+
* fails in a way that prevents program continuation.
423+
*
424+
* Returns: @MODULEMD_TYPE_MODULE_STREAM_V2, @MODULEMD_TYPE_PACKAGER_V3, or
425+
* @G_TYPE_INVALID. Returns the matching GObject through the @object parameter.
426+
* If the return value is @G_TYPE_INVALID, returns the reason as @error.
427+
*
428+
* Since: 2.11
429+
*/
430+
GType
431+
modulemd_read_packager_string_ext (const gchar *yaml_string,
432+
GObject **object,
433+
const gchar *module_name,
434+
const gchar *module_stream,
435+
GError **error);
436+
383437
G_END_DECLS

modulemd/modulemd.c

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,25 @@ verify_load (gboolean ret,
111111
static GType
112112
modulemd_read_packager_from_parser (yaml_parser_t *parser,
113113
GObject **object,
114+
const gchar *module_name,
115+
const gchar *module_stream,
114116
GError **error);
115117

116118
GType
117119
modulemd_read_packager_file (const gchar *yaml_path,
118120
GObject **object,
119121
GError **error)
122+
{
123+
return modulemd_read_packager_file_ext (
124+
yaml_path, object, NULL, NULL, error);
125+
}
126+
127+
GType
128+
modulemd_read_packager_file_ext (const gchar *yaml_path,
129+
GObject **object,
130+
const gchar *module_name,
131+
const gchar *module_stream,
132+
GError **error)
120133
{
121134
MMD_INIT_YAML_PARSER (parser);
122135
g_autoptr (FILE) yaml_stream = NULL;
@@ -142,13 +155,25 @@ modulemd_read_packager_file (const gchar *yaml_path,
142155

143156
yaml_parser_set_input_file (&parser, yaml_stream);
144157

145-
return modulemd_read_packager_from_parser (&parser, object, error);
158+
return modulemd_read_packager_from_parser (
159+
&parser, object, module_name, module_stream, error);
146160
}
147161

148162
GType
149163
modulemd_read_packager_string (const gchar *yaml_string,
150164
GObject **object,
151165
GError **error)
166+
{
167+
return modulemd_read_packager_string_ext (
168+
yaml_string, object, NULL, NULL, error);
169+
}
170+
171+
GType
172+
modulemd_read_packager_string_ext (const gchar *yaml_string,
173+
GObject **object,
174+
const gchar *module_name,
175+
const gchar *module_stream,
176+
GError **error)
152177
{
153178
MMD_INIT_YAML_PARSER (parser);
154179

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

162-
return modulemd_read_packager_from_parser (&parser, object, error);
187+
return modulemd_read_packager_from_parser (
188+
&parser, object, module_name, module_stream, error);
163189
}
164190

165191
static GType
166192
modulemd_read_packager_from_parser (yaml_parser_t *parser,
167193
GObject **object,
194+
const gchar *module_name,
195+
const gchar *module_stream,
168196
GError **error)
169197
{
170198
MMD_INIT_YAML_EVENT (event);
@@ -252,6 +280,17 @@ modulemd_read_packager_from_parser (yaml_parser_t *parser,
252280
return G_TYPE_INVALID;
253281
}
254282

283+
if (module_name)
284+
{
285+
modulemd_packager_v3_set_module_name (packager_v3, module_name);
286+
}
287+
288+
if (module_stream)
289+
{
290+
modulemd_packager_v3_set_stream_name (packager_v3,
291+
module_stream);
292+
}
293+
255294
return_object = (GObject *)g_steal_pointer (&packager_v3);
256295
return_type = MODULEMD_TYPE_PACKAGER_V3;
257296
break;
@@ -285,6 +324,18 @@ modulemd_read_packager_from_parser (yaml_parser_t *parser,
285324
return G_TYPE_INVALID;
286325
}
287326

327+
if (module_name)
328+
{
329+
modulemd_module_stream_set_module_name (
330+
MODULEMD_MODULE_STREAM (stream_v2), module_name);
331+
}
332+
333+
if (module_stream)
334+
{
335+
modulemd_module_stream_set_stream_name (
336+
MODULEMD_MODULE_STREAM (stream_v2), module_stream);
337+
}
338+
288339
return_object = (GObject *)g_steal_pointer (&stream_v2);
289340
return_type = MODULEMD_TYPE_MODULE_STREAM_V2;
290341
break;
@@ -297,6 +348,18 @@ modulemd_read_packager_from_parser (yaml_parser_t *parser,
297348
return G_TYPE_INVALID;
298349
}
299350

351+
if (module_name)
352+
{
353+
modulemd_module_stream_set_module_name (
354+
MODULEMD_MODULE_STREAM (stream_v2), module_name);
355+
}
356+
357+
if (module_stream)
358+
{
359+
modulemd_module_stream_set_stream_name (
360+
MODULEMD_MODULE_STREAM (stream_v2), module_stream);
361+
}
362+
300363
return_object = (GObject *)g_steal_pointer (&stream_v2);
301364
return_type = MODULEMD_TYPE_MODULE_STREAM_V2;
302365
break;

0 commit comments

Comments
 (0)