comparison MoinMoin/script/export/package.py @ 3062:94941d9d30ee

refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 21 Feb 2008 21:11:06 +0100
parents
children ed1a433803c6
comparison
equal deleted inserted replaced
3061:861407f630b4 3062:94941d9d30ee
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - Create a MoinMoin package from wiki pages specified.
4
5 You must run this script as owner of the wiki files, usually this is the
6 web server user.
7
8 @copyright: 2002-2004 Juergen Hermann <jh@web.de>,
9 2005-2006 MoinMoin:ThomasWaldmann,
10 2007 Federico Lorenzi
11 @license: GNU GPL, see COPYING for details.
12
13 """
14
15 import codecs, errno, os, re, shutil, sys, time
16
17 from MoinMoin import config, wikiutil, Page, user
18 from MoinMoin import script
19
20
21 class PluginScript(script.MoinScript):
22 """ Create package class """
23
24 def __init__(self, argv=None, def_values=None):
25 script.MoinScript.__init__(self, argv, def_values)
26 self.parser.add_option(
27 "-p", "--pages", dest="pages",
28 help="List of pages to package. Can be regular expressions, comma seperated lists, or a lone * for everything."
29 )
30 self.parser.add_option(
31 "-o", "--output", dest="output",
32 help="Output file for the package."
33 )
34 self.parser.add_option(
35 "-s", "--search", dest="search",
36 help="Search string to match."
37 )
38
39 self.parser.add_option(
40 "-u", "--user", dest="package_user",
41 help="User as whom the package operation will be performed as. "
42 )
43
44 def mainloop(self):
45 """ moin-package's main code. """
46
47 # Initalize request
48 self.init_request()
49 request = self.request
50 _ = self.request.getText
51
52 # Check our command line args
53 if self.options.pages and self.options.search:
54 script.fatal(_("Options --pages and --search are mutually exclusive!"))
55 elif not self.options.output:
56 script.fatal(_("You must specify an output file!"))
57 elif not self.options.pages and not self.options.search:
58 script.log(_("No pages specified using --pages or --search, assuming full package."))
59
60 # Sanity checks
61 if os.path.exists(self.options.output):
62 script.fatal(_("Output file already exists! Cowardly refusing to continue!"))
63
64 # Check for user
65 if self.options.package_user:
66 request.user = user.User(request, name=self.options.package_user)
67
68 # Import PackagePages here, as we now have an initalized request.
69 from MoinMoin.action.PackagePages import PackagePages
70
71 # Perform actual packaging.
72 package = PackagePages(request.rootpage.page_name, request)
73 packageoutput = open(self.options.output, "wb")
74 if self.options.search:
75 packagedata = package.collectpackage(package.searchpackage(request,
76 self.options.search), packageoutput)
77 elif self.options.pages:
78 packagedata = package.collectpackage(self.options.pages.split(","), packageoutput)
79 else:
80 packagedata = package.collectpackage(request.rootpage.getPageList(
81 include_underlay=False,
82 filter=lambda name: not wikiutil.isSystemPage(request, name)),
83 packageoutput)
84 if packagedata:
85 script.fatal(packagedata)