def _resolve_sockname_helper(): # if invoked via a trigger, watchman will set this env var; we # should use it unless explicitly set otherwise path = os.getenv('WATCHMAN_SOCK') if path: return path cmd = ['watchman', '--output-encoding=bser', 'get-sockname'] try: p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=os.name != 'nt') except OSError as e: raise WatchmanError('"watchman" executable not in PATH (%s)', e) stdout, stderr = p.communicate() exitcode = p.poll() if exitcode: raise WatchmanError('watchman exited with code %d' % exitcode) result = bser.loads(stdout) if 'error' in result: raise WatchmanError(str(result['error'])) return result['sockname']
async def _process_unilateral_response(self, response): if "log" in response: await self.log_queue.put(response["log"]) elif "subscription" in response: sub = response["subscription"] root = os.path.normcase(response["root"]) self._ensure_subscription_queue_exists(sub, root) await self.sub_by_root[root][sub].put(response) elif self._is_unilateral(response): raise WatchmanError("Unknown unilateral response: " + str(response)) else: raise WatchmanError("Not a unilateral response: " + str(response))
async def _process_unilateral_response(self, response): if 'log' in response: await self.logs.put(response['log']) elif 'subscription' in response: sub = response['subscription'] root = os.path.normcase(response['root']) self._ensure_subscription_queue_exists(sub, root) await self.sub_by_root[root][sub].put(response) elif self._is_unilateral(response): raise WatchmanError('Unknown unilateral response: ' + str(response)) else: raise WatchmanError('Not a unilateral response: ' + str(response))
async def receive(self): sniff = await self.transport.read(SNIFF_LEN) if not sniff: raise WatchmanError('empty watchman response') _1, _2, elen = bser.pdu_info(sniff) rlen = len(sniff) buf = bytearray(elen) buf[:rlen] = sniff while elen > rlen: b = await self.transport.read(elen - rlen) buf[rlen:rlen + len(b)] = b rlen += len(b) response = bytes(buf) try: res = self._loads(response) return res except ValueError as e: raise WatchmanError('watchman response decode error: %s' % e)
def query(self, *args): self.query_invoked = True raise WatchmanError("Nobody watches the watchmen")