view MoinMoin/script/migration/ @ 6133:a6283e189869 default tip

fixup: remove nonexisting passlib.utils._blowfish this was removed by the passlib 1.7.1 upgrade.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Jun 2017 18:10:19 +0200
parents 5dfd26496da8
line wrap: on
line source

# -*- coding: iso-8859-1 -*-
    MoinMoin - utility functions used by the migration scripts

    @copyright: 2005,2007 MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.
import os, sys, shutil

opj = os.path.join # yes, I am lazy
join = os.path.join

def fatalError(msg):
    """ Exit with error message on fatal errors """
    print "Fatal error:", msg
    print "Stoping"

def error(msg):
    """ Report minor error and continue """
    print "Error:", msg

def backup(src, dst):
    """ Create a backup of src directory in dst, create empty src

    @param src: source
    @param dst: destination
    print "Create backup of '%s' in '%s'" % (src, dst)

    if not os.path.isdir(src):
        fatalError("can't find '%s'. You must run this script from the directory where '%s' is located." % src)

        shutil.move(src, dst)
        fatalError("can't move '%s' to '%s'" % (src, dst))

    except OSError:
        fatalError("can't create '%s'" % src)

def listdir(path):
    """ Return list of files in path, filtering certain files """
    names = [name for name in os.listdir(path)
             if not name.startswith('.') and
             not name.endswith('.pickle') and
             name != 'CVS']
    return names

def makedir(newdir):
    """ Create a directory, if it doesn't exist """
    except OSError:

def copy_dir(dir_from, dir_to):
    """ Copy a complete directory """
    print "%s/ -> %s/" % (dir_from, dir_to)
        shutil.copytree(dir_from, dir_to)
    except Exception, err:
        error("can't copy '%s' to '%s' (%s)" % (dir_from, dir_to, str(err)))

def copy_file(fname_from, fname_to):
    """ Copy a single file """
    print "%s -> %s" % (fname_from, fname_to)
        shutil.copy2(fname_from, fname_to) # copies file data, mode, atime, mtime
        error("can't copy '%s' to '%s'" % (fname_from, fname_to))

def move_file(fname_from, fname_to):
    """ Move a single file """
    print "%s -> %s" % (fname_from, fname_to)
        shutil.move(fname_from, fname_to) # moves file (even to different filesystem, including mode and atime/mtime)
        error("can't move '%s' to '%s'" % (fname_from, fname_to))

def copy(items, srcdir, dstdir):
    """ copy items from src dir into dst dir

    @param items: list of items to copy
    @param srcdir: source directory to copy items from
    @param dstdir: destination directory to copy into
    for item in items:
        src = join(srcdir, item)
        dst = join(dstdir, item)

        # Copy directories
        if os.path.isdir(src):
            copy_dir(src, dst)
        elif os.path.isfile(src):
            copy_file(src, dst)
            error("can't find '%s'" % src)