Update how the logging level is set to DEBUG
[wifi-radar.git] / wifiradar / __init__.py
blob96ab1ac98ecf2e9a93dceb87be25bd5ed7713c14
1 # -*- coding: utf-8 -*-
3 # __init__.py - main logic for operating WiFi Radar
5 # Part of WiFi Radar: A utility for managing WiFi profiles on GNU/Linux.
7 # Copyright (C) 2004-2005 Ahmad Baitalmal <ahmad@baitalmal.com>
8 # Copyright (C) 2005 Nicolas Brouard <nicolas.brouard@mandrake.org>
9 # Copyright (C) 2005-2009 Brian Elliott Finley <brian@thefinleys.com>
10 # Copyright (C) 2006 David Decotigny <com.d2@free.fr>
11 # Copyright (C) 2006 Simon Gerber <gesimu@gmail.com>
12 # Copyright (C) 2006-2007 Joey Hurst <jhurst@lucubrate.org>
13 # Copyright (C) 2006, 2009 Ante Karamatic <ivoks@ubuntu.com>
14 # Copyright (C) 2009-2010,2014 Sean Robinson <seankrobinson@gmail.com>
15 # Copyright (C) 2010 Prokhor Shuchalov <p@shuchalov.ru>
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; version 2 of the License.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License in LICENSE.GPL for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 try:
33 # Py2
34 import Queue as queue
35 except ImportError:
36 # Py3
37 import queue
39 import logging
40 from multiprocessing import Pipe
41 from subprocess import Popen
42 from threading import Event, Thread
44 from wifiradar.connections import ConnectionManager
45 from wifiradar.pubsub import Dispatcher, Message
46 import wifiradar.gui.g2 as ui
47 import wifiradar.gui.g2.transients as transients
49 # Set up a logging framework.
50 logger = logging.getLogger("wifiradar")
53 def main(config):
54 """
55 """
56 if __debug__:
57 logger.setLevel(logging.DEBUG)
58 else:
59 logger.setLevel(config.get_opt_as_int('DEFAULT', 'loglevel'))
61 try:
62 fileLogHandler = logging.handlers.RotatingFileHandler(config.get_opt('DEFAULT', 'logfile'), maxBytes=64*1024, backupCount=5)
63 except IOError as e:
64 pass
65 else:
66 fileLogHandler.setFormatter(generic_formatter)
67 logger.addHandler(fileLogHandler)
68 dispatcher = Dispatcher()
70 exit_event = Event()
71 exit_event.clear()
73 apQueue = queue.Queue(100)
74 commQueue = queue.Queue(2)
76 connman_thread = Thread(None, misc.scanning_thread, None, (config, apQueue, commQueue, exit_event))
77 connman_thread.start()
78 main_radar_window = ui.RadarWindow(config, apQueue, commQueue, exit_event)
79 main_radar_window.main()