Commit 41bd19a4 authored by Martyn Russell's avatar Martyn Russell

tracker-extract: Added --force-module option

This allows developers to force a particular module is used over all
the others available.
parent 86911d51
......@@ -21,9 +21,6 @@ will run for 30 seconds waiting for DBus calls before quitting.
.B \-?, \-\-help
Show summary of options.
.TP
.B \-V, \-\-version
Show binary version.
.TP
.B \-v, \-\-verbosity=N
Set verbosity to N. This overrides the config value.
Values include 0=errors, 1=minimal, 2=detailed and 3=debug.
......@@ -39,12 +36,41 @@ will be guessed automatically.
.B \-d, \-\-debug
Enable debug mode which will provide more information about what is
going on during the extraction.
.TP
.B \-i, \-\-force-internal-extractors
Use this option to force internal extractors over 3rd parties like
libstreamanalyzer.
.TP
.B \-m, \-\-force-module=MODULE
Force a particular module to be used. This is here as a convenience
for developers wanting to test their \fIMODULE\fR file. Only the
\fIMODULE\fR name has to be specified, not the full path. Typically, a
\fIMODULE\fR is installed to /usr/lib/tracker-0.7/extract-modules/.
This option can be used with or without the .so part of the name too,
for example, you can use
.B --force-module=foo
Modules are shared objects which are dynamically loaded at run time. These files
must have the .so suffix to be loaded and must contain the correct
symbols to be authenticated by
.B tracker-extract.
For more information see the libtracker-extract reference documentation.
.TP
.B \-V, \-\-version
Show binary version.
.SH EXAMPLES
.TP
Using tracker-extract from command line to extract metadata from one file:
.BR
$ echo -e "/x/y/z.mp3\\naudio/mpeg" | tracker-extract
Using command line to extract metadata from a file:
.BR
$ tracker-extract -v 3 -f /path/to/some/file.mp3
.TP
Using a specific module to extract metadata from a file:
.BR
$ tracker-extract -v 3 -f /path/to/some/file.mp3 -m mymodule
.SH FILES
.I $HOME/.config/tracker/tracker-extract.cfg
......@@ -56,3 +82,5 @@ $ echo -e "/x/y/z.mp3\\naudio/mpeg" | tracker-extract
.BR tracker-info (1).
.TP
.BR tracker-extract.cfg (5).
.TP
.BR /usr/lib/tracker-0.7/extract-modules/
......@@ -103,32 +103,45 @@ tracker_extract_finalize (GObject *object)
G_OBJECT_CLASS (tracker_extract_parent_class)->finalize (object);
}
TrackerExtract *
tracker_extract_new (gboolean disable_shutdown,
gboolean force_internal_extractors)
static gboolean
load_modules (const gchar *force_module,
GArray **specific_extractors,
GArray **generic_extractors)
{
TrackerExtract *object;
TrackerExtractPrivate *priv;
GDir *dir;
GError *error;
GError *error = NULL;
const gchar *name;
GArray *specific_extractors;
GArray *generic_extractors;
gchar *force_module_checked;
gboolean success;
if (!g_module_supported ()) {
g_error ("Modules are not supported for this platform");
return NULL;
}
error = NULL;
dir = g_dir_open (MODULESDIR, 0, &error);
if (!dir) {
g_error ("Error opening modules directory: %s", error->message);
g_error_free (error);
return NULL;
return FALSE;
}
if (G_UNLIKELY (force_module)) {
if (!g_str_has_suffix (force_module, "." G_MODULE_SUFFIX)) {
force_module_checked = g_strdup_printf ("%s.%s",
force_module,
G_MODULE_SUFFIX);
} else {
force_module_checked = g_strdup (force_module);
}
} else {
force_module_checked = NULL;
}
*specific_extractors = g_array_new (FALSE,
TRUE,
sizeof (ModuleData));
*generic_extractors = g_array_new (FALSE,
TRUE,
sizeof (ModuleData));
#ifdef HAVE_LIBSTREAMANALYZER
if (!force_internal_extractors) {
g_message ("Adding extractor for libstreamanalyzer");
......@@ -139,13 +152,6 @@ tracker_extract_new (gboolean disable_shutdown,
g_message (" It is available but disabled by command line");
}
#endif /* HAVE_STREAMANALYZER */
specific_extractors = g_array_new (FALSE,
TRUE,
sizeof (ModuleData));
generic_extractors = g_array_new (FALSE,
TRUE,
sizeof (ModuleData));
while ((name = g_dir_read_name (dir)) != NULL) {
TrackerExtractDataFunc func;
......@@ -156,6 +162,10 @@ tracker_extract_new (gboolean disable_shutdown,
continue;
}
if (force_module_checked && strcmp (name, force_module_checked) != 0) {
continue;
}
module_path = g_build_filename (MODULESDIR, name, NULL);
module = g_module_open (module_path, G_MODULE_BIND_LOCAL);
......@@ -183,11 +193,11 @@ tracker_extract_new (gboolean disable_shutdown,
if (G_UNLIKELY (strchr (mdata.edata->mime, '*') != NULL)) {
g_message (" Generic match for mime:'%s'",
mdata.edata->mime);
g_array_append_val (generic_extractors, mdata);
g_array_append_val (*generic_extractors, mdata);
} else {
g_message (" Specific match for mime:'%s'",
mdata.edata->mime);
g_array_append_val (specific_extractors, mdata);
g_array_append_val (*specific_extractors, mdata);
}
}
} else {
......@@ -198,8 +208,40 @@ tracker_extract_new (gboolean disable_shutdown,
g_free (module_path);
}
if (G_UNLIKELY (force_module) &&
(!*specific_extractors || (*specific_extractors)->len < 1) &&
(!*generic_extractors || (*generic_extractors)->len < 1)) {
g_warning ("Could not force module '%s', it was not found", force_module_checked);
success = FALSE;
} else {
success = TRUE;
}
g_free (force_module_checked);
g_dir_close (dir);
return success;
}
TrackerExtract *
tracker_extract_new (gboolean disable_shutdown,
gboolean force_internal_extractors,
const gchar *force_module)
{
TrackerExtract *object;
TrackerExtractPrivate *priv;
GArray *specific_extractors;
GArray *generic_extractors;
if (!g_module_supported ()) {
g_error ("Modules are not supported for this platform");
return NULL;
}
if (!load_modules (force_module, &specific_extractors, &generic_extractors)) {
return NULL;
}
/* Set extractors */
object = g_object_new (TRACKER_TYPE_EXTRACT, NULL);
......
......@@ -50,7 +50,8 @@ struct TrackerExtractClass {
GType tracker_extract_get_type (void);
TrackerExtract *tracker_extract_new (gboolean disable_shutdown,
gboolean force_internal_extractors);
gboolean force_internal_extractors,
const gchar *force_module);
void tracker_extract_get_pid (TrackerExtract *object,
DBusGMethodInvocation *context,
GError **error);
......
......@@ -65,23 +65,20 @@
#define QUIT_TIMEOUT 30 /* 1/2 minutes worth of seconds */
static GMainLoop *main_loop;
static guint quit_timeout_id = 0;
static GMainLoop *main_loop;
static guint quit_timeout_id = 0;
static gboolean version;
static gint verbosity = -1;
static gchar *filename;
static gchar *mime_type;
static gboolean disable_shutdown;
static gboolean force_internal_extractors;
static gint verbosity = -1;
static gchar *filename;
static gchar *mime_type;
static gboolean disable_shutdown;
static gboolean force_internal_extractors;
static gboolean force_module;
static gboolean version;
static TrackerFTSConfig *fts_config;
static GOptionEntry entries[] = {
{ "version", 'V', 0,
G_OPTION_ARG_NONE, &version,
N_("Displays version information"),
NULL },
static GOptionEntry entries[] = {
{ "verbosity", 'v', 0,
G_OPTION_ARG_INT, &verbosity,
N_("Logging, 0 = errors only, "
......@@ -91,7 +88,7 @@ static GOptionEntry entries[] = {
G_OPTION_ARG_FILENAME, &filename,
N_("File to extract metadata for"),
N_("FILE") },
{ "mime", 'm', 0,
{ "mime", 't', 0,
G_OPTION_ARG_STRING, &mime_type,
N_("MIME type for file (if not provided, this will be guessed)"),
N_("MIME") },
......@@ -105,6 +102,14 @@ static GOptionEntry entries[] = {
G_OPTION_ARG_NONE, &force_internal_extractors,
N_("Force internal extractors over 3rd parties like libstreamanalyzer"),
NULL },
{ "force-module", 'm', 0,
G_OPTION_ARG_STRING, &force_module,
N_("Force a module to be used for extraction (e.g. \"foo\" for \"foo.so\")"),
N_("MODULE") },
{ "version", 'V', 0,
G_OPTION_ARG_NONE, &version,
N_("Displays version information"),
NULL },
{ NULL }
};
......@@ -298,7 +303,8 @@ run_standalone (void)
uri = g_file_get_uri (file);
object = tracker_extract_new (disable_shutdown,
force_internal_extractors);
force_internal_extractors,
force_module);
if (!object) {
g_free (uri);
......@@ -357,6 +363,20 @@ main (int argc, char *argv[])
return EXIT_FAILURE;
}
if (force_internal_extractors && force_module) {
gchar *help;
g_printerr ("%s\n\n",
_("Options --force-internal-extractors and --force-module can't be used together"));
help = g_option_context_get_help (context, TRUE, NULL);
g_option_context_free (context);
g_printerr ("%s", help);
g_free (help);
return EXIT_FAILURE;
}
g_option_context_free (context);
if (version) {
......@@ -415,7 +435,8 @@ main (int argc, char *argv[])
}
object = tracker_extract_new (disable_shutdown,
force_internal_extractors);
force_internal_extractors,
force_module);
if (!object) {
g_object_unref (config);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment