3
''Lookup'' notes file indexing
5
The file format has text notes separated by lines with a single '%' character
7
If the script is called with just the file name as an argument, it will
8
(re)index the contents.
10
If the script is called with second numeric argument, it will retrieve the
11
specified record and output it in html
19
rclconf = "/Users/dockes/.recoll-dlkp"
21
def udi(docfile, numrec):
22
return docfile + "#" + str(numrec)
24
###############################################################
25
def index_rec(db, numrec, rec):
28
doc.url = "file://" + docfile
31
doc.ipath = str(numrec)
33
doc.mimetype = "text/plain"
37
lines = rec.split("\n")
39
doc.title = unicode(lines[1], "iso-8859-1")
40
if len(doc.title.strip()) == 0 and len(lines) >= 3:
41
doc.title = unicode(lines[2], "iso-8859-1")
46
doc.fbytes = str(fbytes)
48
doc.text = unicode(rec, "iso-8859-1")
50
doc.dbytes = str(len(rec))
54
db.addOrUpdate(udi(docfile, numrec), doc)
58
rec = unicode(rec, "iso-8859-1").encode("utf-8")
59
rec = rec.replace("<", "<");
60
rec = rec.replace("&", "&");
61
rec = rec.replace('"', "&dquot;");
63
print '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">'
64
print '</head><body><pre>'
66
print '</pre></body></html>'
69
################################################################
72
sys.stderr.write("Usage: rcldlkp.py <filename> [<recnum>]\n")
81
targetnum = int(sys.argv[2])
85
#print docfile, targetnum
87
stdata = os.stat(docfile)
88
fmtime = stdata[stat.ST_MTIME]
89
fbytes = stdata[stat.ST_SIZE]
90
f = open(docfile, 'r')
94
db = recoll.connect(confdir=rclconf, writable=1)
95
if not db.needUpdate(udi(docfile, 0), str(fmtime)):
101
if re.compile("^%[ \t]*").match(line):
102
if targetnum == None:
103
index_rec(db, numrec, rec)
104
elif targetnum == numrec:
112
if targetnum == None: