From de8b8c11f8a992cad993fbff62ccac90700c4273 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Fri, 27 Feb 2009 00:13:00 -0500 Subject: [PATCH 1/5] Get rid of unneeded "use_tray" variable being passed around in wicd-client. Add some methods for executing multiple scripts to be use for global scripts later. Remove some rogue extra whitespace in networking.py --- wicd/misc.py | 21 +++++++++++++++----- wicd/networking.py | 10 +++++----- wicd/wicd-client.py | 47 +++++++++++++++------------------------------ 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/wicd/misc.py b/wicd/misc.py index d42418c..0a8f03d 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -57,7 +57,7 @@ ROUTE = 2 GKSUDO = 1 KDESU = 2 KTSUSS = 3 -sudo_dict = { +_sudo_dict = { AUTO : "", GKSUDO : "gksudo", KDESU : "kdesu", @@ -171,9 +171,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 """ @@ -409,7 +420,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 = [] @@ -667,4 +678,4 @@ def timeout_add(time, func, milli=False): else: if not milli: time = time * 1000 return gobject.timeout_add(time, func) - \ No newline at end of file + diff --git a/wicd/networking.py b/wicd/networking.py index b324663..4f9b797 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -396,7 +396,7 @@ class ConnectThread(threading.Thread): print 'Setting the broadcast address...' + self.network['broadcast'] iface.SetAddress(broadcast=self.network['broadcast']) - @abortable + @abortable def set_ip_address(self, iface): """ Set the IP address for the given interface. @@ -420,7 +420,7 @@ class ConnectThread(threading.Thread): self.abort_connection(dhcp_status) return - @abortable + @abortable def set_dns_addresses(self): """ Set the DNS address(es). @@ -443,7 +443,7 @@ class ConnectThread(threading.Thread): self.network.get('dns_domain'), self.network.get('search_domain')) - @abortable + @abortable def release_dhcp_clients(self, iface): """ Release all running dhcp clients. """ print "Releasing DHCP leases..." @@ -474,7 +474,7 @@ class ConnectThread(threading.Thread): finally: self.lock.release() - @abortable + @abortable def put_iface_up(self, iface): """ Bring up given interface. """ print 'Putting interface up...' @@ -819,7 +819,7 @@ class WirelessConnectThread(ConnectThread): print 'Stopping wpa_supplicant' wiface.StopWPA() - @abortable + @abortable def generate_psk_and_authenticate(self, wiface): """ Generates a PSK and authenticates if necessary. diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index cc04b19..85fcbae 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -109,12 +109,12 @@ class TrayIcon(object): Base Class for implementing a tray icon to display network status. """ - def __init__(self, use_tray, animate): + def __init__(self, animate): if USE_EGG: - self.tr = self.EggTrayIconGUI(use_tray) + self.tr = self.EggTrayIconGUI() else: - self.tr = self.StatusTrayIconGUI(use_tray) - self.icon_info = self.TrayConnectionInfo(self.tr, use_tray, animate) + self.tr = self.StatusTrayIconGUI() + self.icon_info = self.TrayConnectionInfo(self.tr, animate) def is_embedded(self): if USE_EGG: @@ -125,7 +125,7 @@ class TrayIcon(object): class TrayConnectionInfo(object): """ Class for updating the tray icon status. """ - def __init__(self, tr, use_tray=True, animate=True): + def __init__(self, tr, animate=True): """ Initialize variables needed for the icon status methods. """ self.last_strength = -2 self.still_wired = False @@ -133,7 +133,6 @@ class TrayIcon(object): self.tried_reconnect = False self.connection_lost_counter = 0 self.tr = tr - self.use_tray = use_tray self.last_sndbytes = -1 self.last_rcvbytes = -1 self.max_snd_gain = 10000 @@ -203,7 +202,7 @@ class TrayIcon(object): @catchdbus def update_tray_icon(self, state=None, info=None): """ Updates the tray icon and current connection status. """ - if not self.use_tray or not DBUS_AVAIL: return False + if not DBUS_AVAIL: return False if not state or not info: [state, info] = daemon.GetConnectionStatus() @@ -330,7 +329,7 @@ class TrayIcon(object): tray icons. """ - def __init__(self, use_tray): + def __init__(self): menu = """ @@ -361,7 +360,6 @@ class TrayIcon(object): props.parent) self.gui_win = None self.current_icon_path = None - self.use_tray = use_tray self._is_scanning = False net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/") net_menuitem.connect("activate", self.on_net_menu_activate) @@ -571,14 +569,9 @@ class TrayIcon(object): for machines running versions of GTK < 2.10. """ - def __init__(self, use_tray=True): + def __init__(self): """Initializes the tray icon""" - TrayIcon.TrayIconGUI.__init__(self, use_tray) - self.use_tray = use_tray - if not use_tray: - self.toggle_wicd_gui() - return - + TrayIcon.TrayIconGUI.__init__(self) self.tooltip = gtk.Tooltips() self.eb = gtk.EventBox() self.tray = egg.trayicon.TrayIcon("WicdTrayIcon") @@ -601,7 +594,6 @@ class TrayIcon(object): def set_from_file(self, val=None): """ Calls set_from_file on the gtk.Image for the tray icon. """ - if not self.use_tray: return self.pic.set_from_file(val) def set_tooltip(self, val): @@ -611,7 +603,6 @@ class TrayIcon(object): tray icon. """ - if not self.use_tray: return self.tooltip.set_tip(self.eb, val) @@ -622,13 +613,8 @@ class TrayIcon(object): Uses gtk.StatusIcon to implement a tray icon. """ - def __init__(self, use_tray=True): - TrayIcon.TrayIconGUI.__init__(self, use_tray) - self.use_tray = use_tray - if not use_tray: - self.toggle_wicd_gui() - return - + def __init__(self): + TrayIcon.TrayIconGUI.__init__(self) gtk.StatusIcon.__init__(self) self.current_icon_path = '' @@ -645,7 +631,6 @@ class TrayIcon(object): def set_from_file(self, path=None): """ Sets a new tray icon picture. """ - if not self.use_tray: return if path != self.current_icon_path: self.current_icon_path = path gtk.StatusIcon.set_from_file(self, path) @@ -716,9 +701,6 @@ def main(argv): argv -- The arguments passed to the script. """ - use_tray = True - animate = True - try: opts, args = getopt.getopt(sys.argv[1:], 'nha', ['help', 'no-tray', 'no-animate']) @@ -727,6 +709,8 @@ def main(argv): usage() sys.exit(2) + use_tray = True + animate = True for opt, a in opts: if opt in ('-h', '--help'): usage() @@ -750,7 +734,7 @@ def main(argv): sys.exit(0) # Set up the tray icon GUI and backend - tray_icon = TrayIcon(use_tray, animate) + tray_icon = TrayIcon(animate) # Check to see if wired profile chooser was called before icon # was launched (typically happens on startup or daemon restart). @@ -767,7 +751,8 @@ def main(argv): 'org.wicd.daemon.wireless') bus.add_signal_receiver(tray_icon.tr.tray_scan_started, 'SendStartScanSignal', 'org.wicd.daemon.wireless') - bus.add_signal_receiver(lambda: handle_no_dbus() or tray_icon.icon_info.set_not_connected_state(), + bus.add_signal_receiver(lambda: (handle_no_dbus() or + tray_icon.icon_info.set_not_connected_state()), "DaemonClosing", 'org.wicd.daemon') bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting", "org.wicd.daemon") From e40afce1041439046465a68d38ec82e42b4ccf7f Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Fri, 27 Feb 2009 00:40:19 -0500 Subject: [PATCH 2/5] Initial crack at global scripts support. Also includes some setup.py tweaks. --- in/wicd=wpath.py.in | 4 ++++ setup.py | 56 +++++++++++++++++++++++++++------------------ wicd/networking.py | 17 +++++++++++--- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/in/wicd=wpath.py.in b/in/wicd=wpath.py.in index fa4a753..2d27b0e 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 = '%DISCONNECTSCRIPTS%' +preconnectscripts = '%PRECONNECTSCRIPTS%' +postconnectscripts = '%POSTCONNECTSCRIPTS%' images = '%IMAGES%' encryption = '%ENCRYPTION%' bin = '%BIN%' diff --git a/setup.py b/setup.py index 92ffc2c..68af3ab 100755 --- a/setup.py +++ b/setup.py @@ -51,6 +51,10 @@ 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'), + ('disconnectscripts=', None, 'set the global disconnect scripts directory'), + ('preconnectscripts=', None, 'set the global preconnect scripts directory'), + ('postconnectscripts=', None, 'set the global postconnect scripts directory'), ('images=', None, 'set the image directory'), ('encryption=', None, 'set the encryption template directory'), ('bin=', None, 'set the bin directory'), @@ -96,6 +100,10 @@ class configure(Command): self.lib = '/usr/lib/wicd/' self.share = '/usr/share/wicd/' self.etc = '/etc/wicd/' + self.scripts = self.etc + "scripts/" + self.preconnectscripts = self.scripts + "preconnect/" + self.postconnectscripts = self.scripts + "postconnect/" + self.disconnectscripts = self.scripts + "disconnect/" self.icons = '/usr/share/icons/hicolor/' self.images = '/usr/share/pixmaps/wicd/' self.encryption = self.etc + 'encryption/templates/' @@ -175,10 +183,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 +199,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' @@ -218,11 +229,10 @@ class configure(Command): 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 @@ -408,6 +418,10 @@ try: (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.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'])) @@ -456,14 +470,16 @@ except Exception, e: 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 +492,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/networking.py b/wicd/networking.py index c308790..26c71bc 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -202,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() @@ -368,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. @@ -379,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): @@ -761,6 +768,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']) @@ -803,6 +811,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']) @@ -971,6 +980,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') @@ -989,6 +999,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') From edbfd1855326ed40da73d83d29dc4b960940cbd8 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sat, 28 Feb 2009 15:34:34 -0500 Subject: [PATCH 3/5] Don't use the thread module in networking.py. --- wicd/networking.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wicd/networking.py b/wicd/networking.py index c308790..efb62c5 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -45,7 +45,6 @@ import re import time import threading import os -import thread from signal import SIGTERM # wicd imports @@ -267,7 +266,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, @@ -470,7 +469,7 @@ class ConnectThread(threading.Thread): try: if self._should_die: self.connect_aborted('aborted') - thread.exit() + raise SystemExit finally: self.lock.release() From 5f6807732ab90b77b09d88bae7ad3f3bf92efc93 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sun, 1 Mar 2009 22:43:28 -0500 Subject: [PATCH 4/5] Don't provide separate options for pre/post/disconnect scripts. Just a parent scripts directory. --- in/wicd=wpath.py.in | 6 ++-- setup.py | 84 +++++++++++++++++++++++---------------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/in/wicd=wpath.py.in b/in/wicd=wpath.py.in index 2d27b0e..8f82101 100755 --- a/in/wicd=wpath.py.in +++ b/in/wicd=wpath.py.in @@ -27,9 +27,9 @@ lib = '%LIB%' share = '%SHARE%' etc = '%ETC%' scripts = '%SCRIPTS%' -disconnectscripts = '%DISCONNECTSCRIPTS%' -preconnectscripts = '%PRECONNECTSCRIPTS%' -postconnectscripts = '%POSTCONNECTSCRIPTS%' +disconnectscripts = '%SCRIPTS%disconnect' +preconnectscripts = '%SCRIPTS%preconnect' +postconnectscripts = '%SCRIPTS%postconnect' images = '%IMAGES%' encryption = '%ENCRYPTION%' bin = '%BIN%' diff --git a/setup.py b/setup.py index 68af3ab..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" @@ -52,9 +53,6 @@ class configure(Command): ('share=', None, 'set the share directory'), ('etc=', None, 'set the etc directory'), ('scripts=', None, 'set the global scripts directory'), - ('disconnectscripts=', None, 'set the global disconnect scripts directory'), - ('preconnectscripts=', None, 'set the global preconnect scripts directory'), - ('postconnectscripts=', None, 'set the global postconnect scripts directory'), ('images=', None, 'set the image directory'), ('encryption=', None, 'set the encryption template directory'), ('bin=', None, 'set the bin directory'), @@ -95,15 +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.preconnectscripts = self.scripts + "preconnect/" - self.postconnectscripts = self.scripts + "postconnect/" - self.disconnectscripts = self.scripts + "disconnect/" self.icons = '/usr/share/icons/hicolor/' self.images = '/usr/share/pixmaps/wicd/' self.encryption = self.etc + 'encryption/templates/' @@ -210,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 @@ -227,14 +222,12 @@ class configure(Command): self.initfilename = os.path.basename(self.initfile) self.wicdgroup = 'users' - def finalize_options(self): 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 @@ -257,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'): @@ -275,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)) @@ -363,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') @@ -383,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.''' @@ -410,12 +408,15 @@ 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, []), @@ -424,12 +425,12 @@ try: (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) @@ -437,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/'): @@ -462,8 +464,8 @@ 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 From 6dd064207908006e9d7449a2f6e263dc1ddc7c97 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sun, 1 Mar 2009 23:15:34 -0500 Subject: [PATCH 5/5] Apply lang patch from David Paleino --- wicd/misc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wicd/misc.py b/wicd/misc.py index 1a53b5c..cc57deb 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -353,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"