view MoinMoin/script/export/ @ 5437:a20de9383481

fix --wiki-url examples, needs http:// now
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 16 Jan 2010 13:10:50 +0100
parents d54e233a8784
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 os

from MoinMoin import wikiutil, 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:
    --config-dir=/path/to/my/cfg/ --wiki-url=

[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.

    5. Optionally, the --include_attachments argument could be added to any of the above examples,
       causing the script to include attachments into the output file.

    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."
            "-a", "--include_attachments", action="store_true", dest="attachment",
            help="Include attachments from each page"
            "-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."))

        include_attachments = self.options.attachment or False
        if include_attachments:
            script.log(_("All attachments included into the 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, include_attachments=include_attachments)
            packagedata = package.collectpackage(request.rootpage.getPageList(
                                filter=lambda name: not wikiutil.isSystemPage(request, name)),
                                packageoutput, include_attachments=include_attachments)
        if packagedata: