Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/util_win32.py @ 2147:b7225adb2e0b
merge with crew.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Thu, 27 Apr 2006 22:10:45 -0700 |
parents | 760339ccc799 |
children | 9b42304d9896 |
rev | line source |
---|---|
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1 # util_win32.py - utility functions that use win32 API |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
2 # |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
4 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
5 # |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
6 # This software may be used and distributed according to the terms of |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
7 # the GNU General Public License, incorporated herein by reference. |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
8 |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
9 # Mark Hammond's win32all package allows better functionality on |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
10 # Windows. this module overrides definitions in util.py. if not |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
11 # available, import of this module will fail, and generic code will be |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
12 # used. |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
13 |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
14 import win32api |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
15 |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
16 from demandload import * |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
17 from i18n import gettext as _ |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
18 demandload(globals(), 'errno os pywintypes win32con win32file win32process') |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
19 demandload(globals(), 'winerror') |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
20 |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
21 class WinError(OSError): |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
22 winerror_map = { |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
23 winerror.ERROR_ACCESS_DENIED: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
24 winerror.ERROR_ACCOUNT_DISABLED: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
25 winerror.ERROR_ACCOUNT_RESTRICTION: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
26 winerror.ERROR_ALREADY_ASSIGNED: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
27 winerror.ERROR_ALREADY_EXISTS: errno.EEXIST, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
28 winerror.ERROR_ARITHMETIC_OVERFLOW: errno.ERANGE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
29 winerror.ERROR_BAD_COMMAND: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
30 winerror.ERROR_BAD_DEVICE: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
31 winerror.ERROR_BAD_DRIVER_LEVEL: errno.ENXIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
32 winerror.ERROR_BAD_EXE_FORMAT: errno.ENOEXEC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
33 winerror.ERROR_BAD_FORMAT: errno.ENOEXEC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
34 winerror.ERROR_BAD_LENGTH: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
35 winerror.ERROR_BAD_PATHNAME: errno.ENOENT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
36 winerror.ERROR_BAD_PIPE: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
37 winerror.ERROR_BAD_UNIT: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
38 winerror.ERROR_BAD_USERNAME: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
39 winerror.ERROR_BROKEN_PIPE: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
40 winerror.ERROR_BUFFER_OVERFLOW: errno.ENAMETOOLONG, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
41 winerror.ERROR_BUSY: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
42 winerror.ERROR_BUSY_DRIVE: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
43 winerror.ERROR_CALL_NOT_IMPLEMENTED: errno.ENOSYS, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
44 winerror.ERROR_CANNOT_MAKE: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
45 winerror.ERROR_CANTOPEN: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
46 winerror.ERROR_CANTREAD: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
47 winerror.ERROR_CANTWRITE: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
48 winerror.ERROR_CRC: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
49 winerror.ERROR_CURRENT_DIRECTORY: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
50 winerror.ERROR_DEVICE_IN_USE: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
51 winerror.ERROR_DEV_NOT_EXIST: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
52 winerror.ERROR_DIRECTORY: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
53 winerror.ERROR_DIR_NOT_EMPTY: errno.ENOTEMPTY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
54 winerror.ERROR_DISK_CHANGE: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
55 winerror.ERROR_DISK_FULL: errno.ENOSPC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
56 winerror.ERROR_DRIVE_LOCKED: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
57 winerror.ERROR_ENVVAR_NOT_FOUND: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
58 winerror.ERROR_EXE_MARKED_INVALID: errno.ENOEXEC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
59 winerror.ERROR_FILENAME_EXCED_RANGE: errno.ENAMETOOLONG, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
60 winerror.ERROR_FILE_EXISTS: errno.EEXIST, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
61 winerror.ERROR_FILE_INVALID: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
62 winerror.ERROR_FILE_NOT_FOUND: errno.ENOENT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
63 winerror.ERROR_GEN_FAILURE: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
64 winerror.ERROR_HANDLE_DISK_FULL: errno.ENOSPC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
65 winerror.ERROR_INSUFFICIENT_BUFFER: errno.ENOMEM, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
66 winerror.ERROR_INVALID_ACCESS: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
67 winerror.ERROR_INVALID_ADDRESS: errno.EFAULT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
68 winerror.ERROR_INVALID_BLOCK: errno.EFAULT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
69 winerror.ERROR_INVALID_DATA: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
70 winerror.ERROR_INVALID_DRIVE: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
71 winerror.ERROR_INVALID_EXE_SIGNATURE: errno.ENOEXEC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
72 winerror.ERROR_INVALID_FLAGS: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
73 winerror.ERROR_INVALID_FUNCTION: errno.ENOSYS, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
74 winerror.ERROR_INVALID_HANDLE: errno.EBADF, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
75 winerror.ERROR_INVALID_LOGON_HOURS: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
76 winerror.ERROR_INVALID_NAME: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
77 winerror.ERROR_INVALID_OWNER: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
78 winerror.ERROR_INVALID_PARAMETER: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
79 winerror.ERROR_INVALID_PASSWORD: errno.EPERM, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
80 winerror.ERROR_INVALID_PRIMARY_GROUP: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
81 winerror.ERROR_INVALID_SIGNAL_NUMBER: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
82 winerror.ERROR_INVALID_TARGET_HANDLE: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
83 winerror.ERROR_INVALID_WORKSTATION: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
84 winerror.ERROR_IO_DEVICE: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
85 winerror.ERROR_IO_INCOMPLETE: errno.EINTR, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
86 winerror.ERROR_LOCKED: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
87 winerror.ERROR_LOCK_VIOLATION: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
88 winerror.ERROR_LOGON_FAILURE: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
89 winerror.ERROR_MAPPED_ALIGNMENT: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
90 winerror.ERROR_META_EXPANSION_TOO_LONG: errno.E2BIG, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
91 winerror.ERROR_MORE_DATA: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
92 winerror.ERROR_NEGATIVE_SEEK: errno.ESPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
93 winerror.ERROR_NOACCESS: errno.EFAULT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
94 winerror.ERROR_NONE_MAPPED: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
95 winerror.ERROR_NOT_ENOUGH_MEMORY: errno.ENOMEM, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
96 winerror.ERROR_NOT_READY: errno.EAGAIN, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
97 winerror.ERROR_NOT_SAME_DEVICE: errno.EXDEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
98 winerror.ERROR_NO_DATA: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
99 winerror.ERROR_NO_MORE_SEARCH_HANDLES: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
100 winerror.ERROR_NO_PROC_SLOTS: errno.EAGAIN, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
101 winerror.ERROR_NO_SUCH_PRIVILEGE: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
102 winerror.ERROR_OPEN_FAILED: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
103 winerror.ERROR_OPEN_FILES: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
104 winerror.ERROR_OPERATION_ABORTED: errno.EINTR, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
105 winerror.ERROR_OUTOFMEMORY: errno.ENOMEM, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
106 winerror.ERROR_PASSWORD_EXPIRED: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
107 winerror.ERROR_PATH_BUSY: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
108 winerror.ERROR_PATH_NOT_FOUND: errno.ENOTDIR, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
109 winerror.ERROR_PIPE_BUSY: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
110 winerror.ERROR_PIPE_CONNECTED: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
111 winerror.ERROR_PIPE_LISTENING: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
112 winerror.ERROR_PIPE_NOT_CONNECTED: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
113 winerror.ERROR_PRIVILEGE_NOT_HELD: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
114 winerror.ERROR_READ_FAULT: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
115 winerror.ERROR_SEEK: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
116 winerror.ERROR_SEEK_ON_DEVICE: errno.ESPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
117 winerror.ERROR_SHARING_BUFFER_EXCEEDED: errno.ENFILE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
118 winerror.ERROR_SHARING_VIOLATION: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
119 winerror.ERROR_STACK_OVERFLOW: errno.ENOMEM, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
120 winerror.ERROR_SWAPERROR: errno.ENOENT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
121 winerror.ERROR_TOO_MANY_MODULES: errno.EMFILE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
122 winerror.ERROR_TOO_MANY_OPEN_FILES: errno.EMFILE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
123 winerror.ERROR_UNRECOGNIZED_MEDIA: errno.ENXIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
124 winerror.ERROR_UNRECOGNIZED_VOLUME: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
125 winerror.ERROR_WAIT_NO_CHILDREN: errno.ECHILD, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
126 winerror.ERROR_WRITE_FAULT: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
127 winerror.ERROR_WRITE_PROTECT: errno.EROFS, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
128 } |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
129 |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
130 def __init__(self, err): |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
131 self.win_errno, self.win_function, self.win_strerror = err |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
132 OSError.__init__(self, self.winerror_map.get(self.win_errno, 0), |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
133 self.win_strerror) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
134 |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
135 def os_link(src, dst): |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
136 # NB will only succeed on NTFS |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
137 try: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
138 win32file.CreateHardLink(dst, src) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
139 except pywintypes.error, details: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
140 raise WinError(details) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
141 |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
142 def nlinks(pathname): |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
143 """Return number of hardlinks for the given file.""" |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
144 try: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
145 fh = win32file.CreateFile(pathname, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
146 win32file.GENERIC_READ, win32file.FILE_SHARE_READ, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
147 None, win32file.OPEN_EXISTING, 0, None) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
148 res = win32file.GetFileInformationByHandle(fh) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
149 fh.Close() |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
150 return res[7] |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
151 except pywintypes.error: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
152 return os.stat(pathname).st_nlink |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
153 |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
154 def testpid(pid): |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
155 '''return True if pid is still running or unable to |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
156 determine, False otherwise''' |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
157 try: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
158 handle = win32api.OpenProcess( |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
159 win32con.PROCESS_QUERY_INFORMATION, False, pid) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
160 if handle: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
161 status = win32process.GetExitCodeProcess(handle) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
162 return status == win32con.STILL_ACTIVE |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
163 except pywintypes.error, details: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
164 return details[0] != winerror.ERROR_INVALID_PARAMETER |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
165 return True |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
166 |
2117 | 167 def system_rcpath_win32(): |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
168 '''return default os-specific hgrc search path''' |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
169 proc = win32api.GetCurrentProcess() |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
170 filename = win32process.GetModuleFileNameEx(proc, 0) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
171 return [os.path.join(os.path.dirname(filename), 'mercurial.ini')] |