annotate MoinMoin/util/filesys.py @ 6111:1fdd537e9d83

SubProcess: reimplement exec_cmd subclassing Popen and overriding some methods isn't pretty. the code we have was written for py 2.4 or so and the py 2.7 Popen looked quite different. this way with the timer should be less problematic.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 06 Sep 2016 04:39:28 +0200
parents 371fb8e44d41
children
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - File System Utilities
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
4419
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
5 @copyright: 2002 Juergen Hermann <jh@web.de>,
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
6 2006-2008 MoinMoin:ThomasWaldmann
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9
5573
285d4897339e filesys: take posixemulation.rename code from werkzeug 0.6.1, it has atomic rename support for >=Vista/Server2008
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5144
diff changeset
10 import sys, os, shutil, time, errno
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
11 from stat import S_ISDIR, ST_MODE, S_IMODE
5611
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
12 import warnings
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13
4419
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
14 from MoinMoin import log
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
15 logging = log.getLogger(__name__)
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
16
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
18 ### Misc Helpers
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20
1898
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
21 def chmod(name, mode, catchexception=True):
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
22 """ change mode of some file/dir on platforms that support it.
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
23 usually you don't need this because we use os.umask() when importing
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
24 request.py
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
25 """
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
26 try:
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
27 os.chmod(name, mode)
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
28 except OSError:
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
29 if not catchexception:
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
30 raise
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
31
b5e94fec8669 caching: mkstemp uses 0600 to create files, we need chmod to change them to our preferred file mode
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
32
5802
dba48cb280f9 delete some code we had copied from werkzeug 0.6.1 while we bundled 0.5.1 (it is contained in the bundled werkzeug 0.8.1)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5711
diff changeset
33 from werkzeug.posixemulation import *
4944
506ce7e1f8e0 replace filesys.rename for win32 (thanks to the Mercurial developers!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4935
diff changeset
34
4945
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
35 rename_overwrite = rename
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
36
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
37 def rename_no_overwrite(oldname, newname, delete_old=False):
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
38 """ Multiplatform rename
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
39
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
40 This kind of rename is doing things differently: it fails if newname
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
41 already exists. This is the usual thing on win32, but not on posix.
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
42
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
43 If delete_old is True, oldname is removed in any case (even if the
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
44 rename did not succeed).
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
45 """
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
46 if os.name == 'nt':
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
47 try:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
48 try:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
49 os.rename(oldname, newname)
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
50 success = True
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
51 except:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
52 success = False
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
53 raise
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
54 finally:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
55 if not success and delete_old:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
56 os.unlink(oldname)
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
57 else:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
58 try:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
59 try:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
60 os.link(oldname, newname)
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
61 success = True
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
62 except:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
63 success = False
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
64 raise
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
65 finally:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
66 if success or delete_old:
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
67 os.unlink(oldname)
37b919adfab4 add filesys.rename_no_overwrite (win32 rename semantics, plus optional removal of src file in any case)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4944
diff changeset
68
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
69
3443
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
70 def touch(name):
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
71 if sys.platform == 'win32':
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
72 import win32file, win32con, pywintypes
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
73
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
74 access = win32file.GENERIC_WRITE
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
75 share = (win32file.FILE_SHARE_DELETE |
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
76 win32file.FILE_SHARE_READ |
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
77 win32file.FILE_SHARE_WRITE)
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
78 create = win32file.OPEN_EXISTING
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
79 mtime = time.gmtime()
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
80 handle = win32file.CreateFile(name, access, share, None, create,
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
81 win32file.FILE_ATTRIBUTE_NORMAL |
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
82 win32con.FILE_FLAG_BACKUP_SEMANTICS,
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
83 None)
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
84 try:
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
85 newTime = pywintypes.Time(mtime)
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
86 win32file.SetFileTime(handle, newTime, newTime, newTime)
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
87 finally:
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
88 win32file.CloseHandle(handle)
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
89 else:
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
90 os.utime(name, None)
4ee64d58e801 move platform dependent filesystem routines to util.filesys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
91
4419
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
92
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
93 def access_denied_decorator(fn):
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
94 """ Due to unknown reasons, some os.* functions on Win32 sometimes fail
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
95 with Access Denied (although access should be possible).
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
96 Just retrying it a bit later works and this is what we do.
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
97 """
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
98 if sys.platform == 'win32':
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
99 def wrapper(*args, **kwargs):
5142
294b97b991d3 work around windows caching lock problems (see details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4945
diff changeset
100 max_retries = 42
4419
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
101 retry = 0
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
102 while True:
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
103 try:
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
104 return fn(*args, **kwargs)
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
105 except OSError, err:
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
106 retry += 1
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
107 if retry > max_retries:
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
108 raise
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
109 if err.errno == errno.EACCES:
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
110 logging.warning('%s(%r, %r) -> access denied. retrying...' % (fn.__name__, args, kwargs))
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
111 time.sleep(0.01)
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
112 continue
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
113 raise
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
114 return wrapper
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
115 else:
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
116 return fn
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
117
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
118 stat = access_denied_decorator(os.stat)
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
119 mkdir = access_denied_decorator(os.mkdir)
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
120 rmdir = access_denied_decorator(os.rmdir)
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
121
d85005213fd9 locking: workaround win32 problems (spurious access denied exceptions), improve logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3674
diff changeset
122
3609
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
123 def fuid(filename, max_staleness=3600):
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
124 """ return a unique id for a file
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
125
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
126 Using just the file's mtime to determine if the file has changed is
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
127 not reliable - if file updates happen faster than the file system's
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
128 mtime granularity, then the modification is not detectable because
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
129 the mtime is still the same.
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
130
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
131 This function tries to improve by using not only the mtime, but also
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
132 other metadata values like file size and inode to improve reliability.
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
133
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
134 For the calculation of this value, we of course only want to use data
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
135 that we can get rather fast, thus we use file metadata, not file data
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
136 (file content).
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
137
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
138 Note: depending on the operating system capabilities and the way the
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
139 file update is done, this function might return the same value
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
140 even if the file has changed. It should be better than just
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
141 using file's mtime though.
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
142 max_staleness tries to avoid the worst for these cases.
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
143
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
144 @param filename: file name of the file to look at
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
145 @param max_staleness: if a file is older than that, we may consider
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
146 it stale and return a different uid - this is a
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
147 dirty trick to work around changes never being
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
148 detected. Default is 3600 seconds, use None to
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
149 disable this trickery. See below for more details.
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
150 @return: an object that changes value if the file changed,
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
151 None is returned if there were problems accessing the file
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
152 """
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
153 try:
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
154 st = os.stat(filename)
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
155 except (IOError, OSError):
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
156 uid = None # for permanent errors on stat() this does not change, but
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
157 # having a changing value would be pointless because if we
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
158 # can't even stat the file, it is unlikely we can read it.
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
159 else:
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
160 fake_mtime = int(st.st_mtime)
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
161 if not st.st_ino and max_staleness:
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
162 # st_ino being 0 likely means that we run on a platform not
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
163 # supporting it (e.g. win32) - thus we likely need this dirty
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
164 # trick
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
165 now = int(time.time())
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
166 if now >= st.st_mtime + max_staleness:
4935
a6b0b1fcd463 fuid: keep same fake_mtime for intervals of max_staleness duration
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4419
diff changeset
167 # keep same fake_mtime for each max_staleness interval
a6b0b1fcd463 fuid: keep same fake_mtime for intervals of max_staleness duration
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4419
diff changeset
168 fake_mtime = int(now / max_staleness) * max_staleness
3609
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
169 uid = (st.st_mtime, # might have a rather rough granularity, e.g. 2s
4935
a6b0b1fcd463 fuid: keep same fake_mtime for intervals of max_staleness duration
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4419
diff changeset
170 # on FAT, 1s on ext3 and might not change on fast
a6b0b1fcd463 fuid: keep same fake_mtime for intervals of max_staleness duration
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4419
diff changeset
171 # updates
3609
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
172 st.st_ino, # inode number (will change if the update is done
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
173 # by e.g. renaming a temp file to the real file).
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
174 # not supported on win32 (0 ever)
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
175 st.st_size, # likely to change on many updates, but not
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
176 # sufficient alone
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
177 fake_mtime, # trick to workaround file system / platform
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
178 # limitations causing permanent trouble
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
179 )
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
180 return uid
9653e7a9bcc4 new function filesys.fuid(fname) as slightly better file mtime replacement + tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3443
diff changeset
181
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
182
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
183 def copystat(src, dst):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
184 """Copy stat bits from src to dst
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
185
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
186 This should be used when shutil.copystat would be used on directories
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
187 on win32 because win32 does not support utime() for directories.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
188
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
189 According to the official docs written by Microsoft, it returns ENOACCES if the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
190 supplied filename is a directory. Looks like a trainee implemented the function.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
191 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
192 if sys.platform == 'win32' and S_ISDIR(os.stat(dst)[ST_MODE]):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
193 if os.name == 'nt':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
194 st = os.stat(src)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
195 mode = S_IMODE(st[ST_MODE])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
196 if hasattr(os, 'chmod'):
1317
76a76def8687 remove most chmod calls, use 1 os.umask() call in request module instead (port from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1307
diff changeset
197 os.chmod(dst, mode) # KEEP THIS ONE!
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
198 #else: pass # we are on Win9x,ME - no chmod here
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
199 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
200 shutil.copystat(src, dst)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
201
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
202
6088
371fb8e44d41 AttachFile multifile operation: support copying multiple files to another page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5802
diff changeset
203 copy = shutil.copy
371fb8e44d41 AttachFile multifile operation: support copying multiple files to another page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5802
diff changeset
204
371fb8e44d41 AttachFile multifile operation: support copying multiple files to another page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5802
diff changeset
205
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
206 def copytree(src, dst, symlinks=False):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
207 """Recursively copy a directory tree using copy2().
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
208
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
209 The destination directory must not already exist.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
210 If exception(s) occur, an Error is raised with a list of reasons.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
211
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
212 If the optional symlinks flag is true, symbolic links in the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
213 source tree result in symbolic links in the destination tree; if
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
214 it is false, the contents of the files pointed to by symbolic
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
215 links are copied.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
216
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
217 In contrary to shutil.copytree, this version also copies directory
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
218 stats, not only file stats.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
219
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
220 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
221 names = os.listdir(src)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
222 os.mkdir(dst)
1004
7828d27399d4 whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
223 copystat(src, dst)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
224 errors = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
225 for name in names:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
226 srcname = os.path.join(src, name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
227 dstname = os.path.join(dst, name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
228 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
229 if symlinks and os.path.islink(srcname):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
230 linkto = os.readlink(srcname)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
231 os.symlink(linkto, dstname)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
232 elif os.path.isdir(srcname):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
233 copytree(srcname, dstname, symlinks)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
234 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
235 shutil.copy2(srcname, dstname)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
236 # XXX What about devices, sockets etc.?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
237 except (IOError, os.error), why:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
238 errors.append((srcname, dstname, why))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
239 if errors:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5613
diff changeset
240 raise EnvironmentError(str(errors))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
241
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
242 # Code could come from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
243
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
244 # we currently do not support locking
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
245 LOCK_EX = LOCK_SH = LOCK_NB = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
246
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
247 def lock(file, flags):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
248 raise NotImplementedError
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
249
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
250 def unlock(file):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
251 raise NotImplementedError
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
252
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
253
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
254 # ----------------------------------------------------------------------
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
255 # Get real case of path name on case insensitive file systems
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
256 # TODO: nt version?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
257
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
258 if sys.platform == 'darwin':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
259
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
260 def realPathCase(path):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
261 """ Return the real case of path e.g. PageName for pagename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
262
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
263 HFS and HFS+ file systems, are case preserving but case
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
264 insensitive. You can't have 'file' and 'File' in the same
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
265 directory, but you can get the real name of 'file'.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
266
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
267 @param path: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
268 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
269 @return the real case of path or None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
270 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
271 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
272 from Carbon import File
4133
251827af7ddc Fixed: cannot check for File.Error in same line like checking import of File
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3609
diff changeset
273 try:
251827af7ddc Fixed: cannot check for File.Error in same line like checking import of File
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3609
diff changeset
274 return File.FSRef(path).as_pathname()
251827af7ddc Fixed: cannot check for File.Error in same line like checking import of File
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3609
diff changeset
275 except File.Error:
251827af7ddc Fixed: cannot check for File.Error in same line like checking import of File
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3609
diff changeset
276 return None
3674
8772197c9262 fix traceback in filesys.py on Mac OS X when import Carbon fails (thanks to Uche Ogbuji for the patch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3609
diff changeset
277 except ImportError:
8772197c9262 fix traceback in filesys.py on Mac OS X when import Carbon fails (thanks to Uche Ogbuji for the patch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3609
diff changeset
278 return None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
279
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
280 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
281
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
282 def realPathCase(path):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
283 return None
1004
7828d27399d4 whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 497
diff changeset
284
5611
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
285 # dircache stuff seems to be broken on win32 (at least for FAT32, maybe NTFS).
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
286 # dircache stuff is also broken on POSIX if updates happen too fast (< 1s).
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
287 DCENABLED = 0 # set to 0 to completely disable dircache usage
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
288
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
289 # Note: usage of the dc* functions below is deprecated, they'll get removed soon.
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
290 dc_deprecated = "dircache function calls (dcdisable,dclistdir,dcreset) are deprecated, please fix caller"
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
291
1801
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
292 def dcdisable():
5611
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
293 warnings.warn(dc_deprecated, DeprecationWarning, stacklevel=2)
1801
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
294 global DCENABLED
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
295 DCENABLED = 0
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
296
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
297 import dircache
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
298
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
299 def dclistdir(path):
5611
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
300 warnings.warn(dc_deprecated, DeprecationWarning, stacklevel=2)
1801
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
301 if sys.platform == 'win32' or not DCENABLED:
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
302 return os.listdir(path)
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
303 else:
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
304 return dircache.listdir(path)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
305
1801
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
306 def dcreset():
5611
ad60b3570553 MoinMoin.util.filesys: disable usage of dircache, deprecate dc* functions (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5142
diff changeset
307 warnings.warn(dc_deprecated, DeprecationWarning, stacklevel=2)
1801
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
308 if sys.platform == 'win32' or not DCENABLED:
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
309 return
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
310 else:
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
311 return dircache.reset()
5574
8b9acb287705 filesys.rename: add debug logging and retries (see below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5573
diff changeset
312