[rendering] This simple trick didn't work...
[wikipediardware.git] / host-tools / scripts / extract_index.py
blob77a3ef0d68f197c4da280d32c932514da10faf1c
1 #!/usr/bin/env python
2 """
3 Query the index database and combine the offset table and the
4 index table to produce the final index.
6 Copyright (C) 2009 Holger Hans Peter Freyther <zecke@openmoko.org>
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """
22 import optparse
23 import sys
24 import sqlite3
27 def parse():
28 parser = optparse.OptionParser(version = "Generate index source",
29 usage = """%prog [options] database""")
30 parser.add_option("-o", "--output", help = "The index source output file",
31 action = "store", dest = "output", default = "indexfile.index")
33 return parser.parse_args(sys.argv)
35 (opts, args) = parse()
37 print args[1]
38 connection = sqlite3.connect(args[1])
39 output = open(opts.output, "w")
40 cursor = connection.execute("SELECT IndexTable.title, Offsets.file, Offsets.offset FROM Offsets, IndexTable WHERE Offsets.hash = IndexTable.hash")
42 for row in cursor:
43 title = row[0].encode("utf-8")
44 print >> output, "%s%d%.10d" % (title, (row[1] % 10), row[2])