def stop(self): """Stop the prober.""" if self._feeder: self._stop_interpreter() self._feeder.stop() self._feeder = None else: raise errors.HumodUsageError('Prober not started.')
def tryconnect(self, dialtone_check): """Use pppd to connect to the network.""" try: # Modem is not connected if _pppd_pid is set to None. if not self._pppd_pid: data_port = self.data_port #log( "Openind data") data_port.open() #log( "Opened") data_port.write('ATZ\r\n') print data_port.return_data() data_port.write('ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0\r\n') print data_port.return_data() data_port.write('AT+CGDCONT=1,"IP","internet.wind",,\r\n') print data_port.return_data() if not dialtone_check: data_port.write('ATX3\r\n') print data_port.return_data() data_port.write('ATDT%s\r\n' % self._dial_num) print data_port.readline() status = data_port.readline() print status if status.startswith('CONNECT'): # pppd_args = [defaults.PPPD_PATH, self.baudrate, self.data_port.port] + self.pppd_params pppd_args = [ self.pppd_path, self.data_port.port, self.baudrate ] + self.pppd_params pid = os.fork() if pid: self._pppd_pid = pid else: try: os.execv(self.pppd_path, pppd_args) except: raise errors.PppdError( 'An error while starting pppd.') else: last_pppd_result = os.waitpid(self._pppd_pid, os.WNOHANG) if last_pppd_result != (0, 0): # Reconnect. self._pppd_pid = None self.connect(dialtone_check) else: # Modem already connected. raise errors.HumodUsageError('Modem already connected.') return True except: return False
def start(self, patterns=None): """Start the prober. Starts two threads, an instance of QueueFeeder and Interpreter. """ self.patterns = patterns if not patterns: self.patterns = actions.STANDARD_ACTIONS if self._feeder: raise errors.HumodUsageError('Prober already started.') else: self._feeder = QueueFeeder(self.queue, self.modem.ctrl_port, self.modem.ctrl_lock) self._feeder.start() self._start_interpreter()