def start(self): """This function scans for wifi networks and outputs to a temporary file""" from conf import Conf import logging logger = logging.getLogger(Conf.LOGGER_NAME) import subprocess self.error = 0 import os, parser, cp_builder self.tmp_scan = cp_builder.build_tmp_scan_path(self.config) if Conf.DISABLE_SCAN: if Conf.DEBUG_MODE: logger.info('Scan disabled, we try to read networks from {}'.format(self.tmp_scan)) if not os.path.exists(self.tmp_scan): self.error = 1 logger.error('Modo debug pero el archivo de redes escaneadas {} no existe'. format(self.tmp_scan)) else: try: os.remove(self.config.conf_files[Conf.PATH_TMP_SCAN_FILE]) if Conf.DEBUG_MODE: logger.info("Previous scan deleted") except OSError: pass rfkill_command = cp_builder.build_rfkill_command(self.config, Conf.RFKILL_VAL_UNBLOCK, Conf.RFKILL_VAL_WIFI) ifconfig_command = cp_builder.build_ifconfig_command(self.config, Conf.IFCONFIG_ACTION_UP) scan_command = cp_builder.build_scan_command(self.config) scan_commands = [(rfkill_command, None), (ifconfig_command, None), (scan_command, self.tmp_scan)] scan_return_values = cp_builder.execute(scan_commands, True) if Conf.DEBUG_MODE: logger.info('Commands returned: ' + scan_return_values.__repr__())
def start(self): ''' Comienza el scan de redes con el comando subyacente y construye el diccionario. ''' global logger self.error = 0 import cp_builder self.tmp_scan = cp_builder.build_tmp_scan_path(self.config) try: self.tmp_scan_f = open(self.tmp_scan) current_network_cell = '' #Gran conclusión: elegir tupla aquí fue un error debido a que cada vez #que concateno se crea un objeto nuevo y además cambian las posiciones #relativas de todo si decido incluir algo nuevo más tarde for n_tuple in self.networks_iter(): n_tuple_type = n_tuple[0] if n_tuple_type == self.n_tuple_type_cell: current_network_cell = n_tuple[1] self.networks[current_network_cell] = n_tuple elif n_tuple_type == self.n_tuple_type_essid: self.networks[current_network_cell] += n_tuple elif n_tuple_type == self.n_tuple_type_encryptionkey: self.networks[current_network_cell] += n_tuple elif n_tuple_type == self.n_tuple_type_wpa1: self.networks[current_network_cell] += n_tuple elif n_tuple_type == self.n_tuple_type_wpa2: self.networks[current_network_cell] += n_tuple elif n_tuple_type == self.n_tuple_type_quality: self.networks[current_network_cell] += n_tuple except IOError: self.error = 1 logger.error("El archivo temporal de redes {} no existe ".format(self.tmp_scan)) finally: self.tmp_scan_f.close()