diff options
author | Richard Hughes <richard@hughsie.com> | 2016-03-28 13:34:31 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-03-28 13:34:31 +0100 |
commit | b93a7bfb005a24dd86023ef3c550938eedd53f25 (patch) | |
tree | 76e6546c95f83da4d448e483e6daece73a206c42 | |
parent | ad0a71f4fe0799d5ed71db6e9cc917a0d0e1faf3 (diff) | |
download | appstream-glib-b93a7bfb005a24dd86023ef3c550938eedd53f25.tar.gz |
Add a merge-appstream command to appstream-util
This allows us to merge multiple source AppStream files into a new file.
-rw-r--r-- | client/as-util.c | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/client/as-util.c b/client/as-util.c index 4f07256..18976bb 100644 --- a/client/as-util.c +++ b/client/as-util.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2014 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2014-2016 Richard Hughes <richard@hughsie.com> * * Licensed under the GNU General Public License Version 2 * @@ -3461,6 +3461,61 @@ as_util_pad_strings (const gchar *id, const gchar *msg, guint align) } /** + * as_util_merge_appstream: + **/ +static gboolean +as_util_merge_appstream (AsUtilPrivate *priv, gchar **values, GError **error) +{ + guint i, j; + g_autoptr(GFile) file_new = NULL; + g_autoptr(AsStore) store_new = NULL; + + /* check args */ + if (g_strv_length (values) < 2) { + g_set_error_literal (error, + AS_ERROR, + AS_ERROR_INVALID_ARGUMENTS, + "Not enough arguments, expected: output.xml source1.xml ..."); + return FALSE; + } + + /* load each source store and add to master store */ + store_new = as_store_new (); + as_store_set_api_version (store_new, 0.9); + for (j = 1; values[j] != NULL; j++) { + GPtrArray *apps; + g_autoptr(GFile) file = NULL; + g_autoptr(AsStore) store = NULL; + + file = g_file_new_for_path (values[j]); + store = as_store_new (); + if (!as_store_from_file (store, file, NULL, NULL, error)) + return FALSE; + apps = as_store_get_apps (store); + for (i = 0; i < apps->len; i++) { + AsApp *app = g_ptr_array_index (apps, i); + as_store_add_app (store_new, app); + } + + /* adopt the origin from the first source */ + if (j == 1) { + as_store_set_origin (store_new, + as_store_get_origin (store)); + } + } + + /* save new store */ + file_new = g_file_new_for_path (values[0]); + if (!as_store_to_file (store_new, file_new, + AS_NODE_TO_XML_FLAG_ADD_HEADER | + AS_NODE_TO_XML_FLAG_FORMAT_INDENT | + AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE, + NULL, error)) + return FALSE; + return TRUE; +} + +/** * as_util_split_appstream: **/ static gboolean @@ -4125,6 +4180,12 @@ main (int argc, char *argv[]) _("Split an AppStream file to AppData and Metainfo files"), as_util_split_appstream); as_util_add (priv->cmd_array, + "merge-appstream", + NULL, + /* TRANSLATORS: command description */ + _("Merge several files to an AppStream file"), + as_util_merge_appstream); + as_util_add (priv->cmd_array, "markup-import", NULL, /* TRANSLATORS: command description */ |