Back to index

moin  1.9.0~rc2
data.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - data_dir migration main script (new style)
00004 
00005     You can use this script to migrate your wiki's data_dir to the format
00006     expected by the current MoinMoin code. It will read data/meta to determine
00007     what needs to be done and call other migration scripts as needed.
00008 
00009     You must run this script as owner of the wiki files, usually this is the
00010     web server user (like www-data).
00011 
00012     Important: you must have run all 12_to_13* and the final 152_to_1050300
00013                mig scripts ONCE and in correct order manually before attempting
00014                to use the new style migration stuff.
00015 
00016     @copyright: 2006 MoinMoin:ThomasWaldmann
00017     @license: GNU GPL, see COPYING for details.
00018 """
00019 
00020 import os
00021 
00022 from MoinMoin import wikiutil
00023 from MoinMoin.script import MoinScript
00024 
00025 class PluginScript(MoinScript):
00026     """ Migration script class """
00027 
00028     def __init__(self, argv, def_values):
00029         MoinScript.__init__(self, argv, def_values)
00030         self.parser.add_option(
00031             "--all", action="store_true", dest="all_wikis",
00032             help="when given, update all wikis that belong to this farm"
00033         )
00034 
00035     def mainloop(self):
00036         self.init_request()
00037         request = self.request
00038         data_dir = request.cfg.data_dir
00039         meta_fname = os.path.join(data_dir, 'meta')
00040         while True:
00041             try:
00042                 meta = wikiutil.MetaDict(meta_fname, request.cfg.cache_dir)
00043                 try:
00044                     curr_rev = meta['data_format_revision']
00045                     mig_name = str(curr_rev)
00046                     execute = wikiutil.importBuiltinPlugin('script.migration', mig_name)
00047                     print "Calling migration script for %s, base revision %d" % (data_dir, curr_rev)
00048                     curr_rev = execute(self, data_dir, curr_rev)
00049                     if curr_rev is None:
00050                         print "Final mig script reached, migration is complete."
00051                         break
00052                     else:
00053                         print "Returned. New rev is %d." % curr_rev
00054                         meta['data_format_revision'] = curr_rev
00055                         meta.sync()
00056                 except wikiutil.PluginMissingError:
00057                     print "Error: There is no script for %s." % mig_name
00058                     break
00059             finally:
00060                 del meta
00061