equal
deleted
inserted
replaced
315 |
315 |
316 class UnixSocketTransport(Transport): |
316 class UnixSocketTransport(Transport): |
317 """ local unix domain socket transport """ |
317 """ local unix domain socket transport """ |
318 sock = None |
318 sock = None |
319 |
319 |
320 def __init__(self, sockpath, timeout): |
320 def __init__(self, sockpath, timeout, watchman_exe): |
321 self.sockpath = sockpath |
321 self.sockpath = sockpath |
322 self.timeout = timeout |
322 self.timeout = timeout |
323 |
323 |
324 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
324 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
325 try: |
325 try: |
395 |
395 |
396 |
396 |
397 class WindowsNamedPipeTransport(Transport): |
397 class WindowsNamedPipeTransport(Transport): |
398 """ connect to a named pipe """ |
398 """ connect to a named pipe """ |
399 |
399 |
400 def __init__(self, sockpath, timeout): |
400 def __init__(self, sockpath, timeout, watchman_exe): |
401 self.sockpath = sockpath |
401 self.sockpath = sockpath |
402 self.timeout = int(math.ceil(timeout * 1000)) |
402 self.timeout = int(math.ceil(timeout * 1000)) |
403 self._iobuf = None |
403 self._iobuf = None |
404 |
404 |
405 self.pipe = CreateFile(sockpath, GENERIC_READ | GENERIC_WRITE, 0, None, |
405 self.pipe = CreateFile(sockpath, GENERIC_READ | GENERIC_WRITE, 0, None, |
561 receive codecs appropriately. |
561 receive codecs appropriately. |
562 """ |
562 """ |
563 proc = None |
563 proc = None |
564 closed = True |
564 closed = True |
565 |
565 |
566 def __init__(self, sockpath, timeout): |
566 def __init__(self, sockpath, timeout, watchman_exe): |
567 self.sockpath = sockpath |
567 self.sockpath = sockpath |
568 self.timeout = timeout |
568 self.timeout = timeout |
|
569 self.watchman_exe = watchman_exe |
569 |
570 |
570 def close(self): |
571 def close(self): |
571 if self.proc: |
572 if self.proc: |
572 if self.proc.pid is not None: |
573 if self.proc.pid is not None: |
573 self.proc.kill() |
574 self.proc.kill() |
577 |
578 |
578 def _connect(self): |
579 def _connect(self): |
579 if self.proc: |
580 if self.proc: |
580 return self.proc |
581 return self.proc |
581 args = [ |
582 args = [ |
582 'watchman', |
583 self.watchman_exe, |
583 '--sockname={0}'.format(self.sockpath), |
584 '--sockname={0}'.format(self.sockpath), |
584 '--logfile=/BOGUS', |
585 '--logfile=/BOGUS', |
585 '--statefile=/BOGUS', |
586 '--statefile=/BOGUS', |
586 '--no-spawn', |
587 '--no-spawn', |
587 '--no-local', |
588 '--no-local', |
754 sub_by_root = {} # Keyed by root, then by subscription name |
755 sub_by_root = {} # Keyed by root, then by subscription name |
755 logs = [] # When log level is raised |
756 logs = [] # When log level is raised |
756 unilateral = ['log', 'subscription'] |
757 unilateral = ['log', 'subscription'] |
757 tport = None |
758 tport = None |
758 useImmutableBser = None |
759 useImmutableBser = None |
|
760 watchman_exe = None |
759 |
761 |
760 def __init__(self, |
762 def __init__(self, |
761 sockpath=None, |
763 sockpath=None, |
762 timeout=1.0, |
764 timeout=1.0, |
763 transport=None, |
765 transport=None, |
764 sendEncoding=None, |
766 sendEncoding=None, |
765 recvEncoding=None, |
767 recvEncoding=None, |
766 useImmutableBser=False): |
768 useImmutableBser=False, |
|
769 watchman_exe=None): |
767 self.sockpath = sockpath |
770 self.sockpath = sockpath |
768 self.timeout = timeout |
771 self.timeout = timeout |
769 self.useImmutableBser = useImmutableBser |
772 self.useImmutableBser = useImmutableBser |
|
773 self.watchman_exe = watchman_exe |
770 |
774 |
771 if inspect.isclass(transport) and issubclass(transport, Transport): |
775 if inspect.isclass(transport) and issubclass(transport, Transport): |
772 self.transport = transport |
776 self.transport = transport |
773 else: |
777 else: |
774 transport = transport or os.getenv('WATCHMAN_TRANSPORT') or 'local' |
778 transport = transport or os.getenv('WATCHMAN_TRANSPORT') or 'local' |
815 # should use it unless explicitly set otherwise |
819 # should use it unless explicitly set otherwise |
816 path = os.getenv('WATCHMAN_SOCK') |
820 path = os.getenv('WATCHMAN_SOCK') |
817 if path: |
821 if path: |
818 return path |
822 return path |
819 |
823 |
820 cmd = ['watchman', '--output-encoding=bser', 'get-sockname'] |
824 cmd = [self.watchman_exe, '--output-encoding=bser', 'get-sockname'] |
821 try: |
825 try: |
822 args = dict(stdout=subprocess.PIPE, |
826 args = dict(stdout=subprocess.PIPE, |
823 stderr=subprocess.PIPE, |
827 stderr=subprocess.PIPE, |
824 close_fds=os.name != 'nt') |
828 close_fds=os.name != 'nt') |
825 |
829 |
856 return |
860 return |
857 |
861 |
858 if self.sockpath is None: |
862 if self.sockpath is None: |
859 self.sockpath = self._resolvesockname() |
863 self.sockpath = self._resolvesockname() |
860 |
864 |
861 self.tport = self.transport(self.sockpath, self.timeout) |
865 self.tport = self.transport(self.sockpath, self.timeout, self.watchman_exe) |
862 self.sendConn = self.sendCodec(self.tport) |
866 self.sendConn = self.sendCodec(self.tport) |
863 self.recvConn = self.recvCodec(self.tport) |
867 self.recvConn = self.recvCodec(self.tport) |
864 |
868 |
865 def __del__(self): |
869 def __del__(self): |
866 self.close() |
870 self.close() |