comparison MoinMoin/script/export/package.py @ 4065:d54e233a8784

package pages: feature added to optionally include attachments.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Mon, 01 Sep 2008 09:16:49 +0200
parents 2a3a6cb34e45
children a20de9383481
comparison
equal deleted inserted replaced
4061:fd35b36d6282 4065:d54e233a8784
40 3. To package all pages matching the search term 'MoinMoin' on a wiki to the file '~/mywiki.zip' 40 3. To package all pages matching the search term 'MoinMoin' on a wiki to the file '~/mywiki.zip'
41 moin ... export package --search MoinMoin --output ~/mywiki.zip 41 moin ... export package --search MoinMoin --output ~/mywiki.zip
42 42
43 4. Optionally, the --user argument could be added to any of the above examples, 43 4. Optionally, the --user argument could be added to any of the above examples,
44 causing the script to respect ACLs. 44 causing the script to respect ACLs.
45
46 5. Optionally, the --include_attachments argument could be added to any of the above examples,
47 causing the script to include attachments into the output file.
45 """ 48 """
46 49
47 def __init__(self, argv=None, def_values=None): 50 def __init__(self, argv=None, def_values=None):
48 script.MoinScript.__init__(self, argv, def_values) 51 script.MoinScript.__init__(self, argv, def_values)
49 self.parser.add_option( 52 self.parser.add_option(
50 "-p", "--pages", dest="pages", 53 "-p", "--pages", dest="pages",
51 help="List of pages to package. Can be regular expressions, comma seperated lists, or a lone * for everything." 54 help="List of pages to package. Can be regular expressions, comma seperated lists, or a lone * for everything."
55 )
56 self.parser.add_option(
57 "-a", "--include_attachments", action="store_true", dest="attachment",
58 help="Include attachments from each page"
52 ) 59 )
53 self.parser.add_option( 60 self.parser.add_option(
54 "-o", "--output", dest="output", 61 "-o", "--output", dest="output",
55 help="Output file for the package." 62 help="Output file for the package."
56 ) 63 )
78 elif not self.options.output: 85 elif not self.options.output:
79 script.fatal(_("You must specify an output file!")) 86 script.fatal(_("You must specify an output file!"))
80 elif not self.options.pages and not self.options.search: 87 elif not self.options.pages and not self.options.search:
81 script.log(_("No pages specified using --pages or --search, assuming full package.")) 88 script.log(_("No pages specified using --pages or --search, assuming full package."))
82 89
90 include_attachments = self.options.attachment or False
91 if include_attachments:
92 script.log(_("All attachments included into the package."))
93
83 # Sanity checks 94 # Sanity checks
84 if os.path.exists(self.options.output): 95 if os.path.exists(self.options.output):
85 script.fatal(_("Output file already exists! Cowardly refusing to continue!")) 96 script.fatal(_("Output file already exists! Cowardly refusing to continue!"))
86 97
87 # Check for user 98 # Check for user
94 # Perform actual packaging. 105 # Perform actual packaging.
95 package = PackagePages(request.rootpage.page_name, request) 106 package = PackagePages(request.rootpage.page_name, request)
96 packageoutput = open(self.options.output, "wb") 107 packageoutput = open(self.options.output, "wb")
97 if self.options.search: 108 if self.options.search:
98 packagedata = package.collectpackage(package.searchpackage(request, 109 packagedata = package.collectpackage(package.searchpackage(request,
99 self.options.search), packageoutput) 110 self.options.search), packageoutput,
111 include_attachments=include_attachments)
100 elif self.options.pages: 112 elif self.options.pages:
101 packagedata = package.collectpackage(self.options.pages.split(","), packageoutput) 113 packagedata = package.collectpackage(self.options.pages.split(","), packageoutput, include_attachments=include_attachments)
102 else: 114 else:
103 packagedata = package.collectpackage(request.rootpage.getPageList( 115 packagedata = package.collectpackage(request.rootpage.getPageList(
104 include_underlay=False, 116 include_underlay=False,
105 filter=lambda name: not wikiutil.isSystemPage(request, name)), 117 filter=lambda name: not wikiutil.isSystemPage(request, name)),
106 packageoutput) 118 packageoutput, include_attachments=include_attachments)
107 if packagedata: 119 if packagedata:
108 script.fatal(packagedata) 120 script.fatal(packagedata)
109 121