comparison mercurial/util.py @ 2025:581d9a8b5fb9

clean up lee's windows testpid fix.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Thu, 30 Mar 2006 18:27:04 -0800
parents 6328445b0e71
children 24c604628867
comparison
equal deleted inserted replaced
2024:6328445b0e71 2025:581d9a8b5fb9
534 if pf[0] == '`': 534 if pf[0] == '`':
535 pf = pf[1:-1] # Remove the quotes 535 pf = pf[1:-1] # Remove the quotes
536 return pf 536 return pf
537 537
538 try: # Mark Hammond's win32all package allows better functionality on Windows 538 try: # Mark Hammond's win32all package allows better functionality on Windows
539 import win32api, win32con, win32file, pywintypes 539 import win32api, win32con, win32file, winerror, pywintypes
540 540
541 # create hard links using win32file module 541 # create hard links using win32file module
542 def os_link(src, dst): # NB will only succeed on NTFS 542 def os_link(src, dst): # NB will only succeed on NTFS
543 win32file.CreateHardLink(dst, src) 543 win32file.CreateHardLink(dst, src)
544 544
553 return res[7] 553 return res[7]
554 except: 554 except:
555 return os.stat(pathname).st_nlink 555 return os.stat(pathname).st_nlink
556 556
557 def testpid(pid): 557 def testpid(pid):
558 '''return True if pid is still running or unable to determine, False otherwise''' 558 '''return True if pid is still running or unable to
559 determine, False otherwise'''
559 try: 560 try:
560 handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, False, pid) 561 handle = win32api.OpenProcess(
562 win32con.PROCESS_QUERY_INFORMATION, False, pid)
561 if handle: 563 if handle:
562 status = win32process.GetExitCodeProcess(handle) 564 status = win32process.GetExitCodeProcess(handle)
563 if status == win32con.STILL_ACTIVE: 565 return status == win32con.STILL_ACTIVE
564 return True
565 else:
566 return False
567 except pywintypes.error, details: 566 except pywintypes.error, details:
568 if details[0] == 87: # ERROR_INVALID_PARAMETER 567 return details[0] != winerror.ERROR_INVALID_PARAMETER
569 return False
570 return True 568 return True
571 569
572 except ImportError: 570 except ImportError:
573 def testpid(pid): 571 def testpid(pid):
574 '''return False if pid dead, True if running or not known''' 572 '''return False if pid dead, True if running or not known'''