changeset 2752:7f6093028a66

1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 22 Aug 2007 13:51:26 +0200
parents 7a6b5f0c92c9
children 94d4f531bcf6
files MoinMoin/script/migration/1059999.py MoinMoin/script/migration/_conv160.py MoinMoin/script/migration/_conv160_wiki.py
diffstat 3 files changed, 51 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/migration/1059999.py	Wed Aug 22 10:28:20 2007 +0200
+++ b/MoinMoin/script/migration/1059999.py	Wed Aug 22 13:51:26 2007 +0200
@@ -14,12 +14,17 @@
 def execute(script, data_dir, rev):
     rename1_map = os.path.join(data_dir, 'rename1.txt')
     rename2_map = os.path.join(data_dir, 'rename2.txt')
+    fieldsep = DataConverter.LIST_FIELDSEP
+    if fieldsep == u'\t':
+        fieldsep = u'TAB'
     if not os.path.exists(rename2_map):
         print "You must first edit %s." % rename1_map
         print "For editing it, please use an editor that is able to edit UTF-8 encoded files."
-        print "Carefully edit - the fields are separated by a %r char, do not change this!" % DataConverter.RENAMES_FIELDSEP
-        print "Fields in this file are: TYPE OLDNAME NEWNAME"
-        print "You may ONLY edit the rightmost field (NEWNAME - in case you want to rename the page or file)."
+        print "Carefully edit - the fields are separated by a %s char, do not change this!" % fieldsep
+        print "Entries in this file look like:"
+        print "PAGE OLDPAGENAME NEWPAGENAME"
+        print "FILE OLDPAGENAME OLDFILENAME NEWFILENAME"
+        print "You may ONLY edit the rightmost field (the new name - in case you want to rename the page or file)."
         print
         print "After you have finished editing, rename the file to %s and re-issue the moin migrate command." % rename2_map
         return None # terminate here
--- a/MoinMoin/script/migration/_conv160.py	Wed Aug 22 10:28:20 2007 +0200
+++ b/MoinMoin/script/migration/_conv160.py	Wed Aug 22 13:51:26 2007 +0200
@@ -404,7 +404,9 @@
         self.ddata = dest_data_dir
         self.pages = {}
         self.users = {}
+        self.complete = {}
         self.renames = {}
+        self.complete_fname = opj(self.sdata, 'complete.txt')
         self.rename_fname1 = opj(self.sdata, 'rename1.txt')
         self.rename_fname2 = opj(self.sdata, 'rename2.txt')
 
@@ -418,6 +420,7 @@
             p.read()
             if not p.revisions:
                 continue # we don't care for pages with no revisions (trash)
+            self.complete[('PAGE', pn)] = None
             if "_" in pn:
                 # log all pagenames with underscores
                 self.renames[('PAGE', pn)] = None
@@ -431,44 +434,47 @@
                     else:
                         if ' ' in fn_str or '%' in fn_str: # files with blanks need quoting
                             log = True
+                    self.complete[('FILE', pn, fn)] = None
                     if log:
                         # log all strange attachment filenames
                         fn_str = fn.encode('utf-8')
                         self.renames[('FILE', pn, fn)] = None
-        self.save_renames()
+        self.save_list(self.complete_fname, self.complete)
+        self.save_list(self.rename_fname1, self.renames)
 
-    RENAMES_FIELDSEP = u'|' # in case | makes trouble, one can use \t tab char
+    LIST_FIELDSEP = u'|' # in case | makes trouble, one can use \t tab char
 
-    def save_renames(self):
-        f = codecs.open(self.rename_fname1, 'w', 'utf-8')
-        for k in self.renames:
+    def save_list(self, fname, what):
+        f = codecs.open(fname, 'w', 'utf-8')
+        for k in what:
             rtype, pn, fn = (k + (None, ))[:3]
             if rtype == 'PAGE':
                 line = (rtype, pn, pn)
             elif rtype == 'FILE':
                 line = (rtype, pn, fn, fn)
-            line = self.RENAMES_FIELDSEP.join(line)
+            line = self.LIST_FIELDSEP.join(line)
             f.write(line + u'\n')
         f.close()
 
-    def load_renames(self):
-        f = codecs.open(self.rename_fname2, 'r', 'utf-8')
+    def load_list(self, fname, what):
+        f = codecs.open(fname, 'r', 'utf-8')
         for line in f:
             line = line.rstrip()
             if not line:
                 continue
-            t = line.split(self.RENAMES_FIELDSEP)
+            t = line.split(self.LIST_FIELDSEP)
             rtype, p1, p2, p3 = (t + [None]*3)[:4]
             if rtype == u'PAGE':
-                self.renames[(str(rtype), p1)] = p2
+                what[(str(rtype), p1)] = p2
             elif rtype == u'FILE':
-                self.renames[(str(rtype), p1, p2)] = p3
+                what[(str(rtype), p1, p2)] = p3
         f.close()
 
     def pass2(self):
         """ Second, read the (user edited) rename list and do the renamings everywhere. """
         self.read_src()
-        self.load_renames()
+        #self.load_list(self.complete_fname, self.complete)
+        self.load_list(self.rename_fname2, self.renames)
         self.write_dest()
 
     def read_src(self):
--- a/MoinMoin/script/migration/_conv160_wiki.py	Wed Aug 22 10:28:20 2007 +0200
+++ b/MoinMoin/script/migration/_conv160_wiki.py	Wed Aug 22 13:51:26 2007 +0200
@@ -105,15 +105,34 @@
         item_type, page_name, file_name = (key + (None, ))[:3]
         abs_page_name = wikiutil.AbsPageName(current_page, page_name)
         if item_type == 'PAGE':
-            item_name = page_name
             key = (item_type, abs_page_name)
+            new_name = self.renames.get(key)
+            if new_name is None:
+                # we don't have an entry in rename map - apply the same magic
+                # to the page name as 1.5 did (" " -> "_") and try again:
+                abs_magic_name = abs_page_name.replace(u' ', u'_')
+                key = (item_type, abs_magic_name)
+                new_name = self.renames.get(key)
+                if new_name is None:
+                    # we didn't find it under the magic name either -
+                    # that means we do not rename it!
+                    new_name = page_name
+            if new_name != page_name and abs_page_name != page_name:
+                # we have to fix the (absolute) new_name to be a relative name (as it was before)
+                new_name = wikiutil.RelPageName(current_page, new_name)
         elif item_type == 'FILE':
-            item_name = file_name
             key = (item_type, abs_page_name, file_name)
-        new_name = self.renames.get(key, item_name)
-        if item_type == 'PAGE' and new_name != item_name and abs_page_name != page_name:
-            # we have to fix the (absolute) new_name to be a relative name (as it was before)
-            new_name = wikiutil.RelPageName(current_page, new_name)
+            new_name = self.renames.get(key)
+            if new_name is None:
+                # we don't have an entry in rename map - apply the same magic
+                # to the page name as 1.5 did (" " -> "_") and try again:
+                abs_magic_name = abs_page_name.replace(u' ', u'_')
+                key = (item_type, abs_magic_name, file_name)
+                new_name = self.renames.get(key)
+                if new_name is None:
+                    # we didn't find it under the magic name either -
+                    # that means we do not rename it!
+                    new_name = file_name
         return new_name
 
     def _replace_target(self, target):