Show More
@@ -223,6 +223,24 except AttributeError: | |||||
223 | _kernel32.SetFileAttributesA.argtypes = [_LPCSTR, _DWORD] |
|
223 | _kernel32.SetFileAttributesA.argtypes = [_LPCSTR, _DWORD] | |
224 | _kernel32.SetFileAttributesA.restype = _BOOL |
|
224 | _kernel32.SetFileAttributesA.restype = _BOOL | |
225 |
|
225 | |||
|
226 | _DRIVE_UNKNOWN = 0 | |||
|
227 | _DRIVE_NO_ROOT_DIR = 1 | |||
|
228 | _DRIVE_REMOVABLE = 2 | |||
|
229 | _DRIVE_FIXED = 3 | |||
|
230 | _DRIVE_REMOTE = 4 | |||
|
231 | _DRIVE_CDROM = 5 | |||
|
232 | _DRIVE_RAMDISK = 6 | |||
|
233 | ||||
|
234 | _kernel32.GetDriveTypeA.argtypes = [_LPCSTR] | |||
|
235 | _kernel32.GetDriveTypeA.restype = _UINT | |||
|
236 | ||||
|
237 | _kernel32.GetVolumeInformationA.argtypes = [_LPCSTR, ctypes.c_void_p, _DWORD, | |||
|
238 | ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, _DWORD] | |||
|
239 | _kernel32.GetVolumeInformationA.restype = _BOOL | |||
|
240 | ||||
|
241 | _kernel32.GetVolumePathNameA.argtypes = [_LPCSTR, ctypes.c_void_p, _DWORD] | |||
|
242 | _kernel32.GetVolumePathNameA.restype = _BOOL | |||
|
243 | ||||
226 | _kernel32.OpenProcess.argtypes = [_DWORD, _BOOL, _DWORD] |
|
244 | _kernel32.OpenProcess.argtypes = [_DWORD, _BOOL, _DWORD] | |
227 | _kernel32.OpenProcess.restype = _HANDLE |
|
245 | _kernel32.OpenProcess.restype = _HANDLE | |
228 |
|
246 | |||
@@ -410,6 +428,37 def executablepath(): | |||||
410 | raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER) |
|
428 | raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER) | |
411 | return buf.value |
|
429 | return buf.value | |
412 |
|
430 | |||
|
431 | def getfstype(path): | |||
|
432 | """Get the filesystem type name from a directory or file (best-effort) | |||
|
433 | ||||
|
434 | Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. | |||
|
435 | """ | |||
|
436 | # realpath() calls GetFullPathName() | |||
|
437 | realpath = os.path.realpath(path) | |||
|
438 | ||||
|
439 | size = len(realpath) + 1 | |||
|
440 | buf = ctypes.create_string_buffer(size) | |||
|
441 | ||||
|
442 | if not _kernel32.GetVolumePathNameA(realpath, ctypes.byref(buf), size): | |||
|
443 | raise ctypes.WinError() # Note: WinError is a function | |||
|
444 | ||||
|
445 | t = _kernel32.GetDriveTypeA(buf.value) | |||
|
446 | ||||
|
447 | if t == _DRIVE_REMOTE: | |||
|
448 | return 'cifs' | |||
|
449 | elif t not in (_DRIVE_REMOVABLE, _DRIVE_FIXED, _DRIVE_CDROM, | |||
|
450 | _DRIVE_RAMDISK): | |||
|
451 | return None | |||
|
452 | ||||
|
453 | size = 256 | |||
|
454 | name = ctypes.create_string_buffer(size) | |||
|
455 | ||||
|
456 | if not _kernel32.GetVolumeInformationA(buf.value, None, 0, None, None, None, | |||
|
457 | ctypes.byref(name), size): | |||
|
458 | raise ctypes.WinError() # Note: WinError is a function | |||
|
459 | ||||
|
460 | return name.value | |||
|
461 | ||||
413 | def getuser(): |
|
462 | def getuser(): | |
414 | '''return name of current user''' |
|
463 | '''return name of current user''' | |
415 | size = _DWORD(300) |
|
464 | size = _DWORD(300) |
@@ -32,6 +32,7 except ImportError: | |||||
32 | osutil = policy.importmod(r'osutil') |
|
32 | osutil = policy.importmod(r'osutil') | |
33 |
|
33 | |||
34 | executablepath = win32.executablepath |
|
34 | executablepath = win32.executablepath | |
|
35 | getfstype = win32.getfstype | |||
35 | getuser = win32.getuser |
|
36 | getuser = win32.getuser | |
36 | hidewindow = win32.hidewindow |
|
37 | hidewindow = win32.hidewindow | |
37 | makedir = win32.makedir |
|
38 | makedir = win32.makedir | |
@@ -226,13 +227,6 def checkexec(path): | |||||
226 | def checklink(path): |
|
227 | def checklink(path): | |
227 | return False |
|
228 | return False | |
228 |
|
229 | |||
229 | def getfstype(dirpath): |
|
|||
230 | '''Get the filesystem type name from a directory (best-effort) |
|
|||
231 |
|
||||
232 | Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. |
|
|||
233 | ''' |
|
|||
234 | return None |
|
|||
235 |
|
||||
236 | def setbinary(fd): |
|
230 | def setbinary(fd): | |
237 | # When run without console, pipes may expose invalid |
|
231 | # When run without console, pipes may expose invalid | |
238 | # fileno(), usually set to -1. |
|
232 | # fileno(), usually set to -1. |
General Comments 0
You need to be logged in to leave comments.
Login now