From 8940ad091a33e0e6574245a23b500c5bb17b8ebb Mon Sep 17 00:00:00 2001 From: Sean Robinson Date: Sat, 3 May 2014 03:46:35 -0700 Subject: [PATCH] Only run the rest of WiFi Radar if the configuration was created Without a configuration, WiFi Radar will not be able to run any of the supporting programs (e.g. ifconfig and iwconfig) it needs, so do not try to continue. Signed-off-by: Sean Robinson --- wifiradar/__init__.py | 70 +++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/wifiradar/__init__.py b/wifiradar/__init__.py index 7b680e4..daab549 100644 --- a/wifiradar/__init__.py +++ b/wifiradar/__init__.py @@ -76,44 +76,44 @@ class Main(object): logger.setLevel(self.config.get_opt_as_int('GENERAL', 'loglevel')) - try: - fileLogHandler = logging.handlers.RotatingFileHandler( - self.config.get_opt('GENERAL', 'logfile'), - maxBytes=64*1024, backupCount=5) - except IOError as e: - self.msg_pipe.send(Message('ERROR', - _('Cannot open log file for writing: {ERR}.\n\n' - 'WiFi Radar will work, but a log file will not ' - 'be recorded.').format(ERR=e.strerror))) - else: - fileLogHandler.setFormatter(generic_formatter) - logger.addHandler(fileLogHandler) - - scanner_thread = Thread(name='scanner', target=scanner, args=(config, scanner_pipe)) - scanner_thread.start() + try: + fileLogHandler = logging.handlers.RotatingFileHandler( + self.config.get_opt('GENERAL', 'logfile'), + maxBytes=64*1024, backupCount=5) + except IOError as e: + self.msg_pipe.send(Message('ERROR', + _('Cannot open log file for writing: {ERR}.\n\n' + 'WiFi Radar will work, but a log file will not ' + 'be recorded.').format(ERR=e.strerror))) + else: + fileLogHandler.setFormatter(generic_formatter) + logger.addHandler(fileLogHandler) - ui_proc = Process(name='ui', target=ui.start, args=(ui_pipe,)) - ui_proc.start() + scanner_thread = Thread(name='scanner', target=scanner, + args=(self.config.copy(), scanner_pipe)) + scanner_thread.start() + ui_proc = Process(name='ui', target=ui.start, args=(ui_pipe,)) + ui_proc.start() - # This is the first run (or, at least, no config file was present), - # so pop up the preferences window - try: - if self.config.get_opt_as_bool('GENERAL', 'new_file'): - self.config.remove_option('GENERAL', 'new_file') - config_copy = self.config.copy() - self.msg_pipe.send(Message('PREFS-EDIT', config_copy)) - except NoOptionError: - pass - # Add our known profiles in order. - for profile_name in self.config.auto_profile_order: - profile = self.config.get_profile(profile_name) - self.msg_pipe.send(Message('PROFILE-UPDATE', profile)) - self.running = True - try: - self.run() - finally: - self.shutdown([ui_proc, scanner_thread], dispatcher) + # This is the first run (or, at least, no config file was present), + # so pop up the preferences window + try: + if self.config.get_opt_as_bool('GENERAL', 'new_file'): + self.config.remove_option('GENERAL', 'new_file') + config_copy = self.config.copy() + self.msg_pipe.send(Message('PREFS-EDIT', config_copy)) + except NoOptionError: + pass + # Add our known profiles in order. + for profile_name in self.config.auto_profile_order: + profile = self.config.get_profile(profile_name) + self.msg_pipe.send(Message('PROFILE-UPDATE', profile)) + self.running = True + try: + self.run() + finally: + self.shutdown([ui_proc, scanner_thread], dispatcher) def make_config(self, conf_file): """ Returns a tuple with a :class:`ConfigManager` and a -- 2.11.4.GIT