view MoinMoin/script/export/ @ 3108:2572688e031a

improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 23:40:48 +0100
parents ed1a433803c6
children 2a3a6cb34e45
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
MoinMoin - Create a MoinMoin package from wiki pages specified.

@copyright: 2002-2004 Juergen Hermann <>
            2005-2006 MoinMoin:ThomasWaldmann,
            2007 Federico Lorenzi
@license: GNU GPL, see COPYING for details.

import codecs, errno, os, re, shutil, sys, time

from MoinMoin import config, wikiutil, Page, user
from MoinMoin import script

class PluginScript(script.MoinScript):
This tool allows you to create a package of certain wiki pages.

Detailed Instructions:
General syntax: moin [options] export package [package-options]

[options] usually should be:

[package-options] see below:
    0. You must run this script as owner of the wiki files, usually this is the
       web server user.

    1. To package all non-system and non-underlay pages on a wiki to the file '~/'
       moin ... export package --output ~/

    2. To package the pages 'FooBar' and 'TestPage' on a wiki to the file '~/'
       moin ... export package --pages FooBar,TestPage --output ~/

    3. To package all pages matching the search term 'MoinMoin' on a wiki to the file '~/'
       moin ... export package --search MoinMoin --output ~/

    4. Optionally, the --user argument could be added to any of the above examples,
       causing the script to respect ACLs.

    def __init__(self, argv=None, def_values=None):
        script.MoinScript.__init__(self, argv, def_values)
            "-p", "--pages", dest="pages",
            help="List of pages to package. Can be regular expressions, comma seperated lists, or a lone * for everything."
            "-o", "--output", dest="output",
            help="Output file for the package."
            "-s", "--search", dest="search",
            help="Search string to match."

            "-u", "--user", dest="package_user",
            help="User as whom the package operation will be performed as. "

    def mainloop(self):
        """ moin-package's main code. """

        # Initalize request
        request = self.request
        _ = self.request.getText

        # Check our command line args
        if self.options.pages and
            script.fatal(_("Options --pages and --search are mutually exclusive!"))
        elif not self.options.output:
            script.fatal(_("You must specify an output file!"))
        elif not self.options.pages and not
            script.log(_("No pages specified using --pages or --search, assuming full package."))

        # Sanity checks
        if os.path.exists(self.options.output):
            script.fatal(_("Output file already exists! Cowardly refusing to continue!"))

        # Check for user
        if self.options.package_user:
            request.user = user.User(request, name=self.options.package_user)

        # Import PackagePages here, as we now have an initalized request.
        from MoinMoin.action.PackagePages import PackagePages

        # Perform actual packaging.
        package = PackagePages(request.rootpage.page_name, request)
        packageoutput = open(self.options.output, "wb")
            packagedata = package.collectpackage(package.searchpackage(request,
                                                             , packageoutput)
        elif self.options.pages:
                packagedata = package.collectpackage(self.options.pages.split(","), packageoutput)
                packagedata = package.collectpackage(request.rootpage.getPageList(
                                filter=lambda name: not wikiutil.isSystemPage(request, name)),
        if packagedata: