make python recoll a package with 2 modules recoll and rclextract

This commit is contained in:
Jean-Francois Dockes
2012-12-20 17:05:34 +01:00
parent aa9518ef25
commit 9cc826168b
7 changed files with 51 additions and 15 deletions
+8 -2
View File
@@ -178,9 +178,15 @@ Extractor_idoctofile(rclx_ExtractorObject* self, PyObject *args,
outfile.assign(soutfile);
if (self->xtr == 0) {
PyErr_SetString(PyExc_AttributeError, "extract: null object");
PyErr_SetString(PyExc_AttributeError, "idoctofile: null object");
return 0;
}
if (ipath.empty()) {
PyErr_SetString(PyExc_ValueError, "idoctofile: null ipath");
return 0;
}
self->xtr->setTargetMType(mimetype);
TempFile temp;
bool status = self->xtr->interntofile(temp, outfile, ipath, mimetype);
if (!status) {
@@ -285,5 +291,5 @@ initrclextract(void)
Py_INCREF(&rclx_ExtractorType);
PyModule_AddObject(m, "Extractor", (PyObject *)&rclx_ExtractorType);
recoll_DocType = (PyObject*)PyCapsule_Import("recoll.doctypeptr", 0);
recoll_DocType = (PyObject*)PyCapsule_Import(PYRECOLL_PACKAGE "recoll.doctypeptr", 0);
}
+1 -1
View File
@@ -1703,6 +1703,6 @@ initrecoll(void)
// Export a few pointers for the benefit of other recoll python modules
PyObject* doctypecapsule =
PyCapsule_New(&recoll_DocType, "recoll.doctypeptr", 0);
PyCapsule_New(&recoll_DocType, PYRECOLL_PACKAGE "recoll.doctypeptr", 0);
PyModule_AddObject(m, "doctypeptr", doctypecapsule);
}
+2
View File
@@ -28,4 +28,6 @@ typedef struct {
RclConfig *rclconfig;
} recoll_DocObject;
#define PYRECOLL_PACKAGE "recoll."
#endif // _PYRECOLL_H_INCLUDED_
+6 -4
View File
@@ -50,8 +50,7 @@ module1 = Extension('recoll',
],
libraries = libs,
library_dirs = libdirs,
sources = ['pyrecoll.cpp',
])
sources = ['pyrecoll.cpp'])
module2 = Extension('rclextract',
define_macros = [('MAJOR_VERSION', '1'),
@@ -67,14 +66,17 @@ module2 = Extension('rclextract',
],
libraries = libs,
library_dirs = libdirs,
sources = ['pyrclextract.cpp',
])
sources = ['pyrclextract.cpp'])
setup (name = 'Recoll',
version = '1.0',
description = 'Query/Augment a Recoll full text index',
author = 'J.F. Dockes',
author_email = 'jfd@recoll.org',
url = 'http://www.recoll.org',
license = 'GPL',
long_description = '''
''',
packages = ['recoll'],
ext_package = 'recoll',
ext_modules = [module1, module2])
+20 -6
View File
@@ -6,9 +6,15 @@ This could actually be useful for something after some customization
import sys
from getopt import getopt
import recoll
import rclextract
try:
from recoll import recoll
from recoll import rclextract
hasextract = True
except:
import recoll
hasextract = False
allmeta = ("title", "keywords", "abstract", "url", "mimetype", "mtime",
"ipath", "fbytes", "dbytes", "relevancyrating")
@@ -27,9 +33,15 @@ class ptrmeths:
def extract(doc):
extractor = rclextract.Extractor(doc)
newdoc = extractor.extract(doc.ipath)
newdoc = extractor.textextract(doc.ipath)
return newdoc
def extractofile(doc, outfilename=""):
extractor = rclextract.Extractor(doc)
outfilename = extractor.idoctofile(doc.ipath, doc.mimetype, \
ofilename=outfilename)
return outfilename
def doquery(db, q):
# Get query object
query = db.query()
@@ -48,9 +60,11 @@ def doquery(db, q):
while query.next >= 0 and query.next < nres:
doc = query.fetchone()
print query.next, ":",
# for k,v in doc.items().items():
# print "KEY:", k.encode('utf-8'), "VALUE", v.encode('utf-8')
# continue
#for k,v in doc.items().items():
#print "KEY:", k.encode('utf-8'), "VALUE", v.encode('utf-8')
#continue
#outfile = extractofile(doc)
#print "outfile:", outfile, "url", doc.url.encode("utf-8")
for k in ("title", "mtime", "author"):
value = getattr(doc, k)
# value = doc.get(k)