changeset 3018:5dfd26496da8

copied mig scripts from 1.6 branch
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 06 Jan 2008 21:56:19 +0100
parents 2fb7b7a26690
children 945368f271ef
files MoinMoin/script/migration/_conv160.py MoinMoin/script/migration/_conv160_wiki.py MoinMoin/script/migration/migutil.py
diffstat 3 files changed, 37 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/migration/_conv160.py	Sun Jan 06 20:09:15 2008 +0100
+++ b/MoinMoin/script/migration/_conv160.py	Sun Jan 06 21:56:19 2008 +0100
@@ -53,8 +53,15 @@
     """ Convert the <text> content of page <pagename>, using <renames> dict
         to rename links correctly. Additionally, convert some changed markup.
     """
-    if "#format wiki" not in text and "#format" in text:
-        return text # this is not a wiki page, leave it as is
+    if text.startswith('<?xml'):
+        # would be done with xslt processor
+        return text
+
+    pis, body = wikiutil.get_processing_instructions(text)
+    for pi, val in pis:
+        if pi == 'format' and val != 'wiki':
+            # not wiki page
+            return text
 
     text = convert_wiki(request, pagename, text, renames)
     return text
@@ -141,6 +148,7 @@
             editlog = self.data.items()
             editlog.sort()
             f = file(fname, "w")
+            max_rev = 0
             for key, fields in editlog:
                 timestamp, rev, action, pagename, ip, hostname, userid, extra, comment = fields
                 if action.startswith('ATT'):
@@ -154,6 +162,8 @@
                 if ('PAGE', pagename) in self.renames:
                     pagename = self.renames[('PAGE', pagename)]
                 timestamp = str(timestamp)
+                if rev != 99999999:
+                    max_rev = max(rev, max_rev)
                 revstr = '%08d' % rev
                 pagename = wikiutil.quoteWikinameFS(pagename)
                 fields = timestamp, revstr, action, pagename, ip, hostname, userid, extra, comment
@@ -161,7 +171,7 @@
                 f.write(log_str)
             if create_rev and not deleted:
                 timestamp = str(wikiutil.timestamp2version(time.time()))
-                revstr = '%08d' % (rev + 1)
+                revstr = '%08d' % (max_rev + 1)
                 action = 'SAVE'
                 ip = '127.0.0.1'
                 hostname = 'localhost'
@@ -249,7 +259,11 @@
             current_file = file(current_fname, "r")
             current_rev = current_file.read()
             current_file.close()
-            self.current = int(current_rev)
+            try:
+                self.current = int(current_rev)
+            except ValueError:
+                print "Error: invalid current file %s, SKIPPING THIS PAGE!" % current_fname
+                return
         # read edit-log
         editlog_fname = opj(page_dir, 'edit-log')
         if os.path.exists(editlog_fname):
@@ -353,7 +367,11 @@
             line = line.replace(u'\r', '').replace(u'\n', '')
             if not line.strip() or line.startswith(u'#'): # skip empty or comment lines
                 continue
-            key, value = line.split(u'=', 1)
+            try:
+                key, value = line.split(u'=', 1)
+            except Exception, err:
+                print "Error: User reader can not parse line %r from profile %r (%s)" % (line, fname, str(err))
+                continue
             self.profile[key] = value
         f.close()
         # read bookmarks
--- a/MoinMoin/script/migration/_conv160_wiki.py	Sun Jan 06 20:09:15 2008 +0100
+++ b/MoinMoin/script/migration/_conv160_wiki.py	Sun Jan 06 21:56:19 2008 +0100
@@ -162,7 +162,13 @@
         macro_args = m.group('macro_args')
         if macro_name == 'ImageLink':
             fixed, kw, trailing = wikiutil.parse_quoted_separated(macro_args)
+            #print "macro_args=%r" % macro_args
+            #print "fixed=%r, kw=%r, trailing=%r" % (fixed, kw, trailing)
             image, target = (fixed + ['', ''])[:2]
+            if image is None:
+                image = ''
+            if target is None:
+                target = ''
             if '://' not in image:
                 # if it is not a URL, it is meant as attachment
                 image = u'attachment:%s' % image
--- a/MoinMoin/script/migration/migutil.py	Sun Jan 06 20:09:15 2008 +0100
+++ b/MoinMoin/script/migration/migutil.py	Sun Jan 06 21:56:19 2008 +0100
@@ -2,7 +2,7 @@
 """
     MoinMoin - utility functions used by the migration scripts
 
-    @copyright: 2005 MoinMoin:ThomasWaldmann
+    @copyright: 2005,2007 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 import os, sys, shutil
@@ -35,9 +35,9 @@
         fatalError("can't find '%s'. You must run this script from the directory where '%s' is located." % src)
 
     try:
-        os.rename(src, dst)
-    except OSError:
-        fatalError("can't rename '%s' to '%s'" % (src, dst))
+        shutil.move(src, dst)
+    except:
+        fatalError("can't move '%s' to '%s'" % (src, dst))
 
     try:
         os.mkdir(src)
@@ -66,18 +66,15 @@
     print "%s/ -> %s/" % (dir_from, dir_to)
     try:
         shutil.copytree(dir_from, dir_to)
-    except:
-        error("can't copy '%s' to '%s'" % (dir_from, dir_to))
+    except Exception, err:
+        error("can't copy '%s' to '%s' (%s)" % (dir_from, dir_to, str(err)))
 
 
 def copy_file(fname_from, fname_to):
     """ Copy a single file """
     print "%s -> %s" % (fname_from, fname_to)
     try:
-        data = open(fname_from).read()
-        open(fname_to, "w").write(data)
-        st = os.stat(fname_from)
-        os.utime(fname_to, (st.st_atime, st.st_mtime))
+        shutil.copy2(fname_from, fname_to) # copies file data, mode, atime, mtime
     except:
         error("can't copy '%s' to '%s'" % (fname_from, fname_to))
 
@@ -86,7 +83,7 @@
     """ Move a single file """
     print "%s -> %s" % (fname_from, fname_to)
     try:
-        os.rename(fname_from, fname_to)
+        shutil.move(fname_from, fname_to) # moves file (even to different filesystem, including mode and atime/mtime)
     except:
         error("can't move '%s' to '%s'" % (fname_from, fname_to))