~ubuntu-branches/ubuntu/intrepid/moin/intrepid-updates

« back to all changes in this revision

Viewing changes to MoinMoin/script/old/migration/12_to_13_mig04.py

  • Committer: Bazaar Package Importer
  • Author(s): Sivan Greenberg
  • Date: 2006-07-09 19:28:02 UTC
  • Revision ID: james.westby@ubuntu.com-20060709192802-oaeuvt4v3e9300uj
Tags: 1.5.3-1ubuntu1
* Merge new debian version.
* Reapply Ubuntu changes:
    + debian/rules:
      - Comment out usage of control.ubuntu.in (doesn't fit!).
    + debian/control.in:
      - Dropped python2.3 binary package.
    + debian/control:
      - Dropped python2.3 binary, again.
      - Dropped python2.3-dev from Build-Depends-Indep.
    + debian/patches/001-attachment-xss-fix.patch:
      - Dropped this patch. It's now in upstream's distribution.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""
 
3
    migration from moin 1.3 < patch-196 to moin 1.3 >= patch-196
 
4
    Because of trouble with float timestamps, we migrate to usec timestamp resolution here.
 
5
    * data/pages/PageName/backup/<UTC timestamp> -> .../<UTC timestamp in usecs>
 
6
    * data/user/<uid>.bookmark -> convert to usecs
 
7
    * data/edit-log and data/pages/PageName/edit-log -> convert to usecs
 
8
    * data/event-log -> convert to usecs
 
9
    
 
10
    Steps for a successful migration:
 
11
 
 
12
        1. Stop your wiki and make a backup of old data and code
 
13
 
 
14
        2. Make a copy of the wiki's "data" directory to your working dir
 
15
 
 
16
        3. Run this script from your working dir
 
17
 
 
18
        4. If there was no error, you will find:
 
19
            data.pre-mig4 - the script renames your data directory copy to that name
 
20
            data - converted data dir
 
21
 
 
22
        5. Verify conversion results (number of pages, size of logs, attachments,
 
23
           number of backup copies) - everything should be reasonable before
 
24
           you proceed.
 
25
 
 
26
        6. Copy additional files from data.pre-mig4 to data (maybe intermaps, logs,
 
27
           etc.). Be aware that the file contents AND file names of wiki content
 
28
           may have changed, so DO NOT copy the files inside the cache/ directory,
 
29
           let the wiki refill it.
 
30
 
 
31
        7. Replace the data directory your wiki uses with the data directory
 
32
           you created by previous steps. DO NOT simply copy the converted stuff
 
33
           into the original or you will duplicate pages and create chaos!
 
34
 
 
35
        8. Test it - if something has gone wrong, you still have your backup.
 
36
 
 
37
 
 
38
    @copyright: 2004 Thomas Waldmann
 
39
    @license: GPL, see COPYING for details
 
40
"""
 
41
 
 
42
 
 
43
import os.path, sys, urllib
 
44
 
 
45
sys.path.insert(0, '../../../..')
 
46
from MoinMoin import wikiutil
 
47
 
 
48
from MoinMoin.script.migration.migutil import opj, listdir, copy_file, copy_dir
 
49
 
 
50
def convert_ts(ts_from):
 
51
    if ts_from > 5000000000: # far more than 32bits?
 
52
        ts_to = ts_from # we already have usec kind of timestamp
 
53
    else:
 
54
        ts_to = wikiutil.timestamp2version(ts_from)
 
55
    return long(ts_to) # must be long for py 2.2.x
 
56
 
 
57
def convert_eventlog(file_from, file_to):
 
58
    if not os.path.exists(file_from): 
 
59
        return
 
60
    f = open(file_to, 'a')
 
61
    for l in open(file_from):
 
62
        if not l.strip():
 
63
            continue
 
64
        data = l.split('\t')
 
65
        data[0] = str(convert_ts(float(data[0]))) # we want usecs
 
66
        data = '\t'.join(data)
 
67
        f.write(data)
 
68
    f.close()
 
69
        
 
70
def convert_editlog(file_from, file_to):
 
71
    if not os.path.exists(file_from): 
 
72
        return
 
73
    f = open(file_to, 'a')
 
74
    for l in open(file_from):
 
75
        data = l.split('\t')
 
76
        pagename = data[0]
 
77
        timestamp = data[2]
 
78
        data[2] = str(convert_ts(float(timestamp))) # we want usecs
 
79
        data = '\t'.join(data)
 
80
        f.write(data)
 
81
    f.close()
 
82
        
 
83
def convert_pagedir(dir_from, dir_to, is_backupdir=0):
 
84
    os.mkdir(dir_to)
 
85
    for pagedir in listdir(dir_from):
 
86
        text_from = opj(dir_from, pagedir, 'text')
 
87
        text_to = opj(dir_to, pagedir, 'text')
 
88
        os.mkdir(opj(dir_to, pagedir))
 
89
        copy_file(text_from, text_to)
 
90
        
 
91
        backupdir_from = opj(dir_from, pagedir, 'backup')
 
92
        backupdir_to = opj(dir_to, pagedir, 'backup')
 
93
        if os.path.exists(backupdir_from):
 
94
            os.mkdir(backupdir_to)
 
95
            for ts in listdir(backupdir_from):
 
96
                ts_usec = str(convert_ts(float(ts)))
 
97
                backup_from = opj(backupdir_from, ts)
 
98
                backup_to = opj(backupdir_to, ts_usec)
 
99
                copy_file(backup_from, backup_to)
 
100
        
 
101
        editlog_from = opj(dir_from, pagedir, 'edit-log')
 
102
        editlog_to = opj(dir_to, pagedir, 'edit-log')
 
103
        convert_editlog(editlog_from, editlog_to)
 
104
        
 
105
        #cachedir_from = opj(dir_from, pagedir, 'cache')
 
106
        #cachedir_to = opj(dir_to, pagedir, 'cache')
 
107
        #if os.path.exists(cachedir_from):
 
108
        #    os.mkdir(cachedir_to)
 
109
        #    try:
 
110
        #        copy_file(
 
111
        #            opj(cachedir_from, 'hitcounts'),
 
112
        #            opj(cachedir_to, 'hitcounts'))
 
113
        #    except: pass
 
114
 
 
115
        attachdir_from = opj(dir_from, pagedir, 'attachments')
 
116
        attachdir_to = opj(dir_to, pagedir, 'attachments')
 
117
        if os.path.exists(attachdir_from):
 
118
            try:
 
119
                copy_dir(attachdir_from, attachdir_to)
 
120
            except: pass
 
121
 
 
122
 
 
123
def convert_userdir(dir_from, dir_to):
 
124
    os.mkdir(dir_to)
 
125
    for fname in listdir(dir_from):
 
126
        if fname.endswith('.bookmark'):
 
127
            bm = open(opj(dir_from, fname)).read().strip()
 
128
            bm = str(wikiutil.timestamp2version(float(bm)))
 
129
            f = open(opj(dir_to, fname), 'w')
 
130
            f.write(bm)
 
131
            f.close()
 
132
        else:
 
133
            copy_file(opj(dir_from, fname), opj(dir_to, fname))
 
134
 
 
135
 
 
136
origdir = 'data.pre-mig4'
 
137
 
 
138
# Backup original dir and create new empty dir
 
139
try:
 
140
    os.rename('data', origdir)
 
141
    os.mkdir('data')
 
142
except OSError:
 
143
    print "You need to be in the directory where your copy of the 'data' directory is located."
 
144
    sys.exit(1)
 
145
 
 
146
convert_pagedir(opj(origdir, 'pages'), opj('data', 'pages'))
 
147
 
 
148
convert_editlog(opj(origdir, 'edit-log'), opj('data', 'edit-log'))
 
149
 
 
150
convert_eventlog(opj(origdir, 'event.log'), opj('data', 'event-log'))
 
151
 
 
152
convert_userdir(opj(origdir, 'user'), opj('data', 'user'))
 
153
 
 
154
copy_dir(opj(origdir, 'plugin'), opj('data', 'plugin'))
 
155
 
 
156
copy_file(opj(origdir, 'intermap.txt'), opj('data', 'intermap.txt'))
 
157