From 23f8e94e57462dd5cafd4ae10aa8c947fd0efcdb Mon Sep 17 00:00:00 2001
From: Paul Wise <pabs3@bonedaddy.net>
Date: Sat, 20 Apr 2013 13:46:50 +0800
Subject: [PATCH] Implement an incremental dump process

---
 MoinMoin/script/export/dump.py | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/MoinMoin/script/export/dump.py b/MoinMoin/script/export/dump.py
index d770e5b..91fa4ac 100644
--- a/MoinMoin/script/export/dump.py
+++ b/MoinMoin/script/export/dump.py
@@ -12,11 +12,16 @@ import sys, os, time, codecs, shutil, re, errno
 from MoinMoin import config, wikiutil, Page, user
 from MoinMoin import script
 from MoinMoin.action import AttachFile
+from MoinMoin.logfile import editlog
+from MoinMoin.util.filesys import touch
 
 url_prefix_static = "."
 logo_html = '<img src="logo.png">'
 HTML_SUFFIX = ".html"
 
+timestamp_text = u'''This is a MoinMoin timestamp file.
+Please delete it to rebuild all pages.
+'''
 page_template = u'''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
@@ -126,6 +131,21 @@ General syntax: moin [options] export dump [dump-options]
             help = "User the dump will be performed as (for ACL checks, etc)"
         )
 
+    def changed_pages(self, request, timestamp):
+        pages = set()
+        old_pages = set()
+        unreadable_pages = set()
+        version = wikiutil.timestamp2version(timestamp)
+        log = editlog.EditLog(request)
+        for line in log:
+            if not request.user.may.read(line.pagename):
+                unreadable_pages.add(line.pagename)
+            elif line.ed_time_usecs < version:
+                old_pages.add(line.pagename)
+            else:
+                pages.add(line.pagename)
+        return (unreadable_pages, old_pages, pages)
+
     def mainloop(self):
         """ moin-dump's main code. """
 
@@ -157,7 +177,24 @@ General syntax: moin [options] export dump [dump-options]
         # use this user for permissions checks
         request.user = user.User(request, name=self.options.dump_user)
 
-        pages = request.rootpage.getPageList(user='') # get list of all pages in wiki
+        timestamp = None
+        timestamp_file = os.path.join(outputdir, 'moin-last-update')
+        try:
+            timestamp = os.stat(timestamp_file).st_mtime
+        except OSError, err:
+            if err.errno == errno.EEXIST:
+                with open(timestamp_file, 'w') as f:
+                    f.write(timestamp_text)
+            else:
+                script.fatal("Cannot check last update time of '%s'!" % timestamp_file)
+        if timestamp:
+            unreadable, old, pages = self.changed_pages(request, timestamp)
+            pages = list(pages)
+            touch(timestamp_file)
+            if unreadable or old:
+                script.log('Ignored %s old or unreadable pages' % (len(unreadable) + len(old)))
+        else:
+            pages = request.rootpage.getPageList(user='') # get list of all pages in wiki
         pages.sort()
         if self.options.page: # did user request a particular page or group of pages?
             try:
-- 
1.8.2.1

