comparison MoinMoin/script/migration/migutil.py @ 3018:5dfd26496da8

copied mig scripts from 1.6 branch
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 06 Jan 2008 21:56:19 +0100
parents bb2e053067fb
children
comparison
equal deleted inserted replaced
3017:2fb7b7a26690 3018:5dfd26496da8
1 # -*- coding: iso-8859-1 -*- 1 # -*- coding: iso-8859-1 -*-
2 """ 2 """
3 MoinMoin - utility functions used by the migration scripts 3 MoinMoin - utility functions used by the migration scripts
4 4
5 @copyright: 2005 MoinMoin:ThomasWaldmann 5 @copyright: 2005,2007 MoinMoin:ThomasWaldmann
6 @license: GNU GPL, see COPYING for details. 6 @license: GNU GPL, see COPYING for details.
7 """ 7 """
8 import os, sys, shutil 8 import os, sys, shutil
9 9
10 opj = os.path.join # yes, I am lazy 10 opj = os.path.join # yes, I am lazy
33 33
34 if not os.path.isdir(src): 34 if not os.path.isdir(src):
35 fatalError("can't find '%s'. You must run this script from the directory where '%s' is located." % src) 35 fatalError("can't find '%s'. You must run this script from the directory where '%s' is located." % src)
36 36
37 try: 37 try:
38 os.rename(src, dst) 38 shutil.move(src, dst)
39 except OSError: 39 except:
40 fatalError("can't rename '%s' to '%s'" % (src, dst)) 40 fatalError("can't move '%s' to '%s'" % (src, dst))
41 41
42 try: 42 try:
43 os.mkdir(src) 43 os.mkdir(src)
44 except OSError: 44 except OSError:
45 fatalError("can't create '%s'" % src) 45 fatalError("can't create '%s'" % src)
64 def copy_dir(dir_from, dir_to): 64 def copy_dir(dir_from, dir_to):
65 """ Copy a complete directory """ 65 """ Copy a complete directory """
66 print "%s/ -> %s/" % (dir_from, dir_to) 66 print "%s/ -> %s/" % (dir_from, dir_to)
67 try: 67 try:
68 shutil.copytree(dir_from, dir_to) 68 shutil.copytree(dir_from, dir_to)
69 except: 69 except Exception, err:
70 error("can't copy '%s' to '%s'" % (dir_from, dir_to)) 70 error("can't copy '%s' to '%s' (%s)" % (dir_from, dir_to, str(err)))
71 71
72 72
73 def copy_file(fname_from, fname_to): 73 def copy_file(fname_from, fname_to):
74 """ Copy a single file """ 74 """ Copy a single file """
75 print "%s -> %s" % (fname_from, fname_to) 75 print "%s -> %s" % (fname_from, fname_to)
76 try: 76 try:
77 data = open(fname_from).read() 77 shutil.copy2(fname_from, fname_to) # copies file data, mode, atime, mtime
78 open(fname_to, "w").write(data)
79 st = os.stat(fname_from)
80 os.utime(fname_to, (st.st_atime, st.st_mtime))
81 except: 78 except:
82 error("can't copy '%s' to '%s'" % (fname_from, fname_to)) 79 error("can't copy '%s' to '%s'" % (fname_from, fname_to))
83 80
84 81
85 def move_file(fname_from, fname_to): 82 def move_file(fname_from, fname_to):
86 """ Move a single file """ 83 """ Move a single file """
87 print "%s -> %s" % (fname_from, fname_to) 84 print "%s -> %s" % (fname_from, fname_to)
88 try: 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 except: 87 except:
91 error("can't move '%s' to '%s'" % (fname_from, fname_to)) 88 error("can't move '%s' to '%s'" % (fname_from, fname_to))
92 89
93 90
94 def copy(items, srcdir, dstdir): 91 def copy(items, srcdir, dstdir):