~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/script/index/build.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
"""
3
3
MoinMoin - build xapian search engine's index
4
4
 
5
 
@copyright: 2006-2009 MoinMoin:ThomasWaldmann
 
5
@copyright: 2006 MoinMoin:ThomasWaldmann
6
6
@license: GNU GPL, see COPYING for details.
7
7
"""
8
8
 
9
 
import os
10
 
import errno
11
 
import shutil
12
 
 
13
9
from MoinMoin.script import MoinScript
14
10
 
15
11
class IndexScript(MoinScript):
23
19
General syntax: moin [options] index build [build-options]
24
20
 
25
21
[options] usually should be:
26
 
    --config-dir=/path/to/my/cfg/ --wiki-url=http://wiki.example.org/
 
22
    --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
27
23
 
28
24
[build-options] see below:
29
 
    Please note:
30
 
    * You must run this script as the owner of the wiki files,
31
 
      usually this is the web server user.
32
 
    * You may add the build-option --files=files.lst to let the indexer
33
 
      also consider the filesystem filenames contained in that file (one
34
 
      filename per line). Search results from these files will be "found"
35
 
      under a special pseudo page called FS (like File System).
36
 
      Without this option, the indexer will just consider pages and attachments.
37
 
 
38
 
    1. Conditionally (considering modification time) update the index:
39
 
       moin ... index build --mode=update
40
 
 
41
 
    2. Unconditionally add to the index:
42
 
       moin ... index build --mode=add
43
 
 
44
 
    3. Completely rebuild the index (1-stage):
45
 
       moin ... index build --mode=rebuild
46
 
 
47
 
       Note: until it has completely built the new index, the wiki will still
48
 
       use the old index. After rebuild has completed, it kills the old index
49
 
       and moves the new index into its place.
50
 
       If the wiki uses the index at that moment, that might have unwanted side
51
 
       effects. If you want to avoid that and you can accept a short downtime,
52
 
       consider using this safer method:
53
 
 
54
 
       Completely rebuild the index (2-stage):
55
 
       # takes long, does not interfere with wiki searches:
56
 
       moin ... index build --mode=buildnewindex
57
 
       stop this moin wiki process(es)
58
 
       # quick, replaces the old index with the new one:
59
 
       moin ... index build --mode=usenewindex
60
 
       start this moin wiki process(es)
 
25
    0. You must run this script as owner of the wiki files, usually this is the
 
26
       web server user.
 
27
 
 
28
    1. To add the files from '/files.lst' to the index
 
29
       moin ... index build --files /files.lst --mode add
 
30
 
 
31
    2. To update the index with the files from '/files.lst'
 
32
       moin ... index build --files /files.lst --mode update
 
33
 
 
34
    3. To rebuild the index with the files from '/files.lst'
 
35
       moin ... index build --files /files.lst --mode rebuild
61
36
"""
62
37
 
63
38
    def __init__(self, argv, def_values):
68
43
        )
69
44
        self.parser.add_option(
70
45
            "--mode", metavar="MODE", dest="mode",
71
 
            help="either add (unconditionally add), update (conditional update), rebuild (complete 1-stage index rebuild)"
72
 
                 " or buildnewindex and usenewindex (complete 2-stage index rebuild)"
 
46
            help="either add (unconditionally add to index), update (update an existing index) or rebuild (remove and add)"
73
47
        )
74
48
 
75
49
    def mainloop(self):
85
59
    """ Xapian index build script class """
86
60
 
87
61
    def command(self):
88
 
        from MoinMoin.search.Xapian import XapianIndex
89
 
        mode = self.options.mode
90
 
        if mode in ('rebuild', 'buildnewindex'):
91
 
            # rebuilding the DB into a new index directory, so the rebuild
92
 
            # process does not interfere with the currently in-use DB
93
 
            idx_mode, idx_name = 'add', 'index.new'
94
 
        elif mode in ('add', 'update'):
95
 
            # update/add in-place
96
 
            idx_mode, idx_name = mode, 'index'
97
 
        elif mode == 'usenewindex':
98
 
            pass # nothing todo
99
 
        else:
100
 
            pass # XXX give error msg about invalid mode
101
 
 
102
 
        if mode != 'usenewindex':
103
 
            idx = XapianIndex(self.request, name=idx_name)
104
 
            idx.indexPages(self.files, idx_mode)
105
 
 
106
 
        if mode in ('rebuild', 'usenewindex'):
107
 
            # 'rebuild' is still a bit dirty, because just killing old index will
108
 
            # fail currently running searches. Thus, maybe do this in a time
109
 
            # with litte wiki activity or better use 'buildnewindex' and
110
 
            # 'usenewindex' (see above).
111
 
            # XXX code here assumes that idx.db is a directory
112
 
            # TODO improve this with xapian stub DBs
113
 
            idx_old = XapianIndex(self.request, name='index').db
114
 
            idx_new = XapianIndex(self.request, name='index.new').db
115
 
            try:
116
 
                shutil.rmtree(idx_old)
117
 
            except OSError, err:
118
 
                if err.errno != errno.ENOENT: # ignore it if we have no current index
119
 
                    raise
120
 
            os.rename(idx_new, idx_old)
 
62
        from MoinMoin.search.Xapian import Index
 
63
        Index(self.request).indexPages(self.files, self.options.mode)
121
64