changeset 10:400c6c6fd03a

script.maint.reducewiki: refactored to flask-script and renamed to reduce_revisions
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 22 Feb 2011 22:22:09 +0100
parents 6c54b77ab174
children cee0044428ff
files MoinMoin/script/maint/reduce_revisions.py MoinMoin/script/maint/reducewiki.py moin
diffstat 3 files changed, 40 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/script/maint/reduce_revisions.py	Tue Feb 22 22:22:09 2011 +0100
@@ -0,0 +1,38 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - Reduce Revisions of a backend
+
+    This script removes all revisions but the last one from all selected items.
+
+    @copyright: 2009 MoinMoin:ChristopherDenter,
+                2011 MoinMoin:ReimarBauer
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import re
+from flask import current_app as app
+from flaskext.script import Command, Option
+
+from MoinMoin.search import term
+
+
+class Reduce_Revisions(Command):
+    description = "This command can be used to remove all revisions but the last one from all selected items."
+    option_list = (
+        Option('--pattern', '-p', required=False, dest='pattern', type=unicode, default=".*",
+               help="You can limit the operation on certain items whose names match the given pattern."),
+    )
+
+    def run(self, pattern):
+        storage = app.unprotected_storage
+        query = term.NameRE(re.compile(pattern))
+        # If no pattern is given, the default regex will match every item.
+        for item in storage.search_items(query):
+            current_revno = item.next_revno - 1
+            for revno in item.list_revisions():
+                if revno < current_revno:
+                    rev = item.get_revision(revno)
+                    rev.destroy()
+
+        print "Finished reducing backend."
+
--- a/MoinMoin/script/maint/reducewiki.py	Mon Feb 21 04:21:59 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin - Reduce Wiki
-
-    This script can be used to remove all revisions but
-    the last ones from all items.
-    Handle with great care!
-
-    @copyright: 2009 MoinMoin:ChristopherDenter
-    @license: GNU GPL, see COPYING for details.
-"""
-
-from re import compile
-
-from flask import flaskg
-
-from MoinMoin.wsgiapp import init_unprotected_backends
-from MoinMoin.script import MoinScript, fatal
-from MoinMoin.search import term
-from MoinMoin.storage.error import NoSuchRevisionError
-
-class PluginScript(MoinScript):
-    """Reduce Wiki Script"""
-    def __init__(self, argv, def_values):
-        MoinScript.__init__(self, argv, def_values)
-        self.parser.add_option(
-            "-p", "--pattern", dest="pattern", action="store", type='string', default=".*",
-            help="You can limit the operation on certain items whose names match the given pattern."
-        )
-
-    def mainloop(self):
-        self.init_request()
-        request = self.request
-        init_unprotected_backends(request)
-        storage = flaskg.unprotected_storage
-
-        pattern = self.options.pattern
-        query = term.NameRE(compile(pattern))
-        # If no pattern is given, the default regex will match every item.
-        for item in storage.search_items(query):
-            current_revno = item.next_revno - 1
-            for revno in item.list_revisions():
-                if revno < current_revno:
-                    rev = item.get_revision(revno)
-                    rev.destroy()
-
-        print "Finished reducing backend."
-
--- a/moin	Mon Feb 21 04:21:59 2011 +0100
+++ b/moin	Tue Feb 22 22:22:09 2011 +0100
@@ -70,6 +70,8 @@
 manager.add_command("account_disable", Disable_User())
 from MoinMoin.script.account.resetpw import Set_Password
 manager.add_command("account_password", Set_Password())
+from MoinMoin.script.maint.reduce_revisions import Reduce_Revisions
+manager.add_command("maint_reduce_revisions", Reduce_Revisions())
 
 if __name__ == "__main__":
     if sys.argv == ['./moin']: