Attachment '0001-Implement-an-incremental-dump-process-7.patch'
Download 1 From 2a60dde756b7bd54d00f3578e41faf772d628b26 Mon Sep 17 00:00:00 2001
2 From: Paul Wise <pabs3@bonedaddy.net>
3 Date: Sat, 20 Apr 2013 13:46:50 +0800
4 Subject: [PATCH] Implement an incremental dump process
5
6 ---
7 MoinMoin/script/export/dump.py | 79 +++++++++++++++++++++++++++++++++++++++---
8 1 file changed, 74 insertions(+), 5 deletions(-)
9
10 diff --git a/MoinMoin/script/export/dump.py b/MoinMoin/script/export/dump.py
11 index d770e5b..8d079e6 100644
12 --- a/MoinMoin/script/export/dump.py
13 +++ b/MoinMoin/script/export/dump.py
14 @@ -3,7 +3,8 @@
15 MoinMoin - Dump a MoinMoin wiki to static pages
16
17 @copyright: 2002-2004 Juergen Hermann <jh@web.de>,
18 - 2005-2006 MoinMoin:ThomasWaldmann
19 + 2005-2006 MoinMoin:ThomasWaldmann,
20 + 2013 Paul Wise <pabs3@bonedaddy.net>
21 @license: GNU GPL, see COPYING for details.
22 """
23
24 @@ -12,11 +13,16 @@ import sys, os, time, codecs, shutil, re, errno
25 from MoinMoin import config, wikiutil, Page, user
26 from MoinMoin import script
27 from MoinMoin.action import AttachFile
28 +from MoinMoin.logfile import editlog
29 +from MoinMoin.util.filesys import touch
30
31 url_prefix_static = "."
32 logo_html = '<img src="logo.png">'
33 HTML_SUFFIX = ".html"
34
35 +timestamp_text = u'''This is a MoinMoin timestamp file.
36 +Please delete it to rebuild all pages.
37 +'''
38 page_template = u'''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
39 <html>
40 <head>
41 @@ -172,6 +178,47 @@ General syntax: moin [options] export dump [dump-options]
42
43 AttachFile.getAttachUrl = lambda pagename, filename, request, **kw: _attachment(request, pagename, filename, outputdir, **kw)
44
45 + # Check the last update timestamp
46 + timestamp_file = os.path.join(outputdir, 'moin-last-update')
47 + try:
48 + timestamp = os.stat(timestamp_file).st_mtime
49 + except OSError, err:
50 + timestamp = 0
51 + if err.errno == errno.ENOENT:
52 + with open(timestamp_file, 'w') as f:
53 + f.write(timestamp_text)
54 + else:
55 + script.fatal("Cannot check last update time of '%s' (%s)!" % (timestamp_file, str(err)))
56 +
57 + # Get a list of pages that need actions
58 + update = set()
59 + delete = set()
60 + if timestamp:
61 + touch(timestamp_file)
62 + version = wikiutil.timestamp2version(timestamp)
63 + log = editlog.EditLog(request)
64 + for line in log:
65 + if line.ed_time_usecs < version:
66 + pass
67 + elif line.action == 'ATTDEL':
68 + name = os.path.join(outputdir, "attachments", wikiutil.quoteWikinameFS(line.pagename), line.extra)
69 + url = "attachments/%s/%s" % (wikiutil.quoteWikinameFS(line.pagename), line.extra)
70 + delete.add((name, url))
71 + elif line.action == 'SAVE/RENAME':
72 + update.add(line.pagename)
73 + update.add(line.extra)
74 + else:
75 + update.add(line.pagename)
76 +
77 + # Delete files that need to be removed
78 + for name, url in delete:
79 + script.log('Removing "%s"...' % url)
80 + try:
81 + os.remove(name)
82 + except OSError, err:
83 + if err.errno != errno.ENOENT:
84 + script.fatal("Cannot remove '%s' (%s)!" % (url, str(err)))
85 +
86 errfile = os.path.join(outputdir, 'error.log')
87 errlog = open(errfile, 'w')
88 errcnt = 0
89 @@ -188,11 +235,34 @@ General syntax: moin [options] export dump [dump-options]
90 for pagename in pages:
91 # we have the same name in URL and FS
92 file = wikiutil.quoteWikinameURL(pagename)
93 - script.log('Writing "%s"...' % file)
94 + filepath = os.path.join(outputdir, file)
95 + exists = os.path.exists(filepath)
96 + attpath = os.path.join(outputdir, "attachments", wikiutil.quoteWikinameFS(pagename))
97 + atturl = "attachments/%s" % wikiutil.quoteWikinameFS(pagename)
98 + request.url = urlbase + pagename # add current pagename to url base
99 + page = Page.Page(request, pagename)
100 + missing = not page.exists()
101 + unreadable = not request.user.may.read(pagename)
102 + if missing or unreadable:
103 + script.log('Removing "%s"...' % file)
104 + try:
105 + os.remove(filepath)
106 + except OSError, err:
107 + if err.errno != errno.ENOENT:
108 + script.fatal("Cannot remove '%s' (%s)!" % (file, str(err)))
109 + script.log('Removing "%s"...' % atturl)
110 + try:
111 + shutil.rmtree(attpath)
112 + except OSError, err:
113 + if err.errno != errno.ENOENT:
114 + script.fatal("Cannot remove '%s' (%s)!" % (file, str(err)))
115 + continue
116 + if exists and timestamp and pagename not in update:
117 + # Skip this page since it exists and hasn't been updated
118 + continue
119 try:
120 + script.log('Writing "%s"...' % file)
121 pagehtml = ''
122 - request.url = urlbase + pagename # add current pagename to url base
123 - page = Page.Page(request, pagename)
124 request.page = page
125 try:
126 request.reset()
127 @@ -206,7 +276,6 @@ General syntax: moin [options] export dump [dump-options]
128 traceback.print_exc(None, errlog)
129 finally:
130 timestamp = time.strftime("%Y-%m-%d %H:%M")
131 - filepath = os.path.join(outputdir, file)
132 fileout = codecs.open(filepath, 'w', config.charset)
133 fileout.write(page_template % {
134 'charset': config.charset,
135 --
136 1.8.2.1
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.