本文整理汇总了Python中pywatchman.client函数的典型用法代码示例。如果您正苦于以下问题:Python client函数的具体用法?Python client怎么用?Python client使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了client函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
def start(self):
args = [self.watchmanBinary(), "--foreground", "--log-level=2"]
args.extend(self.get_state_args())
env = os.environ.copy()
env["WATCHMAN_CONFIG_FILE"] = self.cfg_file
with open(self.cli_log_file_name, "w+") as cli_log_file:
self.proc = subprocess.Popen(
args, env=env, stdin=None, stdout=cli_log_file, stderr=cli_log_file
)
if self.debug_watchman:
print("Watchman instance PID: " + str(self.proc.pid))
if pywatchman.compat.PYTHON3:
user_input = input
else:
user_input = raw_input # noqa:F821
user_input("Press Enter to continue...")
# wait for it to come up
deadline = time.time() + self.start_timeout
while time.time() < deadline:
try:
client = pywatchman.client(sockpath=self.sock_file)
self.pid = client.query("get-pid")["pid"]
break
except pywatchman.SocketConnectError:
t, val, tb = sys.exc_info()
time.sleep(0.1)
finally:
client.close()
if self.pid is None:
# self.proc didn't come up: wait for it to die
self.stop()
pywatchman.compat.reraise(t, val, tb)
示例2: start
def start(self):
args = [
'watchman',
'--foreground',
'--sockname={0}'.format(self.sock_file),
'--logfile={0}'.format(self.log_file_name),
'--statefile={0}'.format(self.state_file),
'--log-level=2',
]
env = os.environ.copy()
env["WATCHMAN_CONFIG_FILE"] = self.cfg_file
self.proc = subprocess.Popen(args,
env=env,
stdin=None,
stdout=self.log_file,
stderr=self.log_file)
# wait for it to come up
last_err = None
for i in range(1, 10):
try:
client = pywatchman.client(sockpath=self.sock_file)
self.pid = client.query('get-pid')['pid']
break
except Exception as e:
t, val, tb = sys.exc_info()
last_err = ''.join(traceback.format_exception(t, val, tb))
time.sleep(0.1)
finally:
client.close()
if self.pid is None:
raise Exception(last_err)
示例3: start
def start(self):
args = [
'watchman',
'--foreground',
'--sockname={}'.format(self.sock_file),
'--logfile={}'.format(self.log_file_name),
'--statefile={}'.format(self.state_file),
'--log-level=2',
]
env = os.environ.copy()
env["WATCHMAN_CONFIG_FILE"] = self.cfg_file
self.proc = subprocess.Popen(args,
env=env,
stdin=None,
stdout=self.log_file,
stderr=self.log_file)
# wait for it to come up
last_err = None
for i in xrange(1, 10):
try:
client = pywatchman.client(sockpath=self.sock_file)
self.pid = client.query('get-pid')['pid']
break
except Exception as e:
last_err = e
time.sleep(0.1)
if not self.pid:
raise last_err
示例4: start
def start(self):
args = [
'watchman',
'--foreground',
'--log-level=2',
]
args.extend(self.get_state_args())
env = os.environ.copy()
env["WATCHMAN_CONFIG_FILE"] = self.cfg_file
self.proc = subprocess.Popen(args,
env=env,
stdin=None,
stdout=self.cli_log_file,
stderr=self.cli_log_file)
# wait for it to come up
deadline = time.time() + self.start_timeout
while time.time() < deadline:
try:
client = pywatchman.client(sockpath=self.sock_file)
self.pid = client.query('get-pid')['pid']
break
except Exception as e:
t, val, tb = sys.exc_info()
time.sleep(0.1)
finally:
client.close()
if self.pid is None:
pywatchman.compat.reraise(t, val, tb)
示例5: getClient
def getClient(self):
if not hasattr(self, 'client'):
self.client = pywatchman.client(
transport=self.transport,
sendEncoding=self.encoding,
recvEncoding=self.encoding,
sockpath=WatchmanInstance.getSharedInstance().getSockPath())
return self.client
示例6: test_client
def test_client(self):
# verify that we can talk to the instance set up by the harness
# we're just verifying that the socket set in the environment works
# and that we can understand the result
sock = os.getenv('WATCHMAN_SOCK')
c = pywatchman.client()
res = c.query('get-sockname')
self.assertEquals(sock, res['sockname'])
示例7: getClient
def getClient(self):
if not hasattr(self, 'client'):
self.client = pywatchman.client(
# ASAN-enabled builds can be slower enough that we hit timeouts
# with the default of 1 second
timeout=3.0,
transport=self.transport,
sendEncoding=self.encoding,
recvEncoding=self.encoding,
sockpath=WatchmanInstance.getSharedInstance().getSockPath())
return self.client
示例8: check_availability
def check_availability(cls):
if not pywatchman:
raise WatchmanUnavailable('pywatchman not installed.')
client = pywatchman.client(timeout=0.1)
try:
result = client.capabilityCheck()
except Exception:
# The service is down?
raise WatchmanUnavailable('Cannot connect to the watchman service.')
version = get_version_tuple(result['version'])
# Watchman 4.9 includes multiple improvements to watching project
# directories as well as case insensitive filesystems.
logger.debug('Watchman version %s', version)
if version < (4, 9):
raise WatchmanUnavailable('Watchman 4.9 or later is required.')
示例9: getClient
def getClient(self, inst=None, replace_cached=False, no_cache=False):
if inst or not hasattr(self, "client") or no_cache:
client = pywatchman.client(
timeout=self.socketTimeout,
transport=self.transport,
sendEncoding=self.encoding,
recvEncoding=self.encoding,
sockpath=(inst or WatchmanInstance.getSharedInstance()).getSockPath(),
)
if (not inst or replace_cached) and not no_cache:
# only cache the client if it points to the shared instance
self.client = client
self.addCleanup(lambda: self.__clearClient())
return client
return self.client
示例10: getClient
def getClient(self, inst=None):
if inst or not hasattr(self, 'client'):
client = pywatchman.client(
# ASAN-enabled builds can be slower enough that we hit timeouts
# with the default of 1 second
timeout=3.0,
transport=self.transport,
sendEncoding=self.encoding,
recvEncoding=self.encoding,
sockpath=(inst or
WatchmanInstance.getSharedInstance()).getSockPath())
if not inst:
# only cache the client if it points to the shared instance
self.client = client
return client
return self.client
示例11: test_transport_error
def test_transport_error(self):
buf = '{"foo":"bar"}'
failAfterBytesRead = 5
class FakeFailingTransport(Transport):
def __init__(self, sockpath, timeout):
self.readBuf = buf
self.readBufPos = 0
self.writeBuf = []
self.closed = False
def close(self):
self.closed = True
def readBytes(self, size):
readEnd = self.readBufPos + size
if readEnd > failAfterBytesRead:
raise IOError(23, "fnord")
elif readEnd > len(self.readBuf):
return ""
read = self.readBuf[self.readBufPos : self.readBufPos + size]
self.readBufPos += size
return read
def write(self, buf):
self.writeBuf.extend(buf)
c = client(
sockpath="",
transport=FakeFailingTransport,
sendEncoding="json",
recvEncoding="json",
)
try:
c.query("foobarbaz")
self.assertTrue(False, "expected a WatchmanError")
except WatchmanError as e:
self.assertIn(
"I/O error communicating with watchman daemon: "
+ "errno=23 errmsg=fnord, while executing "
+ "('foobarbaz',)",
str(e),
)
except Exception as e:
self.assertTrue(False, "expected a WatchmanError, but got " + str(e))
示例12: start
def start(self):
args = [
self.watchmanBinary(),
'--foreground',
'--log-level=2',
]
args.extend(self.get_state_args())
env = os.environ.copy()
env["WATCHMAN_CONFIG_FILE"] = self.cfg_file
self.proc = subprocess.Popen(args,
env=env,
stdin=None,
stdout=self.cli_log_file,
stderr=self.cli_log_file)
if self.debug_watchman:
print('Watchman instance PID: ' + str(self.proc.pid))
if pywatchman.compat.PYTHON3:
user_input = input
else:
user_input = raw_input
user_input('Press Enter to continue...')
# wait for it to come up
deadline = time.time() + self.start_timeout
while time.time() < deadline:
try:
client = pywatchman.client(sockpath=self.sock_file)
self.pid = client.query('get-pid')['pid']
break
except Exception as e:
t, val, tb = sys.exc_info()
time.sleep(0.1)
finally:
client.close()
if self.pid is None:
# self.proc didn't come up: wait for it to die
self.stop()
pywatchman.compat.reraise(t, val, tb)
示例13: main
def main():
# Our parent expects to read JSON from our stdout, so if anyone
# uses print, buck will complain with a helpful "but I wanted an
# array!" message and quit. Redirect stdout to stderr so that
# doesn't happen. Actually dup2 the file handle so that writing
# to file descriptor 1, os.system, and so on work as expected too.
to_parent = os.fdopen(os.dup(sys.stdout.fileno()), 'a')
os.dup2(sys.stderr.fileno(), sys.stdout.fileno())
parser = optparse.OptionParser()
parser.add_option(
'--project_root',
action='store',
type='string',
dest='project_root')
parser.add_option(
'--build_file_name',
action='store',
type='string',
dest="build_file_name")
parser.add_option(
'--allow_empty_globs',
action='store_true',
dest='allow_empty_globs',
help='Tells the parser not to raise an error when glob returns no results.')
parser.add_option(
'--use_watchman_glob',
action='store_true',
dest='use_watchman_glob',
help='Invokes `watchman query` to get lists of files instead of globbing in-process.')
parser.add_option(
'--watchman_watch_root',
action='store',
type='string',
dest='watchman_watch_root',
help='Path to root of watchman watch as returned by `watchman watch-project`.')
parser.add_option(
'--watchman_project_prefix',
action='store',
type='string',
dest='watchman_project_prefix',
help='Relative project prefix as returned by `watchman watch-project`.')
parser.add_option(
'--include',
action='append',
dest='include')
(options, args) = parser.parse_args()
# Even though project_root is absolute path, it may not be concise. For
# example, it might be like "C:\project\.\rule".
#
# Under cygwin, the project root will be invoked from buck as C:\path, but
# the cygwin python uses UNIX-style paths. They can be converted using
# cygpath, which is necessary because abspath will treat C:\path as a
# relative path.
options.project_root = cygwin_adjusted_path(options.project_root)
project_root = os.path.abspath(options.project_root)
watchman_client = None
output_format = 'JSON'
output_encode = lambda val: json.dumps(val, sort_keys=True)
if options.use_watchman_glob:
try:
# pywatchman may not be built, so fall back to non-watchman
# in that case.
import pywatchman
watchman_client = pywatchman.client()
output_format = 'BSER'
output_encode = lambda val: pywatchman.bser.dumps(val)
except ImportError, e:
# TODO(agallagher): Restore this when the PEX builds pywatchman.
# print >> sys.stderr, \
# 'Could not import pywatchman (sys.path {}): {}'.format(
# sys.path,
# repr(e))
pass
示例14: client
def client(self):
return pywatchman.client(timeout=self.client_timeout)
示例15: input_changes
def input_changes(self, verbose=True):
'''
Return an iterator of `FasterBuildChange` instances as inputs
to the faster build system change.
'''
# TODO: provide the debug diagnostics we want: this print is
# not immediately before the watch.
if verbose:
print_line('watch', 'Connecting to watchman')
# TODO: figure out why a large timeout is required for the
# client, and a robust strategy for retrying timed out
# requests.
self.client = pywatchman.client(timeout=5.0)
try:
if verbose:
print_line('watch', 'Checking watchman capabilities')
# TODO: restrict these capabilities to the minimal set.
self.client.capabilityCheck(required=[
'clock-sync-timeout',
'cmd-watch-project',
'term-dirname',
'wildmatch',
])
if verbose:
print_line('watch', 'Subscribing to {}'.format(self.config_environment.topsrcdir))
self.subscribe_to_topsrcdir()
if verbose:
print_line('watch', 'Watching {}'.format(self.config_environment.topsrcdir))
input_to_outputs = self.file_copier.input_to_outputs_tree()
for input, outputs in input_to_outputs.items():
if not outputs:
raise Exception("Refusing to watch input ({}) with no outputs".format(input))
while True:
try:
_watch_result = self.client.receive()
changed = self.changed_files()
if not changed:
continue
result = FasterBuildChange()
for change in changed:
if change in input_to_outputs:
result.input_to_outputs[change] = set(input_to_outputs[change])
else:
result.unrecognized.add(change)
for input, outputs in result.input_to_outputs.items():
for output in outputs:
if output not in result.output_to_inputs:
result.output_to_inputs[output] = set()
result.output_to_inputs[output].add(input)
yield result
except pywatchman.SocketTimeout:
# Let's check to see if we're still functional.
_version = self.client.query('version')
except pywatchman.CommandError as e:
# Abstract away pywatchman errors.
raise FasterBuildException(e, 'Command error using pywatchman to watch {}'.format(
self.config_environment.topsrcdir))
except pywatchman.SocketTimeout as e:
# Abstract away pywatchman errors.
raise FasterBuildException(e, 'Socket timeout using pywatchman to watch {}'.format(
self.config_environment.topsrcdir))
finally:
self.client.close()