Attachment 'debug_index_and_nuke.py'

Download

   1 #!/usr/bin/env python
   2 """
   3     debug script for indexing problems
   4 
   5     @copyright: 2010 MoinMoin:ReimarBauer
   6     @license: GNU GPL, see COPYING for details.
   7 """
   8 
   9 import sys, os, shutil, time
  10 moinpath = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
  11 sys.path.insert(0, moinpath)
  12 os.chdir(moinpath)
  13 
  14 from MoinMoin.search.Xapian import XapianIndex
  15 from MoinMoin.web.contexts import ScriptContext
  16 from MoinMoin._tests import nuke_xapian_index, wikiconfig, become_trusted, create_page, nuke_page, append_page
  17 from MoinMoin.PageEditor import PageEditor
  18 
  19 
  20 def run(request, timer):
  21     pages = {u'SearchTestPage': u'this is a test page',
  22              u'SearchTestLinks': u'SearchTestPage',
  23              u'SearchTestLinksLowerCase': u'searchtestpage',
  24              u'SearchTestOtherLinks': u'SearchTestLinks',
  25              u'TestEdit': u'TestEdit',
  26              u'TestOnEditing': u'another test page'}
  27 
  28     nuke_xapian_index(request)
  29     index = XapianIndex(request)
  30 
  31     index.do_queued_updates()
  32 
  33     become_trusted(request)
  34     for pagename, content in pages.iteritems():
  35         if content:
  36             page = PageEditor(request, pagename, do_editor_backup=False)
  37             page.deletePage()
  38             fpath = page.getPagePath(check_create=0)
  39             shutil.rmtree(fpath, True)
  40             time.sleep(timer)
  41             page.saveText(content, 0)
  42 
  43     connection = XapianIndex(request).get_search_connection()
  44     documents = connection.get_all_documents()
  45     result = len(documents)
  46     indexpages = []
  47     for document in documents:
  48         data = document.data
  49         indexpages.append(data["pagename"][0])
  50 
  51     for pagename, text in pages.iteritems():
  52         if text:
  53             nuke_page(request, pagename)
  54 
  55     return result, indexpages, pages.keys()
  56 
  57 if __name__ == '__main__':
  58     request = ScriptContext()
  59     print "----------------------------------------"
  60     print "this fails - unfortunately"
  61     result, indexpages, keys = run(request, timer=0)
  62     print "***************** %s *************" % result
  63     print set(indexpages) == set(keys)
  64     print "----------------------------------------"
  65     print "this succedds, because of 1s sleep"
  66     result, indexpages, keys = run(request, timer=1)
  67     print "***************** %s *************" % result
  68     print set(indexpages) == set(keys)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-03-07 17:01:05, 2.3 KB) [[attachment:debug_index_and_nuke.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.