comparison mercurial/win32.py @ 24418:a2285e2fc949 stable

win32: 'raise ctypes.WinError' -> 'raise ctypes.WinError()' WinError is a function that creates an Error, not an Error itself. This is a partial backout of e34106fa0dc3.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 22 Mar 2015 19:08:13 -0400
parents 4898c37e03c0
children f2b87f4856bf
comparison
equal deleted inserted replaced
24412:9372180b8c9b 24418:a2285e2fc949
277 '''return full path of hg.exe''' 277 '''return full path of hg.exe'''
278 size = 600 278 size = 600
279 buf = ctypes.create_string_buffer(size + 1) 279 buf = ctypes.create_string_buffer(size + 1)
280 len = _kernel32.GetModuleFileNameA(None, ctypes.byref(buf), size) 280 len = _kernel32.GetModuleFileNameA(None, ctypes.byref(buf), size)
281 if len == 0: 281 if len == 0:
282 raise ctypes.WinError 282 raise ctypes.WinError()
283 elif len == size: 283 elif len == size:
284 raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER) 284 raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER)
285 return buf.value 285 return buf.value
286 286
287 def getuser(): 287 def getuser():
288 '''return name of current user''' 288 '''return name of current user'''
289 size = _DWORD(300) 289 size = _DWORD(300)
290 buf = ctypes.create_string_buffer(size.value + 1) 290 buf = ctypes.create_string_buffer(size.value + 1)
291 if not _advapi32.GetUserNameA(ctypes.byref(buf), ctypes.byref(size)): 291 if not _advapi32.GetUserNameA(ctypes.byref(buf), ctypes.byref(size)):
292 raise ctypes.WinError 292 raise ctypes.WinError()
293 return buf.value 293 return buf.value
294 294
295 _signalhandler = [] 295 _signalhandler = []
296 296
297 def setsignalhandler(): 297 def setsignalhandler():
305 if _signalhandler: 305 if _signalhandler:
306 return # already registered 306 return # already registered
307 h = _SIGNAL_HANDLER(handler) 307 h = _SIGNAL_HANDLER(handler)
308 _signalhandler.append(h) # needed to prevent garbage collection 308 _signalhandler.append(h) # needed to prevent garbage collection
309 if not _kernel32.SetConsoleCtrlHandler(h, True): 309 if not _kernel32.SetConsoleCtrlHandler(h, True):
310 raise ctypes.WinError 310 raise ctypes.WinError()
311 311
312 def hidewindow(): 312 def hidewindow():
313 313
314 def callback(hwnd, pid): 314 def callback(hwnd, pid):
315 wpid = _DWORD() 315 wpid = _DWORD()
347 pe = _tagPROCESSENTRY32() 347 pe = _tagPROCESSENTRY32()
348 348
349 # create handle to list all processes 349 # create handle to list all processes
350 ph = _kernel32.CreateToolhelp32Snapshot(_TH32CS_SNAPPROCESS, 0) 350 ph = _kernel32.CreateToolhelp32Snapshot(_TH32CS_SNAPPROCESS, 0)
351 if ph == _INVALID_HANDLE_VALUE: 351 if ph == _INVALID_HANDLE_VALUE:
352 raise ctypes.WinError 352 raise ctypes.WinError()
353 try: 353 try:
354 r = _kernel32.Process32First(ph, ctypes.byref(pe)) 354 r = _kernel32.Process32First(ph, ctypes.byref(pe))
355 # loop over all processes 355 # loop over all processes
356 while r: 356 while r:
357 if pe.th32ParentProcessID == pid: 357 if pe.th32ParentProcessID == pid:
359 return pe.th32ProcessID 359 return pe.th32ProcessID
360 r = _kernel32.Process32Next(ph, ctypes.byref(pe)) 360 r = _kernel32.Process32Next(ph, ctypes.byref(pe))
361 finally: 361 finally:
362 _kernel32.CloseHandle(ph) 362 _kernel32.CloseHandle(ph)
363 if _kernel32.GetLastError() != _ERROR_NO_MORE_FILES: 363 if _kernel32.GetLastError() != _ERROR_NO_MORE_FILES:
364 raise ctypes.WinError 364 raise ctypes.WinError()
365 return None # no child found 365 return None # no child found
366 366
367 class _tochildpid(int): # pid is _DWORD, which always matches in an int 367 class _tochildpid(int): # pid is _DWORD, which always matches in an int
368 '''helper for spawndetached, returns the child pid on conversion to string 368 '''helper for spawndetached, returns the child pid on conversion to string
369 369
411 411
412 res = _kernel32.CreateProcessA( 412 res = _kernel32.CreateProcessA(
413 None, args, None, None, False, _CREATE_NO_WINDOW, 413 None, args, None, None, False, _CREATE_NO_WINDOW,
414 env, os.getcwd(), ctypes.byref(si), ctypes.byref(pi)) 414 env, os.getcwd(), ctypes.byref(si), ctypes.byref(pi))
415 if not res: 415 if not res:
416 raise ctypes.WinError 416 raise ctypes.WinError()
417 417
418 # _tochildpid because the process is the child of COMSPEC 418 # _tochildpid because the process is the child of COMSPEC
419 return _tochildpid(pi.dwProcessId) 419 return _tochildpid(pi.dwProcessId)
420 420
421 def unlink(f): 421 def unlink(f):