Extractor-0.6/0000755000175000017500000000000011632462461015015 5ustar grothoffgrothoff00000000000000Extractor-0.6/README0000644000175000017500000000445311632462307015702 0ustar grothoffgrothoff00000000000000Python bindings for GNU libextractor About libextractor ================== libextractor is a simple library for keyword extraction. libextractor does not support all formats but supports a simple plugging mechanism such that you can quickly add extractors for additional formats, even without recompiling libextractor. libextractor typically ships with a dozen helper-libraries that can be used to obtain keywords from common file-types. libextractor is a part of the GNU project (http://www.gnu.org/). Dependencies ============ * python >= 2.3 web site: http://www.python.org/ * libextractor >= 0.6 web site: http://www.gnu.org/software/libextractor/ * ctypes >= 0.9 web site: http://starship.python.net/crew/theller/ctypes/ * setuptools (optional) web site: http://cheeseshop.python.org/pypi/setuptools Performances ============ Surprisingly the original C native library is only 20% faster than this python ctypes bindings. Here a quick and dirty bench: The C extract on Extractor test files: $ time `find Extractor/test -type f -not -name "*.svn*"|xargs extract` real 0m0.403s user 0m0.303s sys 0m0.061s Same data with the ctypes python bindings: $ time `find Extractor/test -type f -not -name "*.svn*"|xargs extract.py` real 0m0.661s user 0m0.529s sys 0m0.074s Install ======= Using the tarball (as root): # python setup.py install Using the egg (as root): # easy_install Extractor-*.egg Copyright ========= Copyright (C) 2006 Bader Ladjemi Copyright (C) 2011 Christian Grothoff This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA see COPYING for details Extractor-0.6/setup.py0000644000175000017500000000277011632441145016531 0ustar grothoffgrothoff00000000000000#!/bin/env/python try: from setuptools import setup except ImportError: from distutils.core import setup setup( name = "Extractor", version = "0.6", py_modules = ['extractor'], scripts = ['extract.py'], #install_requires = ['ctypes >= 0.9'], # metadata for upload to PyPI author = "Bader Ladjemi, Christian Grothoff", author_email = "libextractor@gnu.org", description = "Python bindings for GNU libextractor", license = "GNU GPL", keywords = "libextractor binding tag metadata", url = "http://gnunet.org/libextractor/", long_description="""libextractor is a simple library for keyword extraction. libextractor does not support all formats but supports a simple plugging mechanism such that you can quickly add extractors for additional formats, even without recompiling libextractor. libextractor typically ships with a dozen helper-libraries that can be used to obtain keywords from common file-types. libextractor is a part of the GNU project (http://www.gnu.org/).""", classifiers=['Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'License :: OSI Approved :: GNU General Public License (GPL)', 'Operating System :: OS Independent', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Topic :: System :: Filesystems', 'Topic :: Text Processing :: Filters'], platforms=['windows', 'Linux', 'MacOS X', 'Solaris', 'FreeBSD'], ) Extractor-0.6/extract.py0000644000175000017500000000301611632462075017042 0ustar grothoffgrothoff00000000000000#!/usr/bin/env python """extract.py This file is part of libextractor. (C) 2002, 2003, 2004, 2005 Vidyut Samanta and Christian Grothoff libextractor is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. libextractor 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 General Public License for more details. You should have received a copy of the GNU General Public License along with libextractor; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Little demo how to use the libextractor Python binding. """ import extractor import sys from ctypes import * import struct xtract = extractor.Extractor() def print_k(xt, plugin, type, format, mime, data, datalen): mstr = cast (data, c_char_p) # FIXME: this ignores 'datalen', not that great... # (in general, depending on the mime type and format, only # the first 'datalen' bytes in 'data' should be used). if (format == extractor.EXTRACTOR_METAFORMAT_UTF8): print "%s - %s" % (xtract.keywordTypes()[type], mstr.value) return 0 for arg in sys.argv[1:]: print "Keywords from %s:" % arg xtract.extract(print_k, None, arg) Extractor-0.6/PKG-INFO0000644000175000017500000000243111632462461016112 0ustar grothoffgrothoff00000000000000Metadata-Version: 1.0 Name: Extractor Version: 0.6 Summary: Python bindings for GNU libextractor Home-page: http://gnunet.org/libextractor/ Author: Bader Ladjemi, Christian Grothoff Author-email: libextractor@gnu.org License: GNU GPL Description: libextractor is a simple library for keyword extraction. libextractor does not support all formats but supports a simple plugging mechanism such that you can quickly add extractors for additional formats, even without recompiling libextractor. libextractor typically ships with a dozen helper-libraries that can be used to obtain keywords from common file-types. libextractor is a part of the GNU project (http://www.gnu.org/). Keywords: libextractor binding tag metadata Platform: windows Platform: Linux Platform: MacOS X Platform: Solaris Platform: FreeBSD Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License (GPL) Classifier: Operating System :: OS Independent Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: Microsoft :: Windows Classifier: Operating System :: POSIX Classifier: Topic :: System :: Filesystems Classifier: Topic :: Text Processing :: Filters Extractor-0.6/extractor.py0000644000175000017500000001307211632462145017404 0ustar grothoffgrothoff00000000000000# -*- coding: utf-8 -*- ## Python bindings for GNU libextractor ## ## Copyright (C) 2006 Bader Ladjemi ## Copyright (C) 2011 Christian Grothoff ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program 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 General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, write to the ## Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, ## USA. ## """ Python bindings for GNU libextractor libextractor is a simple library for keyword extraction. libextractor does not support all formats but supports a simple plugging mechanism such that you can quickly add extractors for additional formats, even without recompiling libextractor. libextractor typically ships with a dozen helper-libraries that can be used to obtain keywords from common file-types. libextractor is a part of the GNU project (http://www.gnu.org/). """ from ctypes import * #fake cdll import try: #loading shared object file libextractor = cdll.LoadLibrary('libextractor.so.3') except OSError: libextractor = cdll.extractor __all__ = ['Extractor'] __version__ = "0.6" __licence__ = "GNU GPL" """ keyword's charset encoding """ KeywordType = c_int MetaType = c_int EXTRACT_CB = CFUNCTYPE(c_int, c_void_p, c_char_p, KeywordType, MetaType, c_char_p, c_void_p, c_size_t) libextractor.EXTRACTOR_metatype_get_max.restype = KeywordType libextractor.EXTRACTOR_metatype_to_description.restype = c_char_p libextractor.EXTRACTOR_metatype_to_string.restype = c_char_p libextractor.EXTRACTOR_plugin_add_defaults.restype = c_void_p libextractor.EXTRACTOR_extract.argtypes = [c_void_p, c_char_p, c_void_p, c_size_t, EXTRACT_CB, c_void_p] EXTRACTOR_METAFORMAT_UNKNOWN = 0 EXTRACTOR_METAFORMAT_UTF8 = 1 EXTRACTOR_METAFORMAT_BINARY = 2 EXTRACTOR_METAFORMAT_C_STRING = 3 class Extractor(object): """ Main class for extracting meta-data with GNU libextractor. You may create multiple instances of Extractor to use different sets of library. Initially each Extractor will start with the default set of libraries. Use the extract method to obtain keywords from a file. Use the add and remove libraries methods to change the list of libraries that should be used. """ def __init__(self, defaults=True, libraries=None): """ Initialize Extractor's instance @param libraries: list of strings that contains extractor's name (supported types) @param defaults: load default plugins """ self.extractors = None if defaults: self.extractors = libextractor.EXTRACTOR_plugin_add_defaults(0) if libraries: self.extractors = libextractor.EXTRACTOR_plugin_add_config (self.extractors, libraries, 0) def extract(self, proc, proc_cls, filename=None, data=None, size=0): """Extract keywords from a file, or from its data. @param filename: filename string @param data: data contents @param size: data size @param proc: function to call on each value @param proc_cls: closure to proc If you give data, size has to be given as well. """ if not filename and not (data and size): return None else: libextractor.EXTRACTOR_extract (self.extractors, filename, data, size, EXTRACT_CB(proc), proc_cls) def addLibrary(self, library): """ Add given library to the extractor. Invoke with a string with the name of the library that should be added. For example, 'libextractor_filename' will prepend the extractor that just adds the filename as a keyword. No errors are reported if the library is not found. @param library: library's name """ self.extractors = libextractor.EXTRACTOR_plugin_add (self.extractors, library, NULL, 0) def removeLibrary(self, library): """ Remove a library. Pass the name of the library that is to be removed. Only one library can be removed at a time. For example, 'libextractor_pdf' removes the PDF extractor (if added). ValueError will be thrown if no library match. @param library: library's name """ self.extractors = libextractor.EXTRACTOR_plugin_remove(self.extractors, library) def addLibraries(self, libraries): """ Add given libraries. Same as addLibary but libraries is a list of library's names. @param libraries: list of libraries names """ self.extractors = libextractor.EXTRACTOR_plugin_add_config(self.extractors, libraries) def removeAllLibraries(self): """ Remove all libraries. """ libextractor.EXTRACTOR_plugin_remove_all(self.extractors) self.extractors = None def keywordTypes(self): """ Returns the list of all keywords types. @return: list of all keywords types """ i = 0 keyword_types = [] while True: keyword_type = libextractor.EXTRACTOR_metatype_to_string(i) if not keyword_type: break keyword_types.append(keyword_type) i += 1 return tuple(keyword_types) def __del__(self): """ >>> extractor = Extractor() >>> del extractor """ if self.extractors: self.removeAllLibraries() if __name__ == "__main__": import doctest doctest.testmod()