Back to index

moin  1.9.0~rc2
12_to_13_mig03.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """
00003     migration from moin 1.3 < patch-101 to moin 1.3 >= patch-101
00004     We heavily change the file system layout here:
00005     * data/backup/PageName.<UTC timestamp> -> data/pages/PageName/backup/<UTC timestamp>
00006     * data/text/PageName -> data/pages/PageName/text
00007     * data/pages/PageName/edit-lock stays the same
00008     * data/pages/PageName/last-edited isn't used any more as we have the same in last line of page edit-log
00009     * data/pages/PageName/attachments/* stays the same
00010     * data/editlog -> stays there (as edit-log), but also gets splitted into data/pages/PageName/edit-log
00011     * data/event.log -> stays there (as event-log)
00012 
00013     We will use this, but don't need to convert, as it will be recreated automatically:
00014     * data/cache/Page.py/PageName.<formatter> -> data/pages/PageName/cache/<formatter>
00015     * data/cache/pagelinks/PageName -> data/pages/PageName/cache/pagelinks
00016     * data/cache/charts/hitcounts-PageName -> data/pages/PageName/cache/hitcounts
00017 
00018 
00019     Steps for a successful migration:
00020 
00021         1. Stop your wiki and make a backup of old data and code
00022 
00023         2. Make a copy of the wiki's "data" directory to your working dir
00024 
00025         3. Run this script from your working dir
00026 
00027         4. If there was no error, you will find:
00028             data.pre-mig3 - the script renames your data directory copy to that name
00029             data - converted data dir
00030 
00031         5. Verify conversion results (number of pages, size of logs, attachments,
00032            number of backup copies) - everything should be reasonable before
00033            you proceed.
00034 
00035         6. Copy additional files from data.pre-mig3 to data (maybe intermaps, logs,
00036            etc.). Be aware that the file contents AND file names of wiki content
00037            may have changed, so DO NOT copy the files inside the cache/ directory,
00038            let the wiki refill it.
00039 
00040         7. Replace the data directory your wiki uses with the data directory
00041            you created by previous steps. DO NOT simply copy the converted stuff
00042            into the original or you will duplicate pages and create chaos!
00043 
00044         8. Test it - if something has gone wrong, you still have your backup.
00045 
00046 
00047     @copyright: 2004 Thomas Waldmann
00048     @license: GPL, see COPYING for details
00049 """
00050 
00051 import os, sys, shutil, urllib
00052 
00053 sys.path.insert(0, '../../../..')
00054 from MoinMoin import wikiutil
00055 
00056 from MoinMoin.script.migration.migutil import opj, copy_file, copy_dir, listdir
00057 
00058 origdir = 'data.pre-mig3'
00059 
00060 def convert_textdir(dir_from, dir_to, is_backupdir=0):
00061     for fname_from in listdir(dir_from):
00062         if is_backupdir:
00063             fname, timestamp = fname_from.split('.')
00064         else:
00065             fname = fname_from
00066         try:
00067             os.mkdir(opj(dir_to, 'pages', fname))
00068         except: pass
00069         try:
00070             os.mkdir(opj(dir_to, 'pages', fname, 'backup'))
00071         except: pass
00072         try:
00073             os.mkdir(opj(dir_to, 'pages', fname, 'cache'))
00074         except: pass
00075         if is_backupdir:
00076             fname_to = opj('pages', fname, 'backup', timestamp)
00077         else:
00078             fname_to = opj('pages', fname, 'text')
00079         copy_file(opj(dir_from, fname_from), opj(dir_to, fname_to))
00080 
00081         #we don't have cache, mig2 doesn't convert it
00082         #try:
00083         #    cache_from = opj(origdir,'cache','charts','hitcounts-%s' % fname)
00084         #    cache_to = opj(dir_to, 'pages', fname, 'cache', 'hitcounts')
00085         #    if os.path.exists(cache_from):
00086         #        copy_file(cache_from, cache_to)
00087         #except: pass
00088 
00089 
00090 def convert_pagedir(dir_from, dir_to):
00091     os.mkdir(dir_to)
00092     for dname_from in listdir(dir_from):
00093         print "%s" % (dname_from, )
00094         dname_to = dname_from
00095         shutil.copytree(opj(dir_from, dname_from), opj(dir_to, dname_to), 1)
00096         try:
00097             os.remove(opj(dir_to, dname_to, 'last-edited'))
00098         except: pass
00099 
00100 
00101 def convert_editlog(file_from, file_to, dir_to):
00102     for l in open(file_from):
00103         data = l.split('\t')
00104         pagename = data[0]
00105         timestamp = data[2]
00106         data[2] = str(long(float(timestamp))) # we only want integer (must be long for py 2.2.x)
00107         data = '\t'.join(data)
00108 
00109         f = open(file_to, 'a')
00110         f.write(data)
00111         f.close()
00112 
00113         try:
00114             file_to2 = opj(dir_to, pagename, 'edit-log')
00115             f = open(file_to2, 'a')
00116             f.write(data)
00117             f.close()
00118         except: pass
00119 
00120 # Backup original dir and create new empty dir
00121 try:
00122     os.rename('data', origdir)
00123     os.mkdir('data')
00124 except OSError:
00125     print "You need to be in the directory where your copy of the 'data' directory is located."
00126     sys.exit(1)
00127 
00128 convert_pagedir(opj(origdir, 'pages'), opj('data', 'pages'))
00129 
00130 convert_textdir(opj(origdir, 'text'), 'data')
00131 
00132 convert_textdir(opj(origdir, 'backup'), 'data', 1)
00133 
00134 convert_editlog(opj(origdir, 'editlog'),
00135                 opj('data', 'edit-log'),
00136                 opj('data', 'pages'))
00137 
00138 copy_file(opj(origdir, 'event.log'), opj('data', 'event.log'))
00139 
00140 copy_dir(opj(origdir, 'plugin'), opj('data', 'plugin'))
00141 
00142 copy_dir(opj(origdir, 'user'), opj('data', 'user'))
00143 
00144 copy_file(opj(origdir, 'intermap.txt'), opj('data', 'intermap.txt'))
00145