diff --git a/in/wicd=wpath.py.in b/in/wicd=wpath.py.in index fa4a753..8f82101 100755 --- a/in/wicd=wpath.py.in +++ b/in/wicd=wpath.py.in @@ -26,6 +26,10 @@ curses_revision = '%CURSES_REVNO%' lib = '%LIB%' share = '%SHARE%' etc = '%ETC%' +scripts = '%SCRIPTS%' +disconnectscripts = '%SCRIPTS%disconnect' +preconnectscripts = '%SCRIPTS%preconnect' +postconnectscripts = '%SCRIPTS%postconnect' images = '%IMAGES%' encryption = '%ENCRYPTION%' bin = '%BIN%' diff --git a/setup.py b/setup.py index 92ffc2c..b8bf723 100755 --- a/setup.py +++ b/setup.py @@ -42,6 +42,7 @@ except Exception, e: print 'failed to find revision number:' print e + class configure(Command): description = "configure the paths that Wicd will be installed to" @@ -51,6 +52,7 @@ class configure(Command): ('lib=', None, 'set the lib directory'), ('share=', None, 'set the share directory'), ('etc=', None, 'set the etc directory'), + ('scripts=', None, 'set the global scripts directory'), ('images=', None, 'set the image directory'), ('encryption=', None, 'set the encryption template directory'), ('bin=', None, 'set the bin directory'), @@ -91,11 +93,11 @@ class configure(Command): ('no-install-ncurses', None, 'do not install the ncurses client') ] - def initialize_options(self): self.lib = '/usr/lib/wicd/' self.share = '/usr/share/wicd/' self.etc = '/etc/wicd/' + self.scripts = self.etc + "scripts/" self.icons = '/usr/share/icons/hicolor/' self.images = '/usr/share/pixmaps/wicd/' self.encryption = self.etc + 'encryption/templates/' @@ -175,10 +177,12 @@ class configure(Command): # If we don't get anything from *-config, or it didn't run properly, # or the path is not a proper absolute path, raise an error try: - pmtemp = subprocess.Popen(["pkg-config","--variable=pm_sleephooks","pm-utils"], stdout=subprocess.PIPE) + pmtemp = subprocess.Popen(["pkg-config", "--variable=pm_sleephooks", + "pm-utils"], stdout=subprocess.PIPE) returncode = pmtemp.wait() # let it finish, and get the exit code pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout - if len(pmutils_candidate) == 0 or returncode != 0 or not os.path.isabs(pmutils_candidate): + if len(pmutils_candidate) == 0 or returncode != 0 or \ + not os.path.isabs(pmutils_candidate): raise ValueError else: self.pmutils = pmutils_candidate @@ -189,7 +193,8 @@ class configure(Command): kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE) returncode = kdetemp.wait() # let it finish, and get the exit code kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout - if len(kdedir_candidate) == 0 or returncode != 0 or not os.path.isabs(kdedir_candidate): + if len(kdedir_candidate) == 0 or returncode != 0 or \ + not os.path.isabs(kdedir_candidate): raise ValueError else: self.kdedir = kdedir_candidate + '/share/autostart' @@ -199,10 +204,11 @@ class configure(Command): kde4temp = subprocess.Popen(["kde4-config","--prefix"], stdout=subprocess.PIPE) returncode = kde4temp.wait() # let it finish, and get the exit code kde4dir_candidate = kde4temp.stdout.readline().strip() # read stdout - if len(kde4dir_candidate) == 0 or returncode != 0 or not os.path.isabs(kde4dir_candidate): + if len(kde4dir_candidate) == 0 or returncode != 0 or \ + not os.path.isabs(kde4dir_candidate): raise ValueError else: - self.kdedir = kde4dir_candidate + '/share/autostart' + self.kdedir = kde4dir_candidate + '/share/autostart' except (OSError, ValueError): # If neither kde-config nor kde4-config are not present or # return an error, then we can assume that kde isn't installed @@ -216,15 +222,12 @@ class configure(Command): self.initfilename = os.path.basename(self.initfile) self.wicdgroup = 'users' - def finalize_options(self): - if self.distro_detect_failed == True: - if not self.no_install_init: - if self.init == 'FAIL' or self.initfile == 'FAIL': - print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \ - 'Please specify --init and --initfile to continue with configuration.' - - + if self.distro_detect_failed and not self.no_install_init and \ + 'FAIL' in [self.init, self.initfile]: + print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \ + 'Please specify --init and --initfile to continue with configuration.' + # loop through the argument definitions in user_options for argument in self.user_options: # argument name is the first item in the user_options list @@ -247,12 +250,15 @@ class configure(Command): values = list() for argument in self.user_options: if argument[0].endswith('='): - print argument[0][:-1],'is', - print getattr(self, argument[0][:-1]) - values.append((argument[0][:-1], getattr(self, argument[0][:-1].replace('-','_')))) + cur_arg = argument[0][:-1] + cur_arg_value = getattr(self, cur_arg) + print "%s is %s" % (cur_arg, cur_arg_value) + values.append((cur_arg, cur_arg_value.replace('-', '_'))) else: - print "Found switch",argument,getattr(self, argument[0].replace('-','_')) - values.append((argument[0], bool(getattr(self, argument[0].replace('-','_'))))) + cur_arg = argument[0] + cur_arg_value = getattr(self, cur_arg.replace('-', '_')) + print "Found switch %s %s" % (argument, cur_arg_value) + values.append((cur_arg, bool(cur_arg_value))) print 'Replacing values in template files...' for item in os.listdir('in'): @@ -265,7 +271,8 @@ class configure(Command): item_out = open(final_name, 'w') for line in item_in.readlines(): for item, value in values: - line = line.replace('%' + str(item.upper().replace('-','_')) + '%', str(value)) + line = line.replace('%' + str(item.upper().replace('-','_')) + \ + '%', str(value)) # other things to replace that aren't arguments line = line.replace('%VERSION%', str(VERSION_NUM)) @@ -353,7 +360,8 @@ class get_translations(Command): shutil.move(pofile, lang_identifier+'.po') print 'Got',lang_identifier os.makedirs('translations/'+lang_identifier+'/LC_MESSAGES') - os.system('msgfmt --output-file=translations/'+lang_identifier+'/LC_MESSAGES/wicd.mo '+lang_identifier+'.po') + os.system('msgfmt --output-file=translations/' + lang_identifier + + '/LC_MESSAGES/wicd.mo ' + lang_identifier + '.po') os.remove(lang_identifier+'.po') @@ -373,7 +381,7 @@ class uninstall(Command): try: import wpath -except: +except ImportError: print '''Error importing wpath.py. You can safely ignore this message. It is probably because you haven't run python setup.py configure yet or you are running it for the first time.''' @@ -400,22 +408,29 @@ try: (wpath.icons + '22x22/apps/', ['icons/22px/wicd-client.png']), (wpath.icons + '16x16/apps/', ['icons/16px/wicd-client.png']), (wpath.images, [('images/' + b) for b in os.listdir('images') if not b.startswith('.')]), - (wpath.encryption, [('encryption/templates/' + b) for b in os.listdir('encryption/templates') if not b.startswith('.')]), + (wpath.encryption, [('encryption/templates/' + b) for b in + os.listdir('encryption/templates') if not b.startswith('.')]), (wpath.networks, []), (wpath.bin, ['scripts/wicd-client', ]), (wpath.sbin, ['scripts/wicd', ]), (wpath.share, ['data/wicd.glade', ]), - (wpath.lib, ['wicd/wicd-client.py', 'wicd/monitor.py', 'wicd/wicd-daemon.py', 'wicd/configscript.py', 'wicd/suspend.py', 'wicd/autoconnect.py']), #'wicd/wicd-gui.py', + (wpath.lib, ['wicd/wicd-client.py', 'wicd/monitor.py', + 'wicd/wicd-daemon.py', 'wicd/configscript.py', + 'wicd/suspend.py', 'wicd/autoconnect.py']), (wpath.backends, ['wicd/backends/be-external.py', 'wicd/backends/be-ioctl.py']), (wpath.autostart, ['other/wicd-tray.desktop', ]), + (wpath.scripts, []), + (wpath.disconnectscripts, []), + (wpath.preconnectscripts, []), + (wpath.postconnectscripts, []), ] if not wpath.no_install_ncurses: - data.append(( wpath.lib, ['curses/curses_misc.py'])) - data.append(( wpath.lib, ['curses/prefs_curses.py'])) - data.append(( wpath.lib, ['curses/wicd-curses.py'])) - data.append(( wpath.lib, ['curses/netentry_curses.py'])) - data.append(( wpath.lib, ['curses/configscript_curses.py'])) - data.append(( wpath.bin, ['scripts/wicd-curses'])) + data.append((wpath.lib, ['curses/curses_misc.py'])) + data.append((wpath.lib, ['curses/prefs_curses.py'])) + data.append((wpath.lib, ['curses/wicd-curses.py'])) + data.append((wpath.lib, ['curses/netentry_curses.py'])) + data.append((wpath.lib, ['curses/configscript_curses.py'])) + data.append((wpath.bin, ['scripts/wicd-curses'])) if not wpath.no_install_man: data.append(( wpath.mandir + 'man8/', ['man/wicd-curses.8'])) piddir = os.path.dirname(wpath.pidfile) @@ -423,22 +438,23 @@ try: piddir += '/' data.append (( piddir, [] )) if not wpath.no_install_docs: - data.append(( wpath.docdir, [ 'INSTALL', 'LICENSE', 'AUTHORS', 'README', 'CHANGES','other/WHEREAREMYFILES' ])) + data.append((wpath.docdir, ['INSTALL', 'LICENSE', 'AUTHORS', + 'README', 'CHANGES', 'other/WHEREAREMYFILES'])) if not wpath.no_install_kde: - data.append(( wpath.kdedir, [ 'other/wicd-tray.desktop' ])) + data.append((wpath.kdedir, ['other/wicd-tray.desktop'])) if not wpath.no_install_init: - data.append(( wpath.init, [ wpath.initfile ])) + data.append((wpath.init, [ wpath.initfile ])) if not wpath.no_install_man: - data.append(( wpath.mandir + 'man8/', [ 'man/wicd.8' ])) - data.append(( wpath.mandir + 'man5/', [ 'man/wicd-manager-settings.conf.5' ])) - data.append(( wpath.mandir + 'man5/', [ 'man/wicd-wired-settings.conf.5' ])) - data.append(( wpath.mandir + 'man5/', [ 'man/wicd-wireless-settings.conf.5' ])) - data.append(( wpath.mandir + 'man1/', [ 'man/wicd-client.1' ])) + data.append((wpath.mandir + 'man8/', [ 'man/wicd.8' ])) + data.append((wpath.mandir + 'man5/', [ 'man/wicd-manager-settings.conf.5' ])) + data.append((wpath.mandir + 'man5/', [ 'man/wicd-wired-settings.conf.5' ])) + data.append((wpath.mandir + 'man5/', [ 'man/wicd-wireless-settings.conf.5' ])) + data.append((wpath.mandir + 'man1/', [ 'man/wicd-client.1' ])) if not wpath.no_install_acpi: - data.append(( wpath.resume, ['other/80-wicd-connect.sh' ])) - data.append(( wpath.suspend, ['other/50-wicd-suspend.sh' ])) + data.append((wpath.resume, ['other/80-wicd-connect.sh' ])) + data.append((wpath.suspend, ['other/50-wicd-suspend.sh' ])) if not wpath.no_install_pmutils: - data.append(( wpath.pmutils, ['other/55wicd' ])) + data.append((wpath.pmutils, ['other/55wicd' ])) print 'Using pid path', os.path.basename(wpath.pidfile) print 'Language support for', for language in os.listdir('translations/'): @@ -448,22 +464,24 @@ try: if codes[0].lower() == codes[1].lower(): short_language = codes[0].lower() print short_language, - data.append((wpath.translations + short_language + '/LC_MESSAGES/', ['translations/' + language + '/LC_MESSAGES/wicd.mo'])) - print + data.append((wpath.translations + short_language + '/LC_MESSAGES/', + ['translations/' + language + '/LC_MESSAGES/wicd.mo'])) except Exception, e: print str(e) print '''Error setting up data array. This is normal if python setup.py configure has not yet been run.''' -wpactrl_ext = Extension(name = 'wpactrl', sources = ['depends/python-wpactrl/wpa_ctrl.c', 'depends/python-wpactrl/wpactrl.c'], - extra_compile_args = ["-fno-strict-aliasing"]) +wpactrl_ext = Extension(name = 'wpactrl', + sources = ['depends/python-wpactrl/wpa_ctrl.c', + 'depends/python-wpactrl/wpactrl.c'], + extra_compile_args = ["-fno-strict-aliasing"]) -iwscan_ext = Extension(name = 'iwscan', - libraries = ['iw'], - sources = ['depends/python-iwscan/pyiwscan.c']) +iwscan_ext = Extension(name = 'iwscan', libraries = ['iw'], + sources = ['depends/python-iwscan/pyiwscan.c']) -setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, 'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated}, +setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, + 'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated}, name="Wicd", version=VERSION_NUM, description="A wireless and wired network manager", @@ -476,16 +494,12 @@ encryption types, such as WPA and WEP. Wicd will automatically connect at startup to any preferred network within range. """, author="Adam Blackburn, Dan O'Reilly", - author_email="compwiz18@users.sourceforge.net, imdano@users.sourceforge.net", + author_email="compwiz18@users.sourceforge.net, oreilldf@gmail.com", url="http://wicd.net", license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html", - ## scripts=['configscript.py', 'autoconnect.py', 'gui.py', 'wicd.py', 'daemon.py', 'suspend.py', 'monitor.py'], - py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath', - 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend', - 'wicd.configmanager', 'wicd.guiutil'], + py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', + 'wicd.wpath', 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', + 'wicd.logfile', 'wicd.backend', 'wicd.configmanager', 'wicd.guiutil'], ext_modules=[iwscan_ext, wpactrl_ext], data_files=data ) -##print "Running post-install configuration..." -##os.system("other/postinst") -##print 'Done.' diff --git a/wicd/backends/be-ioctl.py b/wicd/backends/be-ioctl.py index c799874..bce0986 100644 --- a/wicd/backends/be-ioctl.py +++ b/wicd/backends/be-ioctl.py @@ -296,6 +296,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): ap["bssid"] = cell["bssid"] ap["mode"] = cell["mode"] + ap["bitrates"] = cell["bitrate"] if cell["enc"]: ap["encryption"] = True @@ -484,14 +485,27 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): """ Get the current bitrate for the interface. """ if not self.iface: return "" data = (self.iface + '\0' * 32)[:32] + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + fmt = "ihbb" + size = struct.calcsize(fmt) try: - result = fcntl.ioctl(self.sock.fileno(), SIOCGIWAP, data)[16:] + data = fcntl.ioctl(s, 0x8B21, ifreq)[16:]  # 0x8B21 is SIOCGIWRATE in /usr/include/linux/wireless.h except IOError, e: if self.verbose: print "SIOCGIWAP failed: " + str(e) return "" - raw_addr = struct.unpack("xxBBBBBB", result[:8]) - return "%02X:%02X:%02X:%02X:%02X:%02X" % raw_addr + f, e, x, x = struct.unpack(fmt, data[:size]) + return (f / 1000000) + ' Mb/s' + + def GetOperationalMode(self, iwconfig=None): + """ Get the MAC address for the interface. """ + # TODO: implement me + return '' + + def GetAvailableAuthMethods(self, iwlistauth=None): + """ Get the MAC address for the interface. """ + # TODO: Implement me + return '' def GetSignalStrength(self, iwconfig=None): """ Get the signal strength of the current network. diff --git a/wicd/misc.py b/wicd/misc.py index feafbf7..cc57deb 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -58,7 +58,7 @@ ROUTE = 2 GKSUDO = 1 KDESU = 2 KTSUSS = 3 -__sudo_dict = { +_sudo_dict = { AUTO : "", GKSUDO : "gksudo", KDESU : "kdesu", @@ -172,9 +172,20 @@ def WriteLine(my_file, text): """ write a line to a file """ my_file.write(text + "\n") -def ExecuteScript(script): +def ExecuteScripts(scripts_dir, verbose=False): + """ Execute every executable file in a given directory. """ + for obj in os.listdir(scripts_dir): + obj = os.path.abspath(os.path.join(scripts_dir, obj)) + if os.path.isfile(obj) and os.access(obj, os.X_OK): + ExecuteScript(os.path.abspath(obj), verbose=verbose) + +def ExecuteScript(script, verbose=False): """ Execute a command and send its output to the bit bucket. """ - call("%s > /dev/null 2>&1" % script, shell=True) + if verbose: + print "Executing %s" % script + ret = call("%s > /dev/null 2>&1" % script, shell=True) + if verbose: + "%s returned %s" % (script, ret) def ReadFile(filename): """ read in a file and return it's contents as a string """ @@ -342,7 +353,11 @@ def get_gettext(): if osLanguage: langs += osLanguage.split(":") try: - lc, encoding = locale.getdefaultlocale() + # This avoids a bug: locale.getdefaultlocale() prefers + # LC_CTYPE over LANG/LANGUAGE + lc, encoding = locale.getdefaultlocale(envvars=('LC_MESSAGES', + 'LC_ALL', 'LANG', + 'LANGUAGE')) except ValueError, e: print str(e) print "Default locale unavailable, falling back to en_US" @@ -427,7 +442,7 @@ def get_sudo_cmd(msg, prog_num=0): def choose_sudo_prog(prog_num=0): """ Try to intelligently decide which graphical sudo program to use. """ if prog_num: - return find_path(__sudo_dict[prog_num]) + return find_path(_sudo_dict[prog_num]) desktop_env = detect_desktop_environment() env_path = os.environ['PATH'].split(":") paths = [] diff --git a/wicd/networking.py b/wicd/networking.py index ef4208e..883160b 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -46,7 +46,6 @@ import re import time import threading import os -import thread from signal import SIGTERM # wicd imports @@ -203,10 +202,12 @@ class Controller(object): def Disconnect(self, *args, **kargs): """ Disconnect from the network. """ iface = self.iface - if self.disconnect_script != None: + misc.ExecuteScripts(wpath.disconnectscripts, self.debug) + if self.disconnect_script: print 'Running disconnect script' misc.ExecuteScript(expand_script_macros(self.disconnect_script, - 'disconnection', *args)) + 'disconnection', *args), + self.debug) iface.ReleaseDHCP() iface.SetAddress('0.0.0.0') iface.FlushRoutes() @@ -268,7 +269,7 @@ class ConnectThread(threading.Thread): is_connecting = None should_die = False - lock = thread.allocate_lock() + lock = threading.Lock() def __init__(self, network, interface_name, before_script, after_script, disconnect_script, gdns1, gdns2, gdns3, gdns_dom, gsearch_dom, @@ -369,6 +370,10 @@ class ConnectThread(threading.Thread): self.SetStatus('interface_down') iface.Down() + @abortable + def run_global_scripts_if_needed(self, script_dir): + misc.ExecuteScripts(script_dir, verbose=self.debug) + @abortable def run_script_if_needed(self, script, msg, bssid='wired', essid='wired'): """ Execute a given script if needed. @@ -380,7 +385,8 @@ class ConnectThread(threading.Thread): """ if script: print 'Executing %s script' % (msg) - misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid)) + misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid), + self.debug) @abortable def flush_routes(self, iface): @@ -471,7 +477,7 @@ class ConnectThread(threading.Thread): try: if self._should_die: self.connect_aborted('aborted') - thread.exit() + raise SystemExit finally: self.lock.release() @@ -792,6 +798,7 @@ class WirelessConnectThread(ConnectThread): self.is_connecting = True # Run pre-connection script. + self.run_global_scripts_if_needed(wpath.preconnectscripts) self.run_script_if_needed(self.before_script, 'pre-connection', self.network['bssid'], self.network['essid']) @@ -834,6 +841,7 @@ class WirelessConnectThread(ConnectThread): self.set_dns_addresses() # Run post-connection script. + self.run_global_scripts_if_needed(wpath.postconnectscripts) self.run_script_if_needed(self.after_script, 'post-connection', self.network['bssid'], self.network['essid']) @@ -1002,6 +1010,7 @@ class WiredConnectThread(ConnectThread): self.is_connecting = True # Run pre-connection script. + self.run_global_scripts_if_needed(wpath.preconnectscripts) self.run_script_if_needed(self.before_script, 'pre-connection', 'wired', 'wired') @@ -1020,6 +1029,7 @@ class WiredConnectThread(ConnectThread): self.set_dns_addresses() # Run post-connection script. + self.run_global_scripts_if_needed(wpath.postconnectscripts) self.run_script_if_needed(self.after_script, 'post-connection', 'wired', 'wired')