~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/script/migration/migutil.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
"""
3
3
    MoinMoin - utility functions used by the migration scripts
4
4
 
5
 
    @copyright: 2005 by Thomas Waldmann (MoinMoin:ThomasWaldmann)
 
5
    @copyright: 2005,2007 MoinMoin:ThomasWaldmann
6
6
    @license: GNU GPL, see COPYING for details.
7
7
"""
8
8
import os, sys, shutil
35
35
        fatalError("can't find '%s'. You must run this script from the directory where '%s' is located." % src)
36
36
 
37
37
    try:
38
 
        os.rename(src, dst)
39
 
    except OSError:
40
 
        fatalError("can't rename '%s' to '%s'" % (src, dst))
 
38
        shutil.move(src, dst)
 
39
    except:
 
40
        fatalError("can't move '%s' to '%s'" % (src, dst))
41
41
 
42
42
    try:
43
43
        os.mkdir(src)
44
44
    except OSError:
45
45
        fatalError("can't create '%s'" % src)
46
46
 
47
 
    
 
47
 
48
48
def listdir(path):
49
49
    """ Return list of files in path, filtering certain files """
50
50
    names = [name for name in os.listdir(path)
66
66
    print "%s/ -> %s/" % (dir_from, dir_to)
67
67
    try:
68
68
        shutil.copytree(dir_from, dir_to)
69
 
    except:
70
 
        error("can't copy '%s' to '%s'" % (dir_from, dir_to))
 
69
    except Exception, err:
 
70
        error("can't copy '%s' to '%s' (%s)" % (dir_from, dir_to, str(err)))
71
71
 
72
72
 
73
73
def copy_file(fname_from, fname_to):
74
74
    """ Copy a single file """
75
75
    print "%s -> %s" % (fname_from, fname_to)
76
76
    try:
77
 
        data = open(fname_from).read()
78
 
        open(fname_to, "w").write(data)
79
 
        st=os.stat(fname_from)
80
 
        os.utime(fname_to, (st.st_atime,st.st_mtime))
 
77
        shutil.copy2(fname_from, fname_to) # copies file data, mode, atime, mtime
81
78
    except:
82
79
        error("can't copy '%s' to '%s'" % (fname_from, fname_to))
83
80
 
86
83
    """ Move a single file """
87
84
    print "%s -> %s" % (fname_from, fname_to)
88
85
    try:
89
 
        os.rename(fname_from, fname_to)
 
86
        shutil.move(fname_from, fname_to) # moves file (even to different filesystem, including mode and atime/mtime)
90
87
    except:
91
88
        error("can't move '%s' to '%s'" % (fname_from, fname_to))
92
89
 
109
106
            copy_file(src, dst)
110
107
        else:
111
108
            error("can't find '%s'" % src)
 
109