Commits

Thomas Waldmann committed 04cdc38

add index-dump script command

Comments (0)

Files changed (3)

MoinMoin/script/__init__.py

     manager.add_command("index-destroy", index.IndexDestroy())
     manager.add_command("index-move", index.IndexMove())
     manager.add_command("index-optimize", index.IndexOptimize())
+    manager.add_command("index-dump", index.IndexDump())
     from MoinMoin.script.maint import serialization
     manager.add_command("save", serialization.Serialize())
     manager.add_command("load", serialization.Deserialize())

MoinMoin/script/maint/index.py

 from MoinMoin import log
 logging = log.getLogger(__name__)
 
+from MoinMoin.storage.middleware.indexing import ALL_REVS, LATEST_REVS
+
 
 class IndexCreate(Command):
     description = 'Create empty indexes.'
     def run(self, tmp):
         app.storage.optimize_index(tmp=tmp)
 
+
+class IndexDump(Command):
+    description = 'Dump the indexes in readable form to stdout.'
+
+    option_list = [
+        Option('--tmp', action="store_true", required=False, dest='tmp', default=False,
+            help='use the temporary location.'),
+    ]
+
+    def run(self, tmp):
+        for indexname in [LATEST_REVS, ALL_REVS, ]:
+            print " %s %s %s" % ("-" * 10, indexname, "-" * 60)
+            for kvs in app.storage.dump(tmp=tmp, indexname=indexname):
+                for k, v in kvs:
+                    print k, repr(v)[:70]
+                print
+

MoinMoin/storage/middleware/indexing.py

         name = ALL_REVS if all_revs else LATEST_REVS
         return self.ix[name]
 
-    def dump(self, all_revs=False):
+    def dump(self, tmp=False, indexname=LATEST_REVS):
         """
-        Output all documents in index to stdout (most useful for debugging).
+        Yield key/value tuple lists for all documents in the indexes, fields sorted.
         """
-        ix = self.get_index(all_revs)
+        index_dir = self.index_dir_tmp if tmp else self.index_dir
+        ix = open_dir(index_dir, indexname=indexname)
         with ix.searcher() as searcher:
             for doc in searcher.all_stored_fields():
                 name = doc.pop(NAME, u"")
                 content = doc.pop(CONTENT, u"")
-                for field, value in [(NAME, name), ] + sorted(doc.items()) + [(CONTENT, content), ]:
-                    print "%s: %s" % (field, repr(value)[:70])
-                print
+                yield [(NAME, name), ] + sorted(doc.items()) + [(CONTENT, content), ]
 
     def query_parser(self, default_fields, all_revs=False):
         """