Back to index

moin  1.9.0~rc2
12_to_13_mig07.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """
00003     12_to_13.py - converting CRLF / LF style to the future standard
00004     Use this to convert from 1.3 pre patch-275 to patch-275.
00005 
00006     Changes:
00007     * use OS style for logs (== no change, same as it was)
00008     * use CRLF for page files on any platform (text/* mandates it!) -
00009       and we will use that MIME type soon.
00010     * use LF only internally in moin, convert from/to CRLF early/late
00011       where needed
00012 
00013     @copyright: 2004 Thomas Waldmann
00014     @license: GPL, see COPYING for details
00015 """
00016 
00017 import os.path, sys, urllib
00018 
00019 # Insert THIS moin dir first into sys path, or you would run another
00020 # version of moin!
00021 sys.path.insert(0, '../../../..')
00022 from MoinMoin import wikiutil
00023 
00024 from MoinMoin.script.migration.migutil import opj, listdir, copy_file, move_file, copy_dir
00025 
00026 def tocrlf(fni, fno):
00027     """ rewrite a text file using CRLF for line endings, no matter what
00028         it was before.
00029     """
00030     fi = open(fni, "rb")
00031     data = fi.read()
00032     fi.close()
00033     data = data.replace("\r", "")
00034     lines = data.split("\n")
00035     data = "\r\n".join(lines)
00036     if data[-2:] != "\r\n":
00037         data += "\r\n"
00038     fo = open(fno, "wb")
00039     fo.write(data)
00040     fo.close()
00041     st = os.stat(fni)
00042     os.utime(fno, (st.st_atime, st.st_mtime))
00043 
00044 def process_pagedirs(dir_from, dir_to):
00045     pagelist = listdir(dir_from)
00046     for pagename in pagelist:
00047         pagedir_from = opj(dir_from, pagename)
00048         pagedir_to = opj(dir_to, pagename)
00049 
00050         # first we copy all, even the stuff we convert later:
00051         copy_dir(pagedir_from, pagedir_to)
00052 
00053         rev_from = opj(pagedir_from, 'revisions')
00054         rev_to = opj(pagedir_to, 'revisions')
00055         if os.path.exists(rev_from):
00056             revlist = listdir(rev_from)
00057             for rfile in revlist:
00058                 rev = int(rfile)
00059                 r_from = opj(rev_from, rfile)
00060                 r_to = opj(rev_to, rfile)
00061                 tocrlf(r_from, r_to)
00062 
00063 origdir = 'data.pre-mig7'
00064 
00065 try:
00066     os.rename('data', origdir)
00067 except OSError:
00068     print "You need to be in the directory where your copy of the 'data' directory is located."
00069     sys.exit(1)
00070 
00071 os.makedirs(opj('data', 'pages'))
00072 
00073 process_pagedirs(opj(origdir, 'pages'), opj('data', 'pages'))
00074 
00075 copy_dir(opj(origdir, 'plugin'), opj('data', 'plugin'))
00076 
00077 copy_dir(opj(origdir, 'user'), opj('data', 'user'))
00078 
00079 copy_file(opj(origdir, 'edit-log'), opj('data', 'edit-log'))
00080 copy_file(opj(origdir, 'event-log'), opj('data', 'event-log'))
00081 
00082 copy_file(opj(origdir, 'intermap.txt'), opj('data', 'intermap.txt'))
00083 
00084 
00085