summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-07-01 21:08:24 +0100
committerRichard Hughes <richard@hughsie.com>2014-07-01 21:08:24 +0100
commitbbbf42549b835371f9dd1d6787716b746073a5da (patch)
treeb49d0ccef4dcaf9e0420ae3f6e23ecafe08dd31a
parent75e8ea254d71fc090a6ef81ee290ab30a0a33f22 (diff)
downloadappstream-glib-bbbf42549b835371f9dd1d6787716b746073a5da.tar.gz
Add a 'status-csv' command to appstream-util
This is needed by Ryan and will grow in functionality in the future.
-rw-r--r--client/as-util.c70
-rw-r--r--data/appstream-util2
2 files changed, 71 insertions, 1 deletions
diff --git a/client/as-util.c b/client/as-util.c
index 02c63b5..36a3d88 100644
--- a/client/as-util.c
+++ b/client/as-util.c
@@ -1385,6 +1385,70 @@ as_util_status_html (AsUtilPrivate *priv, gchar **values, GError **error)
}
/**
+ * as_util_status_csv:
+ **/
+static gboolean
+as_util_status_csv (AsUtilPrivate *priv, gchar **values, GError **error)
+{
+ AsApp *app;
+ GPtrArray *apps = NULL;
+ guint i;
+ _cleanup_object_unref_ AsStore *store = NULL;
+ _cleanup_object_unref_ GFile *file = NULL;
+ _cleanup_string_free_ GString *data = NULL;
+
+ /* check args */
+ if (g_strv_length (values) != 1) {
+ g_set_error_literal (error,
+ AS_ERROR,
+ AS_ERROR_INVALID_ARGUMENTS,
+ "Not enough arguments, "
+ "expected filename.xml.gz");
+ return FALSE;
+ }
+
+ /* load file */
+ store = as_store_new ();
+ file = g_file_new_for_path (values[0]);
+ if (!as_store_from_file (store, file, NULL, NULL, error))
+ return FALSE;
+ apps = as_store_get_apps (store);
+
+ /* write applications */
+ data = g_string_new ("id,pkgname,name,comment,description,url\n");
+ for (i = 0; i < apps->len; i++) {
+ _cleanup_free_ gchar *description = NULL;
+ app = g_ptr_array_index (apps, i);
+ if (as_app_get_id_kind (app) == AS_ID_KIND_FONT)
+ continue;
+ if (as_app_get_id_kind (app) == AS_ID_KIND_INPUT_METHOD)
+ continue;
+ if (as_app_get_id_kind (app) == AS_ID_KIND_CODEC)
+ continue;
+ if (as_app_get_id_kind (app) == AS_ID_KIND_SOURCE)
+ continue;
+ g_string_append_printf (data, "%s,", as_app_get_id (app));
+ g_string_append_printf (data, "%s,", as_app_get_pkgname_default (app));
+ g_string_append_printf (data, "\"%s\",", as_app_get_name (app, "C"));
+ g_string_append_printf (data, "\"%s\",", as_app_get_comment (app, "C"));
+ description = g_strdup (as_app_get_description (app, "C"));
+ if (description != NULL) {
+ g_strdelimit (description, "\n", '|');
+ g_strdelimit (description, "\"", '\'');
+ }
+ g_string_append_printf (data, "\"%s\",", description);
+ g_string_append_printf (data, "\"%s\",", as_app_get_url_item (app, AS_URL_KIND_HOMEPAGE));
+ g_string_truncate (data, data->len - 1);
+ g_string_append (data, "\n");
+ }
+
+ /* save file */
+ if (!g_file_set_contents ("./status.csv", data->str, -1, error))
+ return FALSE;
+ return TRUE;
+}
+
+/**
* as_util_non_package_yaml:
**/
static gboolean
@@ -1731,6 +1795,12 @@ main (int argc, char *argv[])
_("Create an HTML status page"),
as_util_status_html);
as_util_add (priv->cmd_array,
+ "status-csv",
+ NULL,
+ /* TRANSLATORS: command description */
+ _("Create an CSV status document"),
+ as_util_status_csv);
+ as_util_add (priv->cmd_array,
"non-package-yaml",
NULL,
/* TRANSLATORS: command description */
diff --git a/data/appstream-util b/data/appstream-util
index 4408b32..64a9762 100644
--- a/data/appstream-util
+++ b/data/appstream-util
@@ -62,7 +62,7 @@ _appstream-util()
upgrade)
ext='@(appdata.xml?(.in))'
;;
- non-package-yaml|status-html)
+ non-package-yaml|status-html|status-csv)
ext='@(xml.gz)'
;;
appdata-from-desktop)