tracker r2067 - in branches/indexer-split: . src/tracker-utils
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2067 - in branches/indexer-split: . src/tracker-utils
- Date: Wed, 13 Aug 2008 11:53:08 +0000 (UTC)
Author: mr
Date: Wed Aug 13 11:53:08 2008
New Revision: 2067
URL: http://svn.gnome.org/viewvc/tracker?rev=2067&view=rev
Log:
* src/tracker-utils/Makefile.am: Added GLib and GIO to the CFLAGS
and LDFLAGS.
* src/tracker-utils/tracker-tag.c: Refactored, fixed bugs, etc.
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/tracker-utils/Makefile.am
branches/indexer-split/src/tracker-utils/tracker-tag.c
Modified: branches/indexer-split/src/tracker-utils/Makefile.am
==============================================================================
--- branches/indexer-split/src/tracker-utils/Makefile.am (original)
+++ branches/indexer-split/src/tracker-utils/Makefile.am Wed Aug 13 11:53:08 2008
@@ -1,41 +1,47 @@
-INCLUDES = \
- -g \
- -DLOCALEDIR=\""$(localedir)"\" \
- -DG_LOG_DOMAIN=\"Tracker\" \
- -I$(top_srcdir)/src \
- $(DBUS_CFLAGS) \
+INCLUDES = \
+ -g \
+ -DLOCALEDIR=\""$(localedir)"\" \
+ -DG_LOG_DOMAIN=\"Tracker\" \
+ -I$(top_srcdir)/src \
+ $(DBUS_CFLAGS) \
+ $(GIO_CFLAGS) \
$(GLIB2_CFLAGS)
-bin_PROGRAMS = \
- tracker-search \
- tracker-query \
- tracker-meta-folder \
- tracker-stats \
- tracker-tag \
- tracker-files \
- tracker-status \
+libs = \
+ $(top_builddir)/src/libtracker/libtrackerclient.la \
+ $(GIO_LIBS) \
+ $(GLIB2_LIBS)
+
+bin_PROGRAMS = \
+ tracker-search \
+ tracker-query \
+ tracker-meta-folder \
+ tracker-stats \
+ tracker-tag \
+ tracker-files \
+ tracker-status \
tracker-unique
tracker_search_SOURCES = tracker-search.c
-tracker_search_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+tracker_search_LDADD = $(libs)
tracker_query_SOURCES = tracker-query.c
-tracker_query_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+tracker_query_LDADD = $(libs)
tracker_meta_folder_SOURCES = tracker-meta-folder.c
-tracker_meta_folder_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+tracker_meta_folder_LDADD = $(libs)
tracker_stats_SOURCES = tracker-stats.c
-tracker_stats_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+tracker_stats_LDADD = $(libs)
tracker_tag_SOURCES = tracker-tag.c
-tracker_tag_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+tracker_tag_LDADD = $(libs)
tracker_files_SOURCES = tracker-files.c
-tracker_files_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+tracker_files_LDADD = $(libs)
tracker_status_SOURCES = tracker-status.c
-tracker_status_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+tracker_status_LDADD = $(libs)
tracker_unique_SOURCES = tracker-unique.c
-tracker_unique_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+tracker_unique_LDADD = $(libs)
Modified: branches/indexer-split/src/tracker-utils/tracker-tag.c
==============================================================================
--- branches/indexer-split/src/tracker-utils/tracker-tag.c (original)
+++ branches/indexer-split/src/tracker-utils/tracker-tag.c Wed Aug 13 11:53:08 2008
@@ -27,6 +27,7 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <libtracker/tracker.h>
@@ -34,60 +35,85 @@
#include <trackerd/mingw-compat.h>
#endif /* G_OS_WIN32 */
-static gint limit = 512;
-static gint offset = 0;
-static gchar **add = NULL;
-static gchar **delete = NULL;
-static gchar **search = NULL;
-static gchar **files = NULL;
-static gboolean remove_all = FALSE;
-static gboolean list = FALSE;
+static gint limit = 512;
+static gint offset;
+static gchar **add;
+static gchar **remove;
+static gchar **search;
+static gchar **files;
+static gboolean remove_all;
+static gboolean list;
static GOptionEntry entries[] = {
- { "add", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &add, N_("Add specified tag to a file"), N_("TAG")},
- { "remove", 'r', 0, G_OPTION_ARG_STRING_ARRAY, &delete, N_("Remove specified tag from a file"), N_("TAG")},
- { "remove-all", 'R', 0, G_OPTION_ARG_NONE, &remove_all, N_("Remove all tags from a file"), NULL},
- { "list", 'l', 0, G_OPTION_ARG_NONE, &list, N_("List all defined tags"), NULL},
- { "limit", 'l', 0, G_OPTION_ARG_INT, &limit, N_("Limit the number of results showed to N"), N_("512") },
- { "offset", 'o', 0, G_OPTION_ARG_INT, &offset, N_("Offset the results at O"), N_("0") },
- { "search", 's', 0, G_OPTION_ARG_STRING_ARRAY, &search, N_("Search for files with specified tag"), N_("TAG")},
- { G_OPTION_REMAINING, 0, G_OPTION_FLAG_FILENAME, G_OPTION_ARG_STRING_ARRAY, &files, N_("FILE..."), NULL},
+ { "add", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &add,
+ N_("Add specified tag to a file"),
+ N_("TAG")
+ },
+ { "remove", 'r', 0, G_OPTION_ARG_STRING_ARRAY, &remove,
+ N_("Remove specified tag from a file"),
+ N_("TAG")
+ },
+ { "remove-all", 'R', 0, G_OPTION_ARG_NONE, &remove_all,
+ N_("Remove all tags from a file"),
+ NULL
+ },
+ { "list", 't', 0, G_OPTION_ARG_NONE, &list,
+ N_("List all defined tags"),
+ NULL
+ },
+ { "limit", 'l', 0, G_OPTION_ARG_INT, &limit,
+ N_("Limit the number of results shown"),
+ N_("512")
+ },
+ { "offset", 'o', 0, G_OPTION_ARG_INT, &offset,
+ N_("Offset the results"),
+ N_("0")
+ },
+ { "search", 's', 0, G_OPTION_ARG_STRING_ARRAY, &search,
+ N_("Search for files with specified tag"),
+ N_("TAG")
+ },
+ { G_OPTION_REMAINING, 0,
+ G_OPTION_FLAG_FILENAME, G_OPTION_ARG_STRING_ARRAY, &files,
+ N_("FILE..."),
+ NULL},
{ NULL }
};
-
static void
get_meta_table_data (gpointer value)
-
{
- char **meta, **meta_p;
-
- meta = (char **)value;
+ gchar **meta;
+ gchar **p;
+ gint i;
- int i = 0;
- for (meta_p = meta; *meta_p; meta_p++) {
+ meta = value;
+ for (p = meta, i = 0; *p; p++, i++) {
if (i == 0) {
- g_print ("%s : ", *meta_p);
-
+ g_print (" %s", *p);
} else {
- g_print ("%s ", *meta_p);
+ g_print (", %s", *p);
}
- i++;
}
+
g_print ("\n");
}
int
main (int argc, char **argv)
{
- TrackerClient *client;
- GOptionContext *context;
- GError *error = NULL;
- gchar *example;
- gchar *summary;
- gint i = 0;
- gint k;
+ TrackerClient *client;
+ GOptionContext *context;
+ GError *error = NULL;
+ const gchar *failed = NULL;
+ gchar *summary;
+ gchar **files_resolved = NULL;
+ gchar **search_resolved = NULL;
+ gchar **tags_to_add = NULL;
+ gchar **tags_to_remove = NULL;
+ gchar *error_str = NULL;
+ gint i, j;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -96,213 +122,283 @@
/* Translators: this messagge will apper immediately after the
* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>
*/
- context = g_option_context_new (_("FILE... - manipulate tags on files"));
- example = g_strconcat ( "-a ", _("TAG"),
- " -a ", _("TAG"),
- " -a ", _("TAG"),
- NULL);
+ context = g_option_context_new (_("Add, remove or search for tags"));
/* Translators: this message will appear after the usage string
* and before the list of options, showing an usage example.
*/
summary = g_strconcat (_("To add, remove, or search for multiple tags "
- "at the same time, join multiple options like:"),
- "\n\n\t",
- example,
+ "at the same time, join multiple options, for example:"),
+ "\n"
+ "\n"
+ " -a ", _("TAG"), " -a ", _("TAG"), " -a ", _("TAG"),
NULL);
g_option_context_set_summary (context, summary);
g_option_context_add_main_entries (context, entries, NULL);
- g_option_context_parse (context, &argc, &argv, &error);
- g_option_context_free (context);
+ g_option_context_parse (context, &argc, &argv, NULL);
g_free (summary);
- g_free (example);
- if (error) {
- g_printerr ("%s: %s", argv[0], error->message);
- g_printerr ("\n");
- g_printerr (_("Try \"%s --help\" for more information."), argv[0]);
- g_printerr ("\n");
- return EXIT_FAILURE;
- }
+ /* Check arguments */
+ if ((add || remove || remove_all) && !files) {
+ failed = _("No files were specified");
+ } else if ((add || remove) && remove_all) {
+ failed = _("Add and delete actions can not be used with remove all actions");
+ } else if (search && files) {
+ failed = _("Files are not needed with searching");
+ } else if (!add && !remove && !remove_all && !files && !search && !list) {
+ failed = _("No arguments were provided");
+ }
+
+ if (failed) {
+ gchar *help;
+
+ g_printerr ("%s\n\n", failed);
+
+ help = g_option_context_get_help (context, TRUE, NULL);
+ g_option_context_free (context);
+ g_printerr (help);
+ g_free (help);
- if (((add || delete || remove_all) && !files) || (remove_all && (add || delete)) || (search && files)) {
- g_printerr (_("%s: invalid arguments"), argv[0]);
- g_printerr ("\n");
- g_printerr (_("Try \"%s --help\" for more information."), argv[0]);
- g_printerr ("\n");
- return EXIT_FAILURE;
- }
+ return EXIT_FAILURE;
+ }
+ g_option_context_free (context);
client = tracker_connect (FALSE);
if (!client) {
- g_printerr (_("%s: no connection to tracker daemon"), argv[0]);
- g_printerr ("\n");
- g_printerr (_("Ensure \"trackerd\" is running before launch this command."));
- g_printerr ("\n");
+ g_printerr ("%s\n",
+ _("Could not establish a DBus connection to Tracker"));
return EXIT_FAILURE;
}
-
if (files) {
- for (i = 0; files[i] != NULL; i++) {
- char resolved_path[1024];
- gchar *tmp = realpath (files[i], resolved_path);
- if (tmp) {
- g_free (files[i]);
- files[i] = g_strdup (tmp);
- } else {
- g_printerr (_("%s: file %s not found"), argv[0], files[i]);
- g_printerr ("\n");
- for (k = i; files[k] != NULL; k++)
- files[k] = files[k+1];
- i--; // Make sure we run over this file again
- }
+ /* gchar *path; */
+
+ files_resolved = g_new0 (gchar*, g_strv_length (files) + 1);
+
+ for (i = 0, j = 0; files[i] != NULL; i++) {
+ /* GFile *file; */
+
+ /* file = g_file_new_for_commandline_arg (files[i]); */
+ /* path = g_file_get_path (file); */
+ /* g_object_unref (file); */
+
+ files_resolved[j++] = g_strdup (files[i]);
}
- }
- if (add || delete || remove_all) {
+ files_resolved[j] = NULL;
+ }
- if (add)
- for (i = 0; add[i] != NULL; i++) {
- gchar *tmp = g_locale_to_utf8 (add[i], -1, NULL, NULL, NULL);
- g_free (add[i]);
- add[i] = tmp;
+ if (add || remove || remove_all) {
+ if (add) {
+ tags_to_add = g_new0 (gchar*, g_strv_length (add) + 1);
+
+ for (i = 0, j = 0; add[i] != NULL; i++) {
+ gchar *path;
+
+ path = g_locale_to_utf8 (add[i], -1, NULL, NULL, NULL);
+ if (path) {
+ tags_to_add[j++] = path;
+ }
}
+ }
- if (delete)
- for (i = 0; delete[i] != NULL; i++) {
- gchar *tmp = g_locale_to_utf8 (delete[i], -1, NULL, NULL, NULL);
- g_free (delete[i]);
- delete[i] = tmp;
+ if (remove) {
+ tags_to_remove = g_new0 (gchar*, g_strv_length (remove) + 1);
+
+ for (i = 0, j = 0; remove[i] != NULL; i++) {
+ gchar *path;
+
+ path = g_locale_to_utf8 (remove[i], -1, NULL, NULL, NULL);
+ if (path) {
+ tags_to_remove[j++] = path;
+ }
}
+ }
- for (i = 0; files[i] != NULL; i++) {
+ for (i = 0; files_resolved[i] != NULL; i++) {
if (remove_all) {
- tracker_keywords_remove_all (client, SERVICE_FILES, files[i], &error);
+ tracker_keywords_remove_all (client,
+ SERVICE_FILES,
+ files_resolved[i],
+ &error);
if (error) {
- g_printerr (_("%s: internal tracker error: %s"), argv[0], error->message);
- g_printerr ("\n");
+ gchar *str;
+
+ str = g_strdup_printf (_("Could not remove all tags for '%s'"),
+ files_resolved[i]);
+ g_printerr ("%s, %s\n",
+ str,
+ error->message);
+ g_free (str);
+ g_clear_error (&error);
}
}
- if (add) {
- tracker_keywords_add (client, SERVICE_FILES, files[i], add, &error);
+ if (tags_to_add) {
+ tracker_keywords_add (client,
+ SERVICE_FILES,
+ files_resolved[i],
+ tags_to_add,
+ &error);
if (error) {
- g_printerr (_("%s: internal tracker error: %s"), argv[0], error->message);
- g_printerr ("\n");
+ gchar *str;
+
+ str = g_strdup_printf (_("Could not add tags for '%s'"),
+ files_resolved[i]);
+ g_printerr ("%s, %s\n",
+ str,
+ error->message);
+ g_free (str);
+ g_clear_error (&error);
}
}
- if (delete) {
- tracker_keywords_remove (client, SERVICE_FILES, files[i], delete, &error);
+ if (tags_to_remove) {
+ tracker_keywords_remove (client,
+ SERVICE_FILES,
+ files_resolved[i],
+ tags_to_remove,
+ &error);
if (error) {
- g_printerr (_("%s: internal tracker error: %s"), argv[0], error->message);
- g_printerr ("\n");
- }
- }
+ gchar *str;
+ str = g_strdup_printf (_("Could not remove tags for '%s'"),
+ files_resolved[i]);
+ g_printerr ("%s, %s\n",
+ str,
+ error->message);
+ g_free (str);
+ g_clear_error (&error);
+ }
+ }
}
-
}
- if (((list && !files) || (!files && (!remove_all && !delete && !add))) && !search) {
- GPtrArray *out_array = NULL;
-
- out_array = tracker_keywords_get_list (client, SERVICE_FILES, &error);
-
- if (error) {
- goto error;
- }
-
- if (out_array) {
- g_ptr_array_foreach (out_array, (GFunc)get_meta_table_data, NULL);
- g_ptr_array_free (out_array, TRUE);
- }
-
+ if (((!files && list) ||
+ (!files && (!add && !remove && !remove_all))) && !search) {
+ GPtrArray *array;
+
+ array = tracker_keywords_get_list (client,
+ SERVICE_FILES,
+ &error);
+
+ if (error) {
+ error_str = g_strdup (_("Could not get tag list"));
+ goto finish;
+ }
+
+ if (!array) {
+ g_print ("%s\n",
+ _("No tags found"));
+ } else {
+ g_print ("%s\n",
+ _("All tags:"));
+
+ g_ptr_array_foreach (array, (GFunc) get_meta_table_data, NULL);
+ g_ptr_array_free (array, TRUE);
+ }
}
- if ((list && files) || (files && (!remove_all && !delete && !add))) {
-
- int i = 0;
-
- for (i = 0; files[i] != NULL; i++) {
-
- int j = 0;
- gchar **tags = tracker_keywords_get (client,
- SERVICE_FILES,
- files[i],
- &error);
+ if ((files && list) ||
+ (files && (!add && !remove && !remove_all))) {
+ g_print ("%s\n",
+ _("Tags found:"));
+
+ for (i = 0, j = 0; files_resolved[i] != NULL; i++) {
+ gchar **tags;
+
+ tags = tracker_keywords_get (client,
+ SERVICE_FILES,
+ files_resolved[i],
+ &error);
if (error) {
- g_printerr (_("%s: internal tracker error: %s"),
- argv[0],
- error->message);
- g_printerr ("\n");
+ error_str = g_strdup_printf (_("Could not get tags for file:'%s'"),
+ files_resolved[i]);
+ goto finish;
}
- if (!tags)
+ if (!tags) {
continue;
+ }
+
+ g_print (" '%s': ", files_resolved[i]);
+
+ for (j = 0; tags[j] != NULL; j++) {
+ if (j > 0) {
+ g_print ("|");
+ }
+
+ g_print ("%s", tags[j]);
+ }
- g_print ("%s:", files[i]);
- for (j = 0; tags[j] != NULL; j++)
- g_print (" %s", tags[j]);
g_print ("\n");
g_strfreev (tags);
-
}
-
}
if (search) {
- int i = 0;
gchar **results;
- for (i = 0; search[i] != NULL; i++) {
- gchar *tmp = g_locale_to_utf8 (search[i],
- -1,
- NULL,
- NULL,
- NULL);
- g_free (search[i]);
- search[i] = tmp;
+ search_resolved = g_new0 (gchar*, g_strv_length (search) + 1);
+
+ for (i = 0, j = 0; search[i] != NULL; i++) {
+ gchar *str;
+
+ str = g_locale_to_utf8 (search[i], -1, NULL, NULL, NULL);
+ search_resolved[j++] = str;
}
+ search_resolved[j] = NULL;
+
results = tracker_keywords_search (client, -1,
SERVICE_FILES,
- search,
+ search_resolved,
offset,
limit,
&error);
- if (error)
- goto error;
+ if (error) {
+ error_str = g_strdup (_("Could not search tags"));
+ goto finish;
+ }
if (!results) {
- /* FIXME!! coreutilus don't print anything on no-results */
- g_print (_("No results found matching your query"));
- g_print ("\n");
- }
- else
- for (i = 0; results[i] != NULL; i++)
- g_print ("%s\n", results[i]);
+ g_print ("%s\n",
+ _("No tags found"));
+ } else {
+ for (i = 0; results[i] != NULL; i++) {
+ g_print (" %s\n", results[i]);
+ }
+ }
g_strfreev (results);
-
}
- tracker_disconnect (client);
- return EXIT_SUCCESS;
-
-error:
- g_printerr (_("%s: internal tracker error: %s"), argv[0], error->message);
- g_printerr ("\n");
- tracker_disconnect (client);
- return EXIT_FAILURE;
+finish:
+ g_strfreev (tags_to_remove);
+ g_strfreev (tags_to_add);
+ g_strfreev (search_resolved);
+ g_strfreev (files_resolved);
+
+ tracker_disconnect (client);
+
+ if (error_str) {
+ g_printerr ("%s, %s\n",
+ error_str,
+ error->message);
+ g_free (error_str);
+ g_clear_error (&error);
+
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]