author | Patrick Mezard <pmezard@gmail.com> |
Wed, 22 Apr 2009 23:13:39 +0200 | |
changeset 8120 | 2b36ed5c1911 |
parent 7948 | de377b1a9a84 |
child 8225 | 46293a0c7e9f |
permissions | -rw-r--r-- |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
1 |
''' |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
2 |
win32.py - utility functions that use win32 API |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
3 |
|
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
4 |
Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
5 |
|
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
6 |
This software may be used and distributed according to the terms of |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
7 |
the GNU General Public License, incorporated herein by reference. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
8 |
|
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
9 |
Mark Hammond's win32all package allows better functionality on |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
10 |
Windows. this module overrides definitions in util.py. if not |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
11 |
available, import of this module will fail, and generic code will be |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
12 |
used. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
13 |
''' |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
14 |
|
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
15 |
import win32api |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
16 |
|
6216 | 17 |
import errno, os, sys, pywintypes, win32con, win32file, win32process |
3877
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3721
diff
changeset
|
18 |
import cStringIO, winerror |
7948
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7890
diff
changeset
|
19 |
import osutil, encoding |
6881
d2375bbee6d4
Folding correction and missing import
Remy Roy <remyroy@remyroy.com>
parents:
6880
diff
changeset
|
20 |
import util |
3877
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3721
diff
changeset
|
21 |
from win32com.shell import shell,shellcon |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
22 |
|
7473
5185a24ce04e
exceptions should inherit the Exception class
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7427
diff
changeset
|
23 |
class WinError(Exception): |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
24 |
winerror_map = { |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
25 |
winerror.ERROR_ACCESS_DENIED: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
26 |
winerror.ERROR_ACCOUNT_DISABLED: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
27 |
winerror.ERROR_ACCOUNT_RESTRICTION: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
28 |
winerror.ERROR_ALREADY_ASSIGNED: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
29 |
winerror.ERROR_ALREADY_EXISTS: errno.EEXIST, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
30 |
winerror.ERROR_ARITHMETIC_OVERFLOW: errno.ERANGE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
31 |
winerror.ERROR_BAD_COMMAND: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
32 |
winerror.ERROR_BAD_DEVICE: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
33 |
winerror.ERROR_BAD_DRIVER_LEVEL: errno.ENXIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
34 |
winerror.ERROR_BAD_EXE_FORMAT: errno.ENOEXEC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
35 |
winerror.ERROR_BAD_FORMAT: errno.ENOEXEC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
36 |
winerror.ERROR_BAD_LENGTH: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
37 |
winerror.ERROR_BAD_PATHNAME: errno.ENOENT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
38 |
winerror.ERROR_BAD_PIPE: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
39 |
winerror.ERROR_BAD_UNIT: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
40 |
winerror.ERROR_BAD_USERNAME: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
41 |
winerror.ERROR_BROKEN_PIPE: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
42 |
winerror.ERROR_BUFFER_OVERFLOW: errno.ENAMETOOLONG, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
43 |
winerror.ERROR_BUSY: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
44 |
winerror.ERROR_BUSY_DRIVE: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
45 |
winerror.ERROR_CALL_NOT_IMPLEMENTED: errno.ENOSYS, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
46 |
winerror.ERROR_CANNOT_MAKE: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
47 |
winerror.ERROR_CANTOPEN: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
48 |
winerror.ERROR_CANTREAD: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
49 |
winerror.ERROR_CANTWRITE: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
50 |
winerror.ERROR_CRC: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
51 |
winerror.ERROR_CURRENT_DIRECTORY: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
52 |
winerror.ERROR_DEVICE_IN_USE: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
53 |
winerror.ERROR_DEV_NOT_EXIST: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
54 |
winerror.ERROR_DIRECTORY: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
55 |
winerror.ERROR_DIR_NOT_EMPTY: errno.ENOTEMPTY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
56 |
winerror.ERROR_DISK_CHANGE: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
57 |
winerror.ERROR_DISK_FULL: errno.ENOSPC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
58 |
winerror.ERROR_DRIVE_LOCKED: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
59 |
winerror.ERROR_ENVVAR_NOT_FOUND: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
60 |
winerror.ERROR_EXE_MARKED_INVALID: errno.ENOEXEC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
61 |
winerror.ERROR_FILENAME_EXCED_RANGE: errno.ENAMETOOLONG, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
62 |
winerror.ERROR_FILE_EXISTS: errno.EEXIST, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
63 |
winerror.ERROR_FILE_INVALID: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
64 |
winerror.ERROR_FILE_NOT_FOUND: errno.ENOENT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
65 |
winerror.ERROR_GEN_FAILURE: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
66 |
winerror.ERROR_HANDLE_DISK_FULL: errno.ENOSPC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
67 |
winerror.ERROR_INSUFFICIENT_BUFFER: errno.ENOMEM, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
68 |
winerror.ERROR_INVALID_ACCESS: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
69 |
winerror.ERROR_INVALID_ADDRESS: errno.EFAULT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
70 |
winerror.ERROR_INVALID_BLOCK: errno.EFAULT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
71 |
winerror.ERROR_INVALID_DATA: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
72 |
winerror.ERROR_INVALID_DRIVE: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
73 |
winerror.ERROR_INVALID_EXE_SIGNATURE: errno.ENOEXEC, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
74 |
winerror.ERROR_INVALID_FLAGS: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
75 |
winerror.ERROR_INVALID_FUNCTION: errno.ENOSYS, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
76 |
winerror.ERROR_INVALID_HANDLE: errno.EBADF, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
77 |
winerror.ERROR_INVALID_LOGON_HOURS: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
78 |
winerror.ERROR_INVALID_NAME: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
79 |
winerror.ERROR_INVALID_OWNER: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
80 |
winerror.ERROR_INVALID_PARAMETER: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
81 |
winerror.ERROR_INVALID_PASSWORD: errno.EPERM, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
82 |
winerror.ERROR_INVALID_PRIMARY_GROUP: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
83 |
winerror.ERROR_INVALID_SIGNAL_NUMBER: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
84 |
winerror.ERROR_INVALID_TARGET_HANDLE: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
85 |
winerror.ERROR_INVALID_WORKSTATION: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
86 |
winerror.ERROR_IO_DEVICE: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
87 |
winerror.ERROR_IO_INCOMPLETE: errno.EINTR, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
88 |
winerror.ERROR_LOCKED: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
89 |
winerror.ERROR_LOCK_VIOLATION: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
90 |
winerror.ERROR_LOGON_FAILURE: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
91 |
winerror.ERROR_MAPPED_ALIGNMENT: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
92 |
winerror.ERROR_META_EXPANSION_TOO_LONG: errno.E2BIG, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
93 |
winerror.ERROR_MORE_DATA: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
94 |
winerror.ERROR_NEGATIVE_SEEK: errno.ESPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
95 |
winerror.ERROR_NOACCESS: errno.EFAULT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
96 |
winerror.ERROR_NONE_MAPPED: errno.EINVAL, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
97 |
winerror.ERROR_NOT_ENOUGH_MEMORY: errno.ENOMEM, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
98 |
winerror.ERROR_NOT_READY: errno.EAGAIN, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
99 |
winerror.ERROR_NOT_SAME_DEVICE: errno.EXDEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
100 |
winerror.ERROR_NO_DATA: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
101 |
winerror.ERROR_NO_MORE_SEARCH_HANDLES: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
102 |
winerror.ERROR_NO_PROC_SLOTS: errno.EAGAIN, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
103 |
winerror.ERROR_NO_SUCH_PRIVILEGE: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
104 |
winerror.ERROR_OPEN_FAILED: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
105 |
winerror.ERROR_OPEN_FILES: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
106 |
winerror.ERROR_OPERATION_ABORTED: errno.EINTR, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
107 |
winerror.ERROR_OUTOFMEMORY: errno.ENOMEM, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
108 |
winerror.ERROR_PASSWORD_EXPIRED: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
109 |
winerror.ERROR_PATH_BUSY: errno.EBUSY, |
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
110 |
winerror.ERROR_PATH_NOT_FOUND: errno.ENOENT, |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
111 |
winerror.ERROR_PIPE_BUSY: errno.EBUSY, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
112 |
winerror.ERROR_PIPE_CONNECTED: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
113 |
winerror.ERROR_PIPE_LISTENING: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
114 |
winerror.ERROR_PIPE_NOT_CONNECTED: errno.EPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
115 |
winerror.ERROR_PRIVILEGE_NOT_HELD: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
116 |
winerror.ERROR_READ_FAULT: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
117 |
winerror.ERROR_SEEK: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
118 |
winerror.ERROR_SEEK_ON_DEVICE: errno.ESPIPE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
119 |
winerror.ERROR_SHARING_BUFFER_EXCEEDED: errno.ENFILE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
120 |
winerror.ERROR_SHARING_VIOLATION: errno.EACCES, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
121 |
winerror.ERROR_STACK_OVERFLOW: errno.ENOMEM, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
122 |
winerror.ERROR_SWAPERROR: errno.ENOENT, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
123 |
winerror.ERROR_TOO_MANY_MODULES: errno.EMFILE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
124 |
winerror.ERROR_TOO_MANY_OPEN_FILES: errno.EMFILE, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
125 |
winerror.ERROR_UNRECOGNIZED_MEDIA: errno.ENXIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
126 |
winerror.ERROR_UNRECOGNIZED_VOLUME: errno.ENODEV, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
127 |
winerror.ERROR_WAIT_NO_CHILDREN: errno.ECHILD, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
128 |
winerror.ERROR_WRITE_FAULT: errno.EIO, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
129 |
winerror.ERROR_WRITE_PROTECT: errno.EROFS, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
130 |
} |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
131 |
|
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
132 |
def __init__(self, err): |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
133 |
self.win_errno, self.win_function, self.win_strerror = err |
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
134 |
if self.win_strerror.endswith('.'): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
135 |
self.win_strerror = self.win_strerror[:-1] |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
136 |
|
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
137 |
class WinIOError(WinError, IOError): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
138 |
def __init__(self, err, filename=None): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
139 |
WinError.__init__(self, err) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
140 |
IOError.__init__(self, self.winerror_map.get(self.win_errno, 0), |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
141 |
self.win_strerror) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
142 |
self.filename = filename |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
143 |
|
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
144 |
class WinOSError(WinError, OSError): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
145 |
def __init__(self, err): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
146 |
WinError.__init__(self, err) |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
147 |
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
|
148 |
self.win_strerror) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
149 |
|
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
150 |
def os_link(src, dst): |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
151 |
try: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
152 |
win32file.CreateHardLink(dst, src) |
5879
cacfeee38870
util_win32: make os_link more robust (issue 761)
Patrick Mezard <pmezard@gmail.com>
parents:
5611
diff
changeset
|
153 |
# CreateHardLink sometimes succeeds on mapped drives but |
cacfeee38870
util_win32: make os_link more robust (issue 761)
Patrick Mezard <pmezard@gmail.com>
parents:
5611
diff
changeset
|
154 |
# following nlinks() returns 1. Check it now and bail out. |
cacfeee38870
util_win32: make os_link more robust (issue 761)
Patrick Mezard <pmezard@gmail.com>
parents:
5611
diff
changeset
|
155 |
if nlinks(src) < 2: |
cacfeee38870
util_win32: make os_link more robust (issue 761)
Patrick Mezard <pmezard@gmail.com>
parents:
5611
diff
changeset
|
156 |
try: |
cacfeee38870
util_win32: make os_link more robust (issue 761)
Patrick Mezard <pmezard@gmail.com>
parents:
5611
diff
changeset
|
157 |
win32file.DeleteFile(dst) |
cacfeee38870
util_win32: make os_link more robust (issue 761)
Patrick Mezard <pmezard@gmail.com>
parents:
5611
diff
changeset
|
158 |
except: |
cacfeee38870
util_win32: make os_link more robust (issue 761)
Patrick Mezard <pmezard@gmail.com>
parents:
5611
diff
changeset
|
159 |
pass |
cacfeee38870
util_win32: make os_link more robust (issue 761)
Patrick Mezard <pmezard@gmail.com>
parents:
5611
diff
changeset
|
160 |
# Fake hardlinking error |
cacfeee38870
util_win32: make os_link more robust (issue 761)
Patrick Mezard <pmezard@gmail.com>
parents:
5611
diff
changeset
|
161 |
raise WinOSError((18, 'CreateHardLink', 'The system cannot ' |
cacfeee38870
util_win32: make os_link more robust (issue 761)
Patrick Mezard <pmezard@gmail.com>
parents:
5611
diff
changeset
|
162 |
'move the file to a different disk drive')) |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
163 |
except pywintypes.error, details: |
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
164 |
raise WinOSError(details) |
7778
82f7145b304c
Don't fail on clone on win98 (issue1492)
Matt Mackall <mpm@selenic.com>
parents:
7473
diff
changeset
|
165 |
except NotImplementedError: # Another fake error win Win98 |
82f7145b304c
Don't fail on clone on win98 (issue1492)
Matt Mackall <mpm@selenic.com>
parents:
7473
diff
changeset
|
166 |
raise WinOSError((18, 'CreateHardLink', 'Hardlinking not supported')) |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
167 |
|
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
168 |
def nlinks(pathname): |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
169 |
"""Return number of hardlinks for the given file.""" |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
170 |
try: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
171 |
fh = win32file.CreateFile(pathname, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
172 |
win32file.GENERIC_READ, win32file.FILE_SHARE_READ, |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
173 |
None, win32file.OPEN_EXISTING, 0, None) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
174 |
res = win32file.GetFileInformationByHandle(fh) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
175 |
fh.Close() |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
176 |
return res[7] |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
177 |
except pywintypes.error: |
2448
b77a2ef61b81
replace os.stat with os.lstat in some where.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2313
diff
changeset
|
178 |
return os.lstat(pathname).st_nlink |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
179 |
|
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
180 |
def testpid(pid): |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
181 |
'''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
|
182 |
determine, False otherwise''' |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
183 |
try: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
184 |
handle = win32api.OpenProcess( |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
185 |
win32con.PROCESS_QUERY_INFORMATION, False, pid) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
186 |
if handle: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
187 |
status = win32process.GetExitCodeProcess(handle) |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
188 |
return status == win32con.STILL_ACTIVE |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
189 |
except pywintypes.error, details: |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
190 |
return details[0] != winerror.ERROR_INVALID_PARAMETER |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
191 |
return True |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
192 |
|
6006
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
193 |
def lookup_reg(key, valname=None, scope=None): |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
194 |
''' Look up a key/value name in the Windows registry. |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
195 |
|
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
196 |
valname: value name. If unspecified, the default value for the key |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
197 |
is used. |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
198 |
scope: optionally specify scope for registry lookup, this can be |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
199 |
a sequence of scopes to look up in order. Default (CURRENT_USER, |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
200 |
LOCAL_MACHINE). |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
201 |
''' |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
202 |
try: |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
203 |
from _winreg import HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, \ |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
204 |
QueryValueEx, OpenKey |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
205 |
except ImportError: |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
206 |
return None |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
207 |
|
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
208 |
if scope is None: |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
209 |
scope = (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE) |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
210 |
elif not isinstance(scope, (list, tuple)): |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
211 |
scope = (scope,) |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
212 |
for s in scope: |
6880
892806b3fc0f
util: disinfect lookup_reg strings (issue1126)
Matt Mackall <mpm@selenic.com>
parents:
6216
diff
changeset
|
213 |
try: |
6881
d2375bbee6d4
Folding correction and missing import
Remy Roy <remyroy@remyroy.com>
parents:
6880
diff
changeset
|
214 |
val = QueryValueEx(OpenKey(s, key), valname)[0] |
6880
892806b3fc0f
util: disinfect lookup_reg strings (issue1126)
Matt Mackall <mpm@selenic.com>
parents:
6216
diff
changeset
|
215 |
# never let a Unicode string escape into the wild |
7948
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7890
diff
changeset
|
216 |
return encoding.tolocal(val.encode('UTF-8')) |
6880
892806b3fc0f
util: disinfect lookup_reg strings (issue1126)
Matt Mackall <mpm@selenic.com>
parents:
6216
diff
changeset
|
217 |
except EnvironmentError: |
892806b3fc0f
util: disinfect lookup_reg strings (issue1126)
Matt Mackall <mpm@selenic.com>
parents:
6216
diff
changeset
|
218 |
pass |
6006
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
5969
diff
changeset
|
219 |
|
2117 | 220 |
def system_rcpath_win32(): |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
221 |
'''return default os-specific hgrc search path''' |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
222 |
proc = win32api.GetCurrentProcess() |
2285
0912f807b7ff
win98: fall back to win32api.GetModuleFileName if needed.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2284
diff
changeset
|
223 |
try: |
0912f807b7ff
win98: fall back to win32api.GetModuleFileName if needed.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2284
diff
changeset
|
224 |
# This will fail on windows < NT |
0912f807b7ff
win98: fall back to win32api.GetModuleFileName if needed.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2284
diff
changeset
|
225 |
filename = win32process.GetModuleFileNameEx(proc, 0) |
0912f807b7ff
win98: fall back to win32api.GetModuleFileName if needed.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2284
diff
changeset
|
226 |
except: |
0912f807b7ff
win98: fall back to win32api.GetModuleFileName if needed.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2284
diff
changeset
|
227 |
filename = win32api.GetModuleFileName(0) |
5619
55d3e845736a
win32: favor local mercurial.ini over registry key
Steve Borho <steve@borho.org>
parents:
5612
diff
changeset
|
228 |
# Use mercurial.ini found in directory with hg.exe |
55d3e845736a
win32: favor local mercurial.ini over registry key
Steve Borho <steve@borho.org>
parents:
5612
diff
changeset
|
229 |
progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') |
55d3e845736a
win32: favor local mercurial.ini over registry key
Steve Borho <steve@borho.org>
parents:
5612
diff
changeset
|
230 |
if os.path.isfile(progrc): |
55d3e845736a
win32: favor local mercurial.ini over registry key
Steve Borho <steve@borho.org>
parents:
5612
diff
changeset
|
231 |
return [progrc] |
55d3e845736a
win32: favor local mercurial.ini over registry key
Steve Borho <steve@borho.org>
parents:
5612
diff
changeset
|
232 |
# else look for a system rcpath in the registry |
5583
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
233 |
try: |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
234 |
value = win32api.RegQueryValue( |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
235 |
win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Mercurial') |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
236 |
rcpath = [] |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
237 |
for p in value.split(os.pathsep): |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
238 |
if p.lower().endswith('mercurial.ini'): |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
239 |
rcpath.append(p) |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
240 |
elif os.path.isdir(p): |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
241 |
for f, kind in osutil.listdir(p): |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
242 |
if f.endswith('.rc'): |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
243 |
rcpath.append(os.path.join(p, f)) |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
244 |
return rcpath |
1b5b81d9039b
win32: read system rcpath from registry
Steve Borho <steve@borho.org>
parents:
4998
diff
changeset
|
245 |
except pywintypes.error: |
5619
55d3e845736a
win32: favor local mercurial.ini over registry key
Steve Borho <steve@borho.org>
parents:
5612
diff
changeset
|
246 |
return [] |
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
247 |
|
4098
c08b6af023bc
util_win32.py: fix user_rcpath
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3891
diff
changeset
|
248 |
def user_rcpath_win32(): |
2284
d6392a7c03dd
On win98 os.path.expanuser('~') does not result in a useable directory.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2250
diff
changeset
|
249 |
'''return os-specific hgrc search path to the user dir''' |
d6392a7c03dd
On win98 os.path.expanuser('~') does not result in a useable directory.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2250
diff
changeset
|
250 |
userdir = os.path.expanduser('~') |
7427
f21e3d0e335b
util_win32: fix Windows version checking (issue1358)
Patrick Mezard <pmezard@gmail.com>
parents:
7390
diff
changeset
|
251 |
if sys.getwindowsversion()[3] != 2 and userdir == '~': |
2284
d6392a7c03dd
On win98 os.path.expanuser('~') does not result in a useable directory.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2250
diff
changeset
|
252 |
# We are on win < nt: fetch the APPDATA directory location and use |
d6392a7c03dd
On win98 os.path.expanuser('~') does not result in a useable directory.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2250
diff
changeset
|
253 |
# the parent directory as the user home dir. |
d6392a7c03dd
On win98 os.path.expanuser('~') does not result in a useable directory.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2250
diff
changeset
|
254 |
appdir = shell.SHGetPathFromIDList( |
2313
a600d9997521
Fixed typo (qshell instead of shell) in win98 code (see issue244).
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2285
diff
changeset
|
255 |
shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_APPDATA)) |
2284
d6392a7c03dd
On win98 os.path.expanuser('~') does not result in a useable directory.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2250
diff
changeset
|
256 |
userdir = os.path.dirname(appdir) |
6153
09a8be3e5bfb
Also search for .hgrc if mercurial.ini not found on windows
Stefan Rank <strank(AT)strank(DOT)info>
parents:
6012
diff
changeset
|
257 |
return [os.path.join(userdir, 'mercurial.ini'), |
09a8be3e5bfb
Also search for .hgrc if mercurial.ini not found on windows
Stefan Rank <strank(AT)strank(DOT)info>
parents:
6012
diff
changeset
|
258 |
os.path.join(userdir, '.hgrc')] |
2284
d6392a7c03dd
On win98 os.path.expanuser('~') does not result in a useable directory.
Volker Kleinfeld <Volker.Kleinfeld@gmx.de>
parents:
2250
diff
changeset
|
259 |
|
2250
45aef5ddcdbe
windows: revlog.lazyparser not always safe to use.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2243
diff
changeset
|
260 |
class posixfile_nt(object): |
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
261 |
'''file object with posix-like semantics. on windows, normal |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
262 |
files can not be deleted or renamed if they are open. must open |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
263 |
with win32file.FILE_SHARE_DELETE. this flag does not exist on |
2250
45aef5ddcdbe
windows: revlog.lazyparser not always safe to use.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2243
diff
changeset
|
264 |
windows < nt, so do not use this class there.''' |
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
265 |
|
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
266 |
# tried to use win32file._open_osfhandle to pass fd to os.fdopen, |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
267 |
# but does not work at all. wrap win32 file api instead. |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
268 |
|
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
269 |
def __init__(self, name, mode='rb'): |
5840
c67dfc4ecba6
posixfile_nt: set closed early
Matt Mackall <mpm@selenic.com>
parents:
5619
diff
changeset
|
270 |
self.closed = False |
c67dfc4ecba6
posixfile_nt: set closed early
Matt Mackall <mpm@selenic.com>
parents:
5619
diff
changeset
|
271 |
self.name = name |
c67dfc4ecba6
posixfile_nt: set closed early
Matt Mackall <mpm@selenic.com>
parents:
5619
diff
changeset
|
272 |
self.mode = mode |
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
273 |
access = 0 |
4998
81f8ff2a9bf2
posixfile_nt: '+' should allow read access.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
4921
diff
changeset
|
274 |
if 'r' in mode or '+' in mode: |
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
275 |
access |= win32file.GENERIC_READ |
4921
8a53b39cd402
posixfile_nt: '+' was understood as read mode instead of update.
Patrick Mezard <pmezard@gmail.com>
parents:
4803
diff
changeset
|
276 |
if 'w' in mode or 'a' in mode or '+' in mode: |
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
277 |
access |= win32file.GENERIC_WRITE |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
278 |
if 'r' in mode: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
279 |
creation = win32file.OPEN_EXISTING |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
280 |
elif 'a' in mode: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
281 |
creation = win32file.OPEN_ALWAYS |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
282 |
else: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
283 |
creation = win32file.CREATE_ALWAYS |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
284 |
try: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
285 |
self.handle = win32file.CreateFile(name, |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
286 |
access, |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
287 |
win32file.FILE_SHARE_READ | |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
288 |
win32file.FILE_SHARE_WRITE | |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
289 |
win32file.FILE_SHARE_DELETE, |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
290 |
None, |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
291 |
creation, |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
292 |
win32file.FILE_ATTRIBUTE_NORMAL, |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
293 |
0) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
294 |
except pywintypes.error, err: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
295 |
raise WinIOError(err, name) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
296 |
|
2243
caf2c6ef5b0e
The posixfile implemented using the win32 API should be iterable.
Christian Boos <cboos@neuf.fr>
parents:
2176
diff
changeset
|
297 |
def __iter__(self): |
7390
0d1c770c6be1
util_win32: implement posixfile_nt.readlines()
Patrick Mezard <pmezard@gmail.com>
parents:
6881
diff
changeset
|
298 |
for line in self.readlines(): |
2243
caf2c6ef5b0e
The posixfile implemented using the win32 API should be iterable.
Christian Boos <cboos@neuf.fr>
parents:
2176
diff
changeset
|
299 |
yield line |
caf2c6ef5b0e
The posixfile implemented using the win32 API should be iterable.
Christian Boos <cboos@neuf.fr>
parents:
2176
diff
changeset
|
300 |
|
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
301 |
def read(self, count=-1): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
302 |
try: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
303 |
cs = cStringIO.StringIO() |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
304 |
while count: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
305 |
wincount = int(count) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
306 |
if wincount == -1: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
307 |
wincount = 1048576 |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
308 |
val, data = win32file.ReadFile(self.handle, wincount) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
309 |
if not data: break |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
310 |
cs.write(data) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
311 |
if count != -1: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
312 |
count -= len(data) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
313 |
return cs.getvalue() |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
314 |
except pywintypes.error, err: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
315 |
raise WinIOError(err) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
316 |
|
7390
0d1c770c6be1
util_win32: implement posixfile_nt.readlines()
Patrick Mezard <pmezard@gmail.com>
parents:
6881
diff
changeset
|
317 |
def readlines(self, sizehint=None): |
0d1c770c6be1
util_win32: implement posixfile_nt.readlines()
Patrick Mezard <pmezard@gmail.com>
parents:
6881
diff
changeset
|
318 |
# splitlines() splits on single '\r' while readlines() |
0d1c770c6be1
util_win32: implement posixfile_nt.readlines()
Patrick Mezard <pmezard@gmail.com>
parents:
6881
diff
changeset
|
319 |
# does not. cStringIO has a well behaving readlines() and is fast. |
0d1c770c6be1
util_win32: implement posixfile_nt.readlines()
Patrick Mezard <pmezard@gmail.com>
parents:
6881
diff
changeset
|
320 |
return cStringIO.StringIO(self.read()).readlines() |
0d1c770c6be1
util_win32: implement posixfile_nt.readlines()
Patrick Mezard <pmezard@gmail.com>
parents:
6881
diff
changeset
|
321 |
|
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
322 |
def write(self, data): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
323 |
try: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
324 |
if 'a' in self.mode: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
325 |
win32file.SetFilePointer(self.handle, 0, win32file.FILE_END) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
326 |
nwrit = 0 |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
327 |
while nwrit < len(data): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
328 |
val, nwrit = win32file.WriteFile(self.handle, data) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
329 |
data = data[nwrit:] |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
330 |
except pywintypes.error, err: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
331 |
raise WinIOError(err) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
332 |
|
5847
e52383c7e7ab
util_win32: implement posixfile_nt.writelines()
Patrick Mezard <pmezard@gmail.com>
parents:
5619
diff
changeset
|
333 |
def writelines(self, sequence): |
e52383c7e7ab
util_win32: implement posixfile_nt.writelines()
Patrick Mezard <pmezard@gmail.com>
parents:
5619
diff
changeset
|
334 |
for s in sequence: |
e52383c7e7ab
util_win32: implement posixfile_nt.writelines()
Patrick Mezard <pmezard@gmail.com>
parents:
5619
diff
changeset
|
335 |
self.write(s) |
e52383c7e7ab
util_win32: implement posixfile_nt.writelines()
Patrick Mezard <pmezard@gmail.com>
parents:
5619
diff
changeset
|
336 |
|
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
337 |
def seek(self, pos, whence=0): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
338 |
try: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
339 |
win32file.SetFilePointer(self.handle, int(pos), whence) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
340 |
except pywintypes.error, err: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
341 |
raise WinIOError(err) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
342 |
|
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
343 |
def tell(self): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
344 |
try: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
345 |
return win32file.SetFilePointer(self.handle, 0, |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
346 |
win32file.FILE_CURRENT) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
347 |
except pywintypes.error, err: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
348 |
raise WinIOError(err) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
349 |
|
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
350 |
def close(self): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
351 |
if not self.closed: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
352 |
self.handle = None |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
353 |
self.closed = True |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
354 |
|
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
355 |
def flush(self): |
5935
0973501e5f4a
win32: remove excessive flushing
Matt Mackall <mpm@selenic.com>
parents:
5879
diff
changeset
|
356 |
# we have no application-level buffering |
0973501e5f4a
win32: remove excessive flushing
Matt Mackall <mpm@selenic.com>
parents:
5879
diff
changeset
|
357 |
pass |
2176
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
358 |
|
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
359 |
def truncate(self, pos=0): |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
360 |
try: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
361 |
win32file.SetFilePointer(self.handle, int(pos), |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
362 |
win32file.FILE_BEGIN) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
363 |
win32file.SetEndOfFile(self.handle) |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
364 |
except pywintypes.error, err: |
9b42304d9896
fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2117
diff
changeset
|
365 |
raise WinIOError(err) |
3721
98f2507c5551
only print a warning when no username is specified
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3466
diff
changeset
|
366 |
|
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
367 |
def getuser(): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
368 |
'''return name of current user''' |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
369 |
return win32api.GetUserName() |
4672
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
370 |
|
4803
7549cd526b7f
Fix serve on Windows without win32* modules.
Nathan Jones <nathanj@insightbb.com>
parents:
4672
diff
changeset
|
371 |
def set_signal_handler_win32(): |
4672
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
372 |
"""Register a termination handler for console events including |
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
373 |
CTRL+C. python signal handlers do not work well with socket |
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
374 |
operations. |
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
375 |
""" |
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
376 |
def handler(event): |
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
377 |
win32process.ExitProcess(1) |
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
378 |
win32api.SetConsoleCtrlHandler(handler) |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
379 |