[PATCH STABLE] windows: make win32 mandatory (issue1922)
Adrian Buehlmann
adrian at cadifra.com
Thu Jan 20 19:04:11 UTC 2011
On 2011-01-20 19:59, Aaron Cohen wrote:
> Would using ctypes directly help?
Yeah. ctypes are cool. But they require python 2.5.
> Such as, for instance:
>
> import ctypes
>
> class FILETIME(ctypes.Structure):
> _fields_ = [
> ('dwLowDateTime', ctypes.c_uint),
> ('dwHighDateTime', ctypes.c_uint),
> ]
>
> class BY_HANDLE_FILE_INFORMATION(ctypes.Structure):
> _fields_ = [
> ('dwFileAttributes', ctypes.c_uint),
> ('ftCreationTime', FILETIME),
> ('ftLastAccessTime', FILETIME),
> ('ftLastWriteTime', FILETIME),
> ('dwVolumeSerialNumber', ctypes.c_uint),
> ('nFileSizeHigh', ctypes.c_uint),
> ('nFileSizeLow', ctypes.c_uint),
> ('nNumberOfLinks', ctypes.c_uint),
> ('nFileIndexHigh', ctypes.c_uint),
> ('nFileIndexLow', ctypes.c_uint),
> ]
>
> _GENERIC_READ = 0x80000000
>
> _FILE_SHARE_READ = 0x00000001
>
> _OPEN_EXISTING = 3
>
> def _getfileinfo(pathname):
> if isinstance(pathname, str):
> #TODO: I'm not sure how mercurial likes to do this
> pathname = unicode(pathname)
>
> fh = ctypes.windll.kernel32.CreateFileW(pathname,
> _GENERIC_READ, _FILE_SHARE_READ,
> None, _OPEN_EXISTING, 0, None)
> if fh == -1:
> raise OSError(errno.ENOENT, 'The system cannot find the file specified')
>
> info = BY_HANDLE_FILE_INFORMATION()
> # TODO: Raise an appropriate exception if this returns true
> ctypes.windll.kernel32.GetFileInformationByHandle(fh,
> ctypes.pointer(info))
> return info
>
> def nlinks(pathname):
> return _getfileinfo(pathname).nNumberOfLinks
>
>
More information about the Mercurial-devel
mailing list