[tracker] tracker-extract: Add ISO extractor using libosinfo



commit 57a81cd7f797511f977d042c7180b05e9a9aa39c
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Tue Dec 13 17:06:08 2011 +0100

    tracker-extract: Add ISO extractor using libosinfo
    
    Fixes GB#666372

 configure.ac                              |   35 +++++++
 data/ontologies/33-nfo.ontology           |    9 ++-
 data/ontologies/93-libosinfo.description  |   13 +++
 data/ontologies/93-libosinfo.ontology     |   23 +++++
 data/ontologies/Makefile.am               |    3 +-
 src/tracker-extract/11-iso.rule.in        |    4 +
 src/tracker-extract/Makefile.am           |   19 ++++
 src/tracker-extract/tracker-extract-iso.c |  148 +++++++++++++++++++++++++++++
 8 files changed, 252 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 78d2959..c9ceebb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -178,6 +178,7 @@ LIBVORBIS_REQUIRED=0.22
 LIBFLAC_REQUIRED=1.2.1
 LIBEXIF_REQUIRED=0.6
 LIBGSF_REQUIRED=1.13
+LIBOSINFO_REQUIRED=0.0.2
 EXEMPI_REQUIRED=2.1.0
 EVO_REQUIRED=2.32.0
 EVO_SHELL_REQUIRED=2.32.0
@@ -1815,6 +1816,39 @@ fi
 AM_CONDITIONAL(HAVE_LIBGSF, test "x$have_libgsf" = "xyes")
 
 ##################################################################
+# Check for tracker-extract: libosinfo
+##################################################################
+
+AC_ARG_ENABLE(libosinfo,
+              AS_HELP_STRING([--enable-libosinfo],
+                             [enable extractor for ISO data [[default=auto]]]),,
+              [enable_libosinfo=auto])
+
+if test "x$enable_libosinfo" != "xno" ; then
+   PKG_CHECK_MODULES(LIBOSINFO,
+                     [libosinfo-1.0 >= $LIBOSINFO_REQUIRED],
+		     [have_libosinfo=yes],
+		     [have_libosinfo=no])
+
+   AC_SUBST(LIBOSINFO_CFLAGS)
+   AC_SUBST(LIBOSINFO_LIBS)
+
+   if test "x$have_libosinfo" = "xyes"; then
+      AC_DEFINE(HAVE_LIBOSINFO, [], [Define if we have libosinfo])
+   fi
+else
+   have_libosinfo="no  (disabled)"
+fi
+
+if test "x$enable_libosinfo" = "xyes"; then
+   if test "x$have_libosinfo" != "xyes"; then
+      AC_MSG_ERROR([Couldn't find libosinfo >= $LIBOSINFO_REQUIRED.])
+   fi
+fi
+
+AM_CONDITIONAL(HAVE_LIBOSINFO, test "x$have_libosinfo" = "xyes")
+
+##################################################################
 # Check for tracker-extract: libgif
 ##################################################################
 
@@ -2333,6 +2367,7 @@ Metadata Extractors:
 	Support media art processing:           $selected_for_media_art
 	Support cue sheet parsing:              $have_libcue
 	Support playlists (w/ Totem):           $have_playlist
+	Support ISO image parsing:              $have_libosinfo
 
 Data Miners:
 
diff --git a/data/ontologies/33-nfo.ontology b/data/ontologies/33-nfo.ontology
index 65e4fb9..3fc09aa 100644
--- a/data/ontologies/33-nfo.ontology
+++ b/data/ontologies/33-nfo.ontology
@@ -12,7 +12,7 @@
 
 nfo: a tracker:Namespace, tracker:Ontology ;
 	tracker:prefix "nfo" ;
-	nao:lastModified "2011-12-06T15:40:00Z" .
+	nao:lastModified "2011-12-15T18:51:25Z" .
 
 nfo:Document a rdfs:Class ;
 	rdfs:label "Document" ;
@@ -926,6 +926,13 @@ nfo:isContentEncrypted a rdf:Property ;
 	rdfs:domain nie:InformationElement ;
 	rdfs:range xsd:boolean .
 
+# This change must be proposed upstream
+nfo:isBootable a rdf:Property ;
+	rdfs:label "Is content bootable" ;
+	rdfs:comment "True when the file is bootable, for example like an ISO or other disc images" ;
+	nrl:maxCardinality 1 ;
+	rdfs:domain nie:InformationElement ;
+	rdfs:range xsd:boolean .
 
 # Ontology request by Alexander Bokovoy, replaces nfo:device
 # These classes and properties need to be submitted to NEPOMUK
diff --git a/data/ontologies/93-libosinfo.description b/data/ontologies/93-libosinfo.description
new file mode 100644
index 0000000..290c123
--- /dev/null
+++ b/data/ontologies/93-libosinfo.description
@@ -0,0 +1,13 @@
+ prefix dsc: <http://www.tracker-project.org/temp/dsc#> .
+
+<virtual-ontology-uri:93-libosinfo.ontology> a dsc:Ontology ;
+	dsc:title "libosinfo-specific annotations Ontology" ;
+	dsc:description "libosinfo properties" ;
+
+	dsc:author "Red Hat, Inc" ;
+	dsc:editor "Red Hat, Inc" ;
+	dsc:gitlog "http://git.gnome.org/cgit/tracker/log/data/ontologies/93-libosinfo.ontology";;
+
+	dsc:localPrefix "osinfo" ;
+	dsc:baseUrl "http://www.tracker-project.org/ontologies/osinfo#";;
+	dsc:relativePath "./93-libosinfo.ontology" .
diff --git a/data/ontologies/93-libosinfo.ontology b/data/ontologies/93-libosinfo.ontology
new file mode 100644
index 0000000..cfe7377
--- /dev/null
+++ b/data/ontologies/93-libosinfo.ontology
@@ -0,0 +1,23 @@
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
+ prefix nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#> .
+ prefix nie: <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#> .
+ prefix nrl: <http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#> .
+ prefix osinfo: <http://www.tracker-project.org/ontologies/osinfo#> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
+ prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+osinfo: a tracker:Namespace, tracker:Ontology ;
+	tracker:prefix "osinfo" ;
+	nao:lastModified "2011-12-16T08:00:00Z" .
+
+osinfo:Installer a rdfs:Class ;
+	rdfs:label "Operating System Installer" ;
+	rdfs:comment "An operating system installer" ;
+	rdfs:subClassOf nfo:OperatingSystem .
+
+osinfo:id a rdf:Property ;
+	nrl:maxCardinality 1 ;
+	rdfs:domain nie:InformationElement ;
+	rdfs:range xsd:string .
diff --git a/data/ontologies/Makefile.am b/data/ontologies/Makefile.am
index b86440d..63ddbd2 100644
--- a/data/ontologies/Makefile.am
+++ b/data/ontologies/Makefile.am
@@ -24,7 +24,8 @@ config_DATA =                                          \
 	41-mfo.ontology	    41-mfo.description         \
 	89-mtp.ontology	    89-mtp.description         \
 	92-slo.ontology     92-slo.description         \
-	90-tracker.ontology 90-tracker.description
+	90-tracker.ontology 90-tracker.description     \
+	93-libosinfo.ontology 93-libosinfo.description
 
 if HAVE_MAEMO
 config_DATA +=                                         \
diff --git a/src/tracker-extract/11-iso.rule.in b/src/tracker-extract/11-iso.rule.in
new file mode 100644
index 0000000..30d0ff6
--- /dev/null
+++ b/src/tracker-extract/11-iso.rule.in
@@ -0,0 +1,4 @@
+[ExtractorRule]
+ModulePath= modulesdir@/libextract-iso.so
+MimeTypes=application/x-cd-image
+
diff --git a/src/tracker-extract/Makefile.am b/src/tracker-extract/Makefile.am
index 105899d..39203e9 100644
--- a/src/tracker-extract/Makefile.am
+++ b/src/tracker-extract/Makefile.am
@@ -34,6 +34,7 @@ rules_in_files = \
 	10-tiff.rule.in \
 	10-vorbis.rule.in \
 	10-xmp.rule.in \
+	11-iso.rule.in \
 	11-msoffice-xml.rule.in \
 	15-gstreamer-guess.rule.in \
 	15-playlist.rule.in \
@@ -141,6 +142,11 @@ modules_LTLIBRARIES += libextract-playlist.la
 rules_DATA += 15-playlist.rule
 endif
 
+if HAVE_LIBOSINFO
+modules_LTLIBRARIES += libextract-iso.la
+rules_DATA += 11-iso.rule
+endif
+
 # ABW
 libextract_abw_la_SOURCES = tracker-extract-abw.c
 libextract_abw_la_CFLAGS = $(TRACKER_EXTRACT_MODULES_CFLAGS)
@@ -422,6 +428,19 @@ libextract_icon_la_LIBADD = \
 	$(BUILD_LIBS) \
 	$(TRACKER_EXTRACT_MODULES_LIBS)
 
+# ISO
+libextract_iso_la_SOURCES = tracker-extract-iso.c
+libextract_iso_la_CFLAGS = \
+	$(TRACKER_EXTRACT_MODULES_CFLAGS) \
+	$(LIBOSINFO_CFLAGS)
+
+libextract_iso_la_LDFLAGS = $(module_flags)
+libextract_iso_la_LIBADD = \
+	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_MODULES_LIBS) \
+	$(LIBOSINFO_LIBS)
+
 #
 # Binaries
 #
diff --git a/src/tracker-extract/tracker-extract-iso.c b/src/tracker-extract/tracker-extract-iso.c
new file mode 100644
index 0000000..658b438
--- /dev/null
+++ b/src/tracker-extract/tracker-extract-iso.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2011, Red Hat, Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ *
+ * Author: Christophe Fergeau <cfergeau redhat com>
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+
+#include <osinfo/osinfo.h>
+
+#include <gio/gio.h>
+
+#include <libtracker-extract/tracker-extract.h>
+#include <libtracker-sparql/tracker-sparql.h>
+
+G_MODULE_EXPORT gboolean
+tracker_extract_get_metadata (TrackerExtractInfo *info_)
+{
+	/* NOTE: This function has to exist, tracker-extract checks
+	 * the symbole table for this function and if it doesn't
+	 * exist, the module is not loaded to be used as an extractor.
+	 */
+
+	/* File information */
+	GFile *file;
+	GError *error = NULL;
+	gchar *filename;
+	OsinfoLoader *loader;
+	OsinfoMedia *media;
+	OsinfoMedia *matched_media;
+	OsinfoDb *db;
+	OsinfoOs *os;
+
+	/* Data input */
+	gboolean bootable;
+	gboolean has_installer;
+	gboolean is_live;
+	const gchar *id;
+	const gchar *name;
+	TrackerSparqlBuilder *metadata;
+
+	metadata = tracker_extract_info_get_metadata_builder (info_);
+
+	file = tracker_extract_info_get_file (info_);
+	filename = g_file_get_path (file);
+
+	media = osinfo_media_create_from_location (filename, NULL, &error);
+	if (error != NULL) {
+		if (error->code != OSINFO_MEDIA_ERROR_NOT_BOOTABLE) {
+			g_message ("Could not extract iso info from '%s': %s",
+				   filename, error->message);
+			g_free (filename);
+			g_error_free (error);
+			return FALSE;
+		}
+		bootable = FALSE;
+		goto no_os;
+	} else {
+		bootable = TRUE;
+	}
+	g_free (filename);
+
+	loader = osinfo_loader_new ();
+	osinfo_loader_process_default_path (loader, &error);
+	if (error != NULL) {
+		g_message ("Error loading libosinfo OS data: %s",
+			   error->message);
+		g_error_free (error);
+		goto no_os;
+	}
+	g_warn_if_fail (media != NULL);
+	g_warn_if_fail (loader != NULL);
+
+	db = osinfo_loader_get_db (loader);
+	os = osinfo_db_guess_os_from_media (db, media, &matched_media);
+
+	if (os == NULL)
+		goto no_os;
+
+	tracker_sparql_builder_predicate (metadata, "a");
+	tracker_sparql_builder_object (metadata, "nfo:FilesystemImage");
+
+	name = osinfo_product_get_name (OSINFO_PRODUCT (os));
+	if (name != NULL) {
+		tracker_sparql_builder_predicate (metadata, "nie:title");
+		tracker_sparql_builder_object_string (metadata, name);
+	}
+
+	is_live = osinfo_media_get_live (matched_media);
+	if (is_live) {
+		tracker_sparql_builder_predicate (metadata, "a");
+		tracker_sparql_builder_object (metadata, "nfo:OperatingSystem");
+	}
+
+	has_installer = osinfo_media_get_installer (matched_media);
+	if (has_installer) {
+		tracker_sparql_builder_predicate (metadata, "a");
+		tracker_sparql_builder_object (metadata, "osinfo:Installer");
+	}
+
+	tracker_sparql_builder_predicate (metadata, "nfo:isBootable");
+	tracker_sparql_builder_object_boolean (metadata, bootable);
+
+	id = osinfo_entity_get_id (OSINFO_ENTITY (os));
+	if (id != NULL) {
+		tracker_sparql_builder_predicate (metadata, "osinfo:id");
+		tracker_sparql_builder_object_string (metadata, id);
+	}
+
+	g_object_unref (G_OBJECT (media));
+	g_object_unref (G_OBJECT (loader));
+
+	return TRUE;
+
+
+no_os:
+	if (media != NULL) {
+		g_object_unref (G_OBJECT (media));
+	}
+	if (loader != NULL) {
+		g_object_unref (G_OBJECT (loader));
+	}
+
+	tracker_sparql_builder_predicate (metadata, "a");
+	tracker_sparql_builder_object (metadata, "nfo:FilesystemImage");
+
+	tracker_sparql_builder_predicate (metadata, "nfo:isBootable");
+	tracker_sparql_builder_object_boolean (metadata, bootable);
+
+	return TRUE;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]