changeset 82:df1fc8a424e8

remove old script infrastructure, remove migration script (use xml dump) remove stuff needed by moin's old plugin system (replaced by flask-script)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 06 Mar 2011 21:40:22 +0100
parents d7a0220aba58
children 8a5be4814a48
files MoinMoin/script/__init__.py MoinMoin/script/maint/__init__.py MoinMoin/script/migration/__init__.py MoinMoin/script/migration/backend.py MoinMoin/script/moin.py
diffstat 5 files changed, 1 insertions(+), 355 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/__init__.py	Sun Mar 06 21:34:36 2011 +0100
+++ b/MoinMoin/script/__init__.py	Sun Mar 06 21:40:22 2011 +0100
@@ -1,236 +1,7 @@
 # Copyright: 2000-2002 Juergen Hermann <jh@web.de>
-# Copyright: 2006 MoinMoin:ThomasWaldmann
+# Copyright: 2006,2011 MoinMoin:ThomasWaldmann
 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
 
 """
     MoinMoin - Extension Script Package
 """
-
-
-import os, sys, time
-from StringIO import StringIO
-
-flag_quiet = 0
-
-# ScriptRequest -----------------------------------------------------------
-
-class ScriptRequest(object):
-    """this is for scripts (MoinMoin/script/*) running from the commandline (CLI).
-    """
-    def __init__(self, instream, outstream, errstream):
-        self.instream = instream
-        self.outstream = outstream
-        self.errstream = errstream
-
-    def read(self, n=None):
-        if n is None:
-            data = self.instream.read()
-        else:
-            data = self.instream.read(n)
-        return data
-
-    def write(self, data):
-        self.outstream.write(data)
-
-    def write_err(self, data):
-        self.errstream.write(data)
-
-
-class ScriptRequestCLI(ScriptRequest):
-    """ When a script runs directly on the shell, we just use the CLI request
-        object (see MoinMoin.request.request_cli) to do I/O (which will use stdin/out/err).
-    """
-    def __init__(self, request):
-        self.request = request
-
-    def read(self, n=None):
-        return self.request.read(n)
-
-    def write(self, data):
-        return self.request.write(data)
-
-    def write_err(self, data):
-        return self.request.write(data) # XXX use correct request method - log, error, whatever.
-
-class ScriptRequestStrings(ScriptRequest):
-    def __init__(self, instr):
-        self.instream = StringIO(instr)
-        self.outstream = StringIO()
-        self.errstream = StringIO()
-
-    def fetch_output(self):
-        outstr = self.outstream.get_value()
-        errstr = self.errstream.get_value()
-        self.outstream.close()
-        self.errstream.close()
-        return outstr, errstr
-
-
-# Logging -----------------------------------------------------------------
-
-def fatal(msgtext, **kw):
-    """ Print error msg to stderr and exit. """
-    sys.stderr.write("\n\nFATAL ERROR: " + msgtext + "\n")
-    sys.exit(1)
-
-
-def log(msgtext):
-    """ Optionally print error msg to stderr. """
-    if not flag_quiet:
-        sys.stderr.write(msgtext + "\n")
-
-
-# Commandline Support --------------------------------------------------------
-
-class Script:
-    def __init__(self, cmd, usage, argv=None, def_values=None):
-        #print "argv:", argv, "def_values:", repr(def_values)
-        if argv is None:
-            self.argv = sys.argv[1:]
-        else:
-            self.argv = argv
-        self.def_values = def_values
-
-        global _start_time
-        _start_time = time.clock()
-
-        import optparse
-        from MoinMoin import project, version
-
-        rev = "%s %s" % (project, str(version))
-        sys.argv[0] = cmd
-
-        self.parser = optparse.OptionParser(
-            usage="%(cmd)s [command] %(usage)s" % {'cmd': os.path.basename(sys.argv[0]), 'usage': usage, },
-            version=rev, add_help_option=False)
-        self.parser.allow_interspersed_args = False
-        if def_values:
-            self.parser.set_defaults(**def_values.__dict__)
-        self.parser.add_option(
-            "-q", "--quiet",
-            action="store_true", dest="quiet",
-            help="Be quiet (no informational messages)"
-        )
-        self.parser.add_option(
-            "--show-timing",
-            action="store_true", dest="show_timing", default=False,
-            help="Show timing values [default: False]"
-        )
-
-    def run(self, showtime=1):
-        """ Run the main function of a command. """
-        global flag_quiet
-        try:
-            try:
-                self.options, self.args = self.parser.parse_args(self.argv)
-                flag_quiet = self.options.quiet
-                # ToDo check if we need to initialize request (self.init_request())
-                self.mainloop()
-            except KeyboardInterrupt:
-                log("*** Interrupted by user!")
-            except SystemExit:
-                showtime = 0
-                raise
-        finally:
-            if showtime:
-                self.logRuntime()
-
-    def logRuntime(self):
-        """ Print the total command run time. """
-        if self.options.show_timing:
-            log("Needed %.3f secs." % (time.clock() - _start_time, ))
-
-
-class MoinScript(Script):
-    """ Moin main script class """
-
-    def __init__(self, argv=None, def_values=None):
-        Script.__init__(self, "moin", "[general options] command subcommand [specific options]", argv, def_values)
-        # those are options potentially useful for all sub-commands:
-        self.parser.add_option(
-            "--config-dir", metavar="DIR", dest="config_dir",
-            help=("Path to the directory containing the wiki "
-                  "configuration files. [default: current directory]")
-        )
-        self.parser.add_option(
-            "--wiki-url", metavar="WIKIURL", dest="wiki_url",
-            help="URL of a single wiki to migrate e.g. http://localhost/mywiki/ [default: CLI]"
-        )
-        self.parser.add_option(
-            "--page", dest="page", default='',
-            help="wiki page name [default: all pages]"
-        )
-
-    def _update_option_help(self, opt_string, help_msg):
-        """ Update the help string of an option. """
-        for option in self.parser.option_list:
-            if option.get_opt_string() == opt_string:
-                option.help = help_msg
-                break
-
-    def init_request(self):
-        """ create request """
-        from MoinMoin.web.contexts import ScriptContext
-        url = self.options.wiki_url or None
-        self.request = ScriptContext(url, self.options.page)
-
-    def mainloop(self):
-        # Insert config dir or the current directory to the start of the path.
-        config_dir = self.options.config_dir
-        if config_dir:
-            if os.path.isdir(config_dir):
-                sys.path.insert(0, os.path.abspath(config_dir))
-            else:
-                fatal("bad path given to --config-dir option")
-
-        args = self.args
-        if len(args) < 2:
-            self.parser.print_help()
-            fatal("""You must specify a command module and name:
-
-moin ... account check ...
-moin ... account create ...
-moin ... account disable ...
-moin ... account resetpw ...
-
-moin ... index build ...
-
-moin ... maint reducewiki ...
-
-moin ... migration data ...
-moin ... migration backend ...
-
-General options:
-    Most commands need some general parameters before command subcommand:
-    --config-dir=/config/directory
-        Mandatory for most commands and specifies the directory that contains
-        your wikiconfig.py (or farmconfig.py).
-
-    --wiki-url=http://wiki.example.org/
-        Mandatory for most commands and specifies the url of the wiki you like
-        to operate on.
-
-Specific options:
-    Most commands need additional parameters after command subcommand.
-
-    To obtain additonal help on a command use 'moin module subcommand --help'
-""")
-
-        cmd_module, cmd_name = args[:2]
-        from MoinMoin.util import plugins
-        try:
-            plugin_class = plugins.importBuiltinPlugin('script.%s' % cmd_module, cmd_name, 'PluginScript')
-        except plugins.PluginMissingError:
-            fatal("Command plugin %r, command %r was not found." % (cmd_module, cmd_name))
-
-        # We have to use the args list here instead of optparse, as optparse only
-        # deals with things coming before command subcommand.
-        if "--help" in args or "-h" in args:
-            print "MoinMoin Help - %s/ %s\n" % (cmd_module, cmd_name)
-            print plugin_class.__doc__
-            print "Command line reference:"
-            print "======================="
-            plugin_class(args[2:], self.options).parser.print_help()
-        else:
-            plugin_class(args[2:], self.options).run() # all starts again there
-
--- a/MoinMoin/script/maint/__init__.py	Sun Mar 06 21:34:36 2011 +0100
+++ b/MoinMoin/script/maint/__init__.py	Sun Mar 06 21:40:22 2011 +0100
@@ -5,10 +5,3 @@
     MoinMoin - Maintenance Script Package
 """
 
-
-from MoinMoin.util import pysupport
-
-# create a list of extension scripts from the subpackage directory
-maint_scripts = pysupport.getPackageModules(__file__)
-modules = maint_scripts
-
--- a/MoinMoin/script/migration/__init__.py	Sun Mar 06 21:34:36 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-# Copyright: 2006 MoinMoin:ThomasWaldmann
-# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
-
-"""
-    MoinMoin - Migration Script Package
-"""
-
-
-from MoinMoin.util import pysupport
-
-# create a list of extension scripts from the subpackage directory
-migration_scripts = pysupport.getPackageModules(__file__)
-modules = migration_scripts
-
--- a/MoinMoin/script/migration/backend.py	Sun Mar 06 21:34:36 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-# Copyright: 2008 MoinMoin:PawelPacana
-# Copyright: 2008-2009 MoinMoin:ChristopherDenter
-# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
-
-"""
-    MoinMoin - backend migration script
-
-    Migrate 1.7, 1.8 and 1.9 wiki data (including users) to the new
-    2.0 storage format.
-    Assumptions:
-    - defined namespace_mapping in wikiconfig (Contains destination backends.)
-    - defined old_instance_path in wikiconfig (may be removed after conversion)
-"""
-
-
-import shutil, sys
-from os.path import join
-
-from flask import flaskg
-from flask import current_app as app
-
-from MoinMoin.script import MoinScript, fatal
-from MoinMoin.wsgiapp import init_unprotected_backends
-from MoinMoin.storage.backends import fs19
-
-class PluginScript(MoinScript):
-    """Backend migration class."""
-    def __init__(self, argv, def_values):
-        MoinScript.__init__(self, argv, def_values)
-        self.parser.add_option(
-            "-v", "--verbose", dest="verbose", action="store_true",
-            help="Provide progress information while performing the migration"
-        )
-        self.parser.add_option(
-            "-f", "--fails", dest="show_failed", action="store_true",
-            help="Print failed migration items"
-        )
-
-    def mainloop(self):
-        self.init_request()
-        request = self.request
-        init_unprotected_backends(request)
-        cfg = app.cfg
-
-        try:
-            data_dir_old = cfg.data_dir_old
-            user_dir_old = cfg.user_dir_old
-        except AttributeError:
-            fatal("""
-The backend migration did not find your old wiki data.
-
-Please, configure in your wiki config:
-    data_dir_old = '.../data' # must be the path of your old data directory
-                              # (it must contain the pages/ subdirectory)
-    user_dir_old = '.../data/user' # must be the path of your old user profile directory
-                                   # or None (no conversion of user profiles)
-""")
-
-        page_backend = fs19.FSPageBackend(data_dir_old)
-        dest_content = flaskg.unprotected_storage.get_backend(cfg.ns_content)
-        sys.stdout.write("Starting backend migration.\nConverting data.\n")
-        content_fails = dest_content.clone(page_backend, self.options.verbose)[2]
-        if self.options.show_failed and len(content_fails):
-            sys.stdout.write("\nFailed report\n-------------\n")
-            for name in content_fails.iterkeys():
-                sys.stdout.write("%r: %s\n" % (name, content_fails[name]))
-        sys.stdout.write("Content migration finished!\n")
-
-        if user_dir_old:
-            user_backend = fs19.FSUserBackend(user_dir_old)
-            dest_userprofile = flaskg.unprotected_storage.get_backend(cfg.ns_user_profile)
-            sys.stdout.write("Converting users.\n")
-            user_fails = dest_userprofile.clone(user_backend, self.options.verbose)[2]
-            if self.options.show_failed and len(user_fails):
-                sys.stdout.write("\nFailed report\n-------------\n")
-                for name in user_fails.iterkeys():
-                    sys.stdout.write("%r: %s\n" % (name, user_fails[name]))
-            sys.stdout.write("User profile migration finished!\n")
-
--- a/MoinMoin/script/moin.py	Sun Mar 06 21:34:36 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-#!/usr/bin/env python
-# Copyright: 2006 MoinMoin:ThomasWaldmann
-# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
-
-"""
-    MoinMoin - "moin" is the main script command and calls other stuff as
-    a sub-command.
-
-    Usage: moin cmdmodule cmdname [options]
-"""
-
-
-def run():
-    from MoinMoin.script import MoinScript
-    MoinScript().run(showtime=0)
-
-if __name__ == "__main__":
-    # Insert the path to MoinMoin in the start of the path
-    import sys, os
-    # we use position 1 (not 0) to give a config dir inserted at 0 a chance
-    # beware: we have a wikiconfig.py at the toplevel directory in the branch
-    sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), os.pardir, os.pardir)))
-
-    run()
-