def __init__(self, buildmaster_host, port, name, passwd, basedir, keepalive, usePTY, keepaliveTimeout=None, umask=None, maxdelay=300, numcpus=None, unicode_encoding=None, allow_shutdown=None): # note: keepaliveTimeout is ignored, but preserved here for # backward-compatibility service.MultiService.__init__(self) WorkerBase.__init__(self, name, basedir, usePTY, umask=umask, unicode_encoding=unicode_encoding) if keepalive == 0: keepalive = None self.numcpus = numcpus self.shutdown_loop = None if allow_shutdown == 'signal': if not hasattr(signal, 'SIGHUP'): raise ValueError("Can't install signal handler") elif allow_shutdown == 'file': self.shutdown_file = os.path.join(basedir, 'shutdown.stamp') self.shutdown_mtime = 0 self.allow_shutdown = allow_shutdown bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay) bf.startLogin(credentials.UsernamePassword(name, passwd), client=self.bot) self.connection = c = internet.TCPClient(buildmaster_host, port, bf) c.setServiceParent(self)
def __init__(self, buildmaster_host, port, name, passwd, basedir, keepalive, usePTY=None, keepaliveTimeout=None, umask=None, maxdelay=300, numcpus=None, unicode_encoding=None, allow_shutdown=None, maxRetries=None): # note: keepaliveTimeout is ignored, but preserved here for # backward-compatibility assert usePTY is None, "worker-side usePTY is not supported anymore" service.MultiService.__init__(self) WorkerBase.__init__(self, name, basedir, umask=umask, unicode_encoding=unicode_encoding) if keepalive == 0: keepalive = None name = unicode2bytes(name, self.bot.unicode_encoding) passwd = unicode2bytes(passwd, self.bot.unicode_encoding) self.numcpus = numcpus self.shutdown_loop = None self.maxRetries = maxRetries if allow_shutdown == 'signal': if not hasattr(signal, 'SIGHUP'): raise ValueError("Can't install signal handler") elif allow_shutdown == 'file': self.shutdown_file = os.path.join(basedir, 'shutdown.stamp') self.shutdown_mtime = 0 self.allow_shutdown = allow_shutdown bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay.bit_length, maxRetries=self.maxRetries, maxRetriesCallback=self.gracefulShutdown) bf.startLogin(credentials.UsernamePassword(name, passwd), client=self.bot) self.connection = c = internet.TCPClient( buildmaster_host, port, HangCheckFactory(bf, hung_callback=self._hung_connection)) c.setServiceParent(self)
def __init__(self, buildmaster_host, port, name, passwd, basedir, keepalive, usePTY=None, keepaliveTimeout=None, umask=None, maxdelay=None, numcpus=None, unicode_encoding=None, allow_shutdown=None, maxRetries=None, connection_string=None): assert usePTY is None, "worker-side usePTY is not supported anymore" assert (connection_string is None or (buildmaster_host, port) == (None, None)), ( "If you want to supply a connection string, " "then set host and port to None") service.MultiService.__init__(self) WorkerBase.__init__( self, name, basedir, umask=umask, unicode_encoding=unicode_encoding) if keepalive == 0: keepalive = None name = unicode2bytes(name, self.bot.unicode_encoding) passwd = unicode2bytes(passwd, self.bot.unicode_encoding) self.numcpus = numcpus self.shutdown_loop = None if allow_shutdown == 'signal': if not hasattr(signal, 'SIGHUP'): raise ValueError("Can't install signal handler") elif allow_shutdown == 'file': self.shutdown_file = os.path.join(basedir, 'shutdown.stamp') self.shutdown_mtime = 0 self.allow_shutdown = allow_shutdown bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay) bf.startLogin( credentials.UsernamePassword(name, passwd), client=self.bot) if connection_string is None: connection_string = 'tcp:host={}:port={}'.format( buildmaster_host.replace(':', r'\:'), # escape ipv6 addresses port) endpoint = clientFromString(reactor, connection_string) def policy(attempt): if maxRetries and attempt >= maxRetries: reactor.stop() return backoffPolicy()(attempt) pb_service = ClientService(endpoint, bf, retryPolicy=policy) self.addService(pb_service)
def __init__(self, buildmaster_host, port, name, passwd, basedir, keepalive, usePTY=None, keepaliveTimeout=None, umask=None, maxdelay=300, numcpus=None, unicode_encoding=None, allow_shutdown=None, maxRetries=None): # note: keepaliveTimeout is ignored, but preserved here for # backward-compatibility assert usePTY is None, "worker-side usePTY is not supported anymore" service.MultiService.__init__(self) WorkerBase.__init__( self, name, basedir, umask=umask, unicode_encoding=unicode_encoding) if keepalive == 0: keepalive = None name = unicode2bytes(name, self.bot.unicode_encoding) passwd = unicode2bytes(passwd, self.bot.unicode_encoding) self.numcpus = numcpus self.shutdown_loop = None self.maxRetries = maxRetries if allow_shutdown == 'signal': if not hasattr(signal, 'SIGHUP'): raise ValueError("Can't install signal handler") elif allow_shutdown == 'file': self.shutdown_file = os.path.join(basedir, 'shutdown.stamp') self.shutdown_mtime = 0 self.allow_shutdown = allow_shutdown bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay, maxRetries=self.maxRetries, maxRetriesCallback=self.gracefulShutdown) bf.startLogin( credentials.UsernamePassword(name, passwd), client=self.bot) self.connection = c = internet.TCPClient( buildmaster_host, port, HangCheckFactory(bf, hung_callback=self._hung_connection)) c.setServiceParent(self)
def __init__(self, buildmaster_host, port, name, passwd, basedir, keepalive, usePTY=None, keepaliveTimeout=None, umask=None, maxdelay=None, numcpus=None, unicode_encoding=None, useTls=None, allow_shutdown=None, maxRetries=None, connection_string=None): assert usePTY is None, "worker-side usePTY is not supported anymore" assert (connection_string is None or (buildmaster_host, port) == (None, None)), ( "If you want to supply a connection string, " "then set host and port to None") service.MultiService.__init__(self) WorkerBase.__init__(self, name, basedir, umask=umask, unicode_encoding=unicode_encoding) if keepalive == 0: keepalive = None name = unicode2bytes(name, self.bot.unicode_encoding) passwd = unicode2bytes(passwd, self.bot.unicode_encoding) self.numcpus = numcpus self.shutdown_loop = None if allow_shutdown == 'signal': if not hasattr(signal, 'SIGHUP'): raise ValueError("Can't install signal handler") elif allow_shutdown == 'file': self.shutdown_file = os.path.join(basedir, 'shutdown.stamp') self.shutdown_mtime = 0 self.allow_shutdown = allow_shutdown bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay) bf.startLogin(credentials.UsernamePassword(name, passwd), client=self.bot) if connection_string is None: if useTls: connection_type = 'tls' else: connection_type = 'tcp' connection_string = '{}:host={}:port={}'.format( connection_type, buildmaster_host.replace(':', r'\:'), # escape ipv6 addresses port) endpoint = clientFromString(reactor, connection_string) def policy(attempt): if maxRetries and attempt >= maxRetries: reactor.stop() return backoffPolicy()(attempt) pb_service = ClientService(endpoint, bf, retryPolicy=policy) self.addService(pb_service)
def __init__(self, buildmaster_host, port, name, passwd, basedir, keepalive, usePTY=None, keepaliveTimeout=None, umask=None, maxdelay=None, numcpus=None, unicode_encoding=None, protocol='pb', useTls=None, allow_shutdown=None, maxRetries=None, connection_string=None, delete_leftover_dirs=False, proxy_connection_string=None): assert usePTY is None, "worker-side usePTY is not supported anymore" assert (connection_string is None or (buildmaster_host, port) == (None, None)), ( "If you want to supply a connection string, " "then set host and port to None") if protocol == 'pb': bot_class = BotPb elif protocol == 'msgpack_experimental_v1': if sys.version_info.major < 3: raise NotImplementedError( 'Msgpack protocol is not supported in Python2') bot_class = BotMsgpack else: raise ValueError('Unknown protocol {}'.format(protocol)) WorkerBase.__init__(self, name, basedir, bot_class, umask=umask, unicode_encoding=unicode_encoding, delete_leftover_dirs=delete_leftover_dirs) if keepalive == 0: keepalive = None name = unicode2bytes(name, self.bot.unicode_encoding) self.numcpus = numcpus self.shutdown_loop = None if allow_shutdown == 'signal': if not hasattr(signal, 'SIGHUP'): raise ValueError("Can't install signal handler") elif allow_shutdown == 'file': self.shutdown_file = os.path.join(basedir, 'shutdown.stamp') self.shutdown_mtime = 0 self.allow_shutdown = allow_shutdown if protocol == 'pb': passwd = unicode2bytes(passwd, self.bot.unicode_encoding) bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay) bf.startLogin(credentials.UsernamePassword(name, passwd), client=self.bot) elif protocol == 'msgpack_experimental_v1': if connection_string is None: ws_conn_string = "ws://{}:{}".format(buildmaster_host, port) else: from urllib.parse import urlparse parsed_url = urlparse(connection_string) ws_conn_string = "ws://{}:{}".format(parsed_url.hostname, parsed_url.port) bf = self.bf = BuildbotWebSocketClientFactory(ws_conn_string) bf.protocol = BuildbotWebSocketClientProtocol self.bf.buildbot_bot = self.bot self.bf.name = name self.bf.password = passwd else: raise ValueError('Unknown protocol {}'.format(protocol)) def get_connection_string(host, port): if useTls: connection_type = 'tls' else: connection_type = 'tcp' return '{}:host={}:port={}'.format( connection_type, host.replace(':', r'\:'), # escape ipv6 addresses port) assert not (proxy_connection_string and connection_string), ( "If you want to use HTTP tunneling, then supply build master " "host and port rather than a connection string") if proxy_connection_string: log.msg("Using HTTP tunnel to connect through proxy") proxy_endpoint = clientFromString(reactor, proxy_connection_string) endpoint = HTTPTunnelEndpoint(buildmaster_host, port, proxy_endpoint) if useTls: from twisted.internet.endpoints import wrapClientTLS from twisted.internet.ssl import optionsForClientTLS contextFactory = optionsForClientTLS(hostname=buildmaster_host) endpoint = wrapClientTLS(contextFactory, endpoint) else: if connection_string is None: connection_string = get_connection_string( buildmaster_host, port) endpoint = clientFromString(reactor, connection_string) def policy(attempt): if maxRetries and attempt >= maxRetries: reactor.stop() return backoffPolicy()(attempt) pb_service = ClientService(endpoint, bf, retryPolicy=policy) self.addService(pb_service)