Simplify RadarWindow.delete_profile
[wifi-radar.git] / wifiradar / misc.py
blob4254405d4c8ccc0937d56928a06697b01cc77d01
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 # misc.py - collection of miscellaneous functions and classes
6 # Part of WiFi Radar: A utility for managing WiFi profiles on GNU/Linux.
8 # Copyright (C) 2004-2005 Ahmad Baitalmal <ahmad@baitalmal.com>
9 # Copyright (C) 2005 Nicolas Brouard <nicolas.brouard@mandrake.org>
10 # Copyright (C) 2005-2009 Brian Elliott Finley <brian@thefinleys.com>
11 # Copyright (C) 2006 David Decotigny <com.d2@free.fr>
12 # Copyright (C) 2006 Simon Gerber <gesimu@gmail.com>
13 # Copyright (C) 2006-2007 Joey Hurst <jhurst@lucubrate.org>
14 # Copyright (C) 2006, 2009 Ante Karamatic <ivoks@ubuntu.com>
15 # Copyright (C) 2009-2010,2014 Sean Robinson <seankrobinson@gmail.com>
16 # Copyright (C) 2010 Prokhor Shuchalov <p@shuchalov.ru>
18 # This program is free software; you can redistribute it and/or modify
19 # it under the terms of the GNU General Public License as published by
20 # the Free Software Foundation; version 2 of the License.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License in LICENSE.GPL for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write to the Free Software
29 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 import logging
34 import os
36 from subprocess import check_call, Popen, PIPE, STDOUT
38 WIFI_RADAR_VERSION = "0.0.0"
40 # create a logger
41 logger = logging.getLogger(__name__)
44 class DeviceError(EnvironmentError):
45 """ DeviceError will be raised when a problem is found while changing
46 a wireless device's configuration (e.g. when 'ifconfig wlan0 up'
47 fails).
48 """
49 pass
52 class NoDeviceError(EnvironmentError):
53 """ NoDeviceError will be raised when a wireless device cannot be
54 found.
55 """
56 pass
59 class PipeError(IOError):
60 """ PipeError is raised when a communication Pipe closes unexpectedly.
61 """
62 pass
64 def get_new_profile():
65 """ Return a blank profile.
67 Parameters:
69 none
71 Returns:
73 dictionary -- An AP profile with defaults set.
74 """
75 return { 'known': False,
76 'available': False,
77 'encrypted': False,
78 'essid': '',
79 'bssid': '',
80 'roaming': False,
81 'protocol': 'g',
82 'signal': -193,
83 'channel': 'auto',
84 'con_prescript': '',
85 'con_postscript': '',
86 'dis_prescript': '',
87 'dis_postscript': '',
88 'key': '',
89 'mode': 'auto',
90 'security': 'none',
91 'wep_mode': '',
92 'wpa_psk': '',
93 'use_dhcp': True,
94 'ip': '',
95 'netmask': '',
96 'gateway': '',
97 'domain': '',
98 'dns1': '',
99 'dns2': ''
102 def shellcmd(command, environment=None):
103 """ Run 'command' through the shell, where 'command' is a tuple of
104 the program to execute and its arguments. 'environment' is a
105 dictionary of shell environment variables (as keys) and their
106 values. Returns 0 on success, otherwise, it raises
107 CalledProcessError.
109 env_tmp = os.environ
110 env_tmp.update(environment)
111 return check_call(command, shell=True, env=env_tmp)
114 # Make so we can be imported
115 if __name__ == "__main__":
116 pass