def onConnect(self, response): this.connection = self self.delegate.transport = self.transport d.callback(self) log.debug("ws://{}:{} connected!".format( this.address, this.port)) self.delegate.connectionMade()
def disconnect(self): """ """ s = self.serial_port if s: log.debug("{} disconnected!".format(self.port)) s.loseConnection() self.serial_port = None
def do_connect(): try: self.serial_port = SerialPort(protocol, self.port, reactor, baudrate=self.baudrate) d.callback(True) log.debug("{} connected!".format(self.port)) except Exception as e: d.callback(e)
def login(self): """ Wait a little for a password prompt """ #: Wait for it to connect yield self.ready() #: Then wait for the password prompt yield async_sleep(300) log.debug(self._buffer) if 'Password:' in self._buffer.decode(): #: Hack yield self.plugin.show_password_prompt()
def scan_subnet(self): """ Scan to find any ws clients on the port""" subnet = self.address.split('.')[0:3] addrs = [] def on_connect(p, addr): log.debug("scan | {}:{} is up!".format(addr, self.port)) addrs.append(addr) p.transport.loseConnection() #: Scan for everything in the subnet #: timeout after 1 second ds = [] for i in range(256): addr = ".".join(subnet + [str(i)]) point = TCP4ClientEndpoint(reactor, addr, self.port) d = connectProtocol(point, Protocol()) d.addCallback(lambda p, addr=addr: on_connect(p, addr)) d.addErrback(lambda e, addr=addr: log.debug("scan | {} is down". format(addr))) reactor.callLater(1, d.cancel) ds.append(d) #: When they all finish update the addresses property done = DeferredList(ds) done.addCallback(lambda r: setattr(self, 'addresses', addrs))
def scan_files(self, event): excluded = ['http_server', 'http_server_ssl'] board = self.board board.disconnect() device = QueryProtocol(self) yield board.connect(device) self.scanning_progress = 0 self.scanning_status = "Connecting...." yield device.login() result = yield device.query(b'\n\x05' + textwrap.dedent(""" def __scanfiles__(path): import os files = {} try: for f in os.listdir(path): files[f] = { 'info':os.stat(f), 'files':__scanfiles__("{}/{}".format(path,f)), 'name':f } except OSError: pass return files __scanfiles__('.') """).encode() + b'\n\x04', raw=True, timeout=200) log.debug("Scan complete!") contents = {} for line in result: try: contents = eval(line) log.debug("Loaded!") break except Exception as e: log.debug(e) #: TODO: Walk... if not contents: return self.files = contents
def lineReceived(self, line): log.debug(line) self.lines.append(line.decode()) if self.request: self.pending += 1 timed_call(self.timeout, self.finish)
def onClose(self, wasClean, code, reason): log.debug("ws://{}:{} disconnected: " "clean={} code={} reason={}!".format( this.address, this.port, wasClean, code, reason)) self.delegate.connectionLost(reason)
def on_connect(p, addr): log.debug("scan | {}:{} is up!".format(addr, self.port)) addrs.append(addr) p.transport.loseConnection()