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/6] 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/6] 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/6] 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/6] 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/6] 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" From a1169cb1df67ef355e08e7faac87d98888575c68 Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Wed, 4 Mar 2009 00:02:14 -0500 Subject: [PATCH 6/6] Added translations.py, and adapted all gtk and curses ui files to use it. Moved the language dict functions and get_gettext to translations.py. Also killed the functions and laid the dict bare in the file Removed all instances of language[number] from wicd. --- curses/netentry_curses.py | 10 +- curses/prefs_curses.py | 4 +- curses/wicd-curses.py | 7 +- setup.py | 12 +- wicd/gui.py | 2 +- wicd/misc.py | 221 ------------------------------------- wicd/netentry.py | 8 +- wicd/prefs.py | 2 +- wicd/translations.py | 226 ++++++++++++++++++++++++++++++++++++++ wicd/wicd-client.py | 7 +- 10 files changed, 254 insertions(+), 245 deletions(-) create mode 100644 wicd/translations.py diff --git a/curses/netentry_curses.py b/curses/netentry_curses.py index c00c887..52f89cc 100644 --- a/curses/netentry_curses.py +++ b/curses/netentry_curses.py @@ -28,7 +28,9 @@ from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool -language = misc.get_language_list_gui() +from wicd.translations import language +for i in language.keys(): + language[i] = language[i].decode('utf8') daemon = None wired = None @@ -56,9 +58,9 @@ class AdvancedSettingsDialog(urwid.WidgetWrap): use_global_dns_t = language['use_global_dns'] dns_dom_t = ('editcp',language['dns_domain']+': ') search_dom_t = ('editcp',language['search_domain']+':') - dns1_t = ('editcp',language['dns']+ ' ' + language['1']+':'+' '*8) - dns2_t = ('editcp',language['dns']+ ' ' + language['2']+':'+' '*8) - dns3_t = ('editcp',language['dns']+ ' ' + language['3']+':'+' '*8) + dns1_t = ('editcp',language['dns']+ ' 1'+':'+' '*8) + dns2_t = ('editcp',language['dns']+ ' 2'+':'+' '*8) + dns3_t = ('editcp',language['dns']+ ' 3'+':'+' '*8) cancel_t = 'Cancel' ok_t = 'OK' diff --git a/curses/prefs_curses.py b/curses/prefs_curses.py index 992bc84..c13d756 100755 --- a/curses/prefs_curses.py +++ b/curses/prefs_curses.py @@ -28,7 +28,9 @@ daemon = None wireless = None wired = None -language = misc.get_language_list_gui() +from wicd.translations import language +for i in language.keys(): + language[i] = language[i].decode('utf8') class PrefsDialog(urwid.WidgetWrap): def __init__(self,body,pos,ui,dbus=None): diff --git a/curses/wicd-curses.py b/curses/wicd-curses.py index 0428085..cc4dce3 100644 --- a/curses/wicd-curses.py +++ b/curses/wicd-curses.py @@ -67,9 +67,10 @@ from optparse import OptionParser CURSES_REVNO=wpath.curses_revision -language = misc.get_language_list_gui() -# We need 'Connecting' without the '...' -language['connecting']=misc.get_language_list_tray()['connecting'] +# Fix strings in wicd-curses +from wicd.translations import language +for i in language.keys(): + language[i] = language[i].decode('utf8') ######################################## ##### SUPPORT CLASSES diff --git a/setup.py b/setup.py index b8bf723..ae80399 100755 --- a/setup.py +++ b/setup.py @@ -162,7 +162,6 @@ class configure(Command): self.init = '/etc/rc.d/' else: self.init = 'FAIL' - self.initfile = 'FAIL' self.no_install_init = True self.distro_detect_failed = True print 'WARNING: Unable to detect the distribution in use. ' + \ @@ -490,16 +489,17 @@ Wicd supports wired and wireless networks, and capable of creating and tracking profiles for both. It has a template-based wireless encryption system, which allows the user to easily add encryption methods used. It ships with some common -encryption types, such as WPA and WEP. Wicd will automatically +encryption types, such as WPA and WEP. Wicdl will automatically connect at startup to any preferred network within range. """, author="Adam Blackburn, Dan O'Reilly", - author_email="compwiz18@users.sourceforge.net, oreilldf@gmail.com", + author_email="compwiz18@gmail.com, oreilldf@gmail.com", url="http://wicd.net", license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html", - 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','wicd.translations'], ext_modules=[iwscan_ext, wpactrl_ext], data_files=data ) diff --git a/wicd/gui.py b/wicd/gui.py index 1f23fb8..4be5bfb 100644 --- a/wicd/gui.py +++ b/wicd/gui.py @@ -43,12 +43,12 @@ from wicd.misc import noneToString from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry from wicd.prefs import PreferencesDialog from wicd.guiutil import error, GreyLabel, LabelEntry, SmallLabel +from wicd.translations import language if __name__ == '__main__': wpath.chdir(__file__) proxy_obj = daemon = wireless = wired = bus = None -language = misc.get_language_list_gui() DBUS_AVAIL = False def setup_dbus(force=True): diff --git a/wicd/misc.py b/wicd/misc.py index cc57deb..dac2743 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -19,7 +19,6 @@ import os import locale -import gettext import sys import re import gobject @@ -339,36 +338,6 @@ def noneToString(text): else: return str(text) -def get_gettext(): - """ Set up gettext for translations. """ - # Borrowed from an excellent post on how to do this at - # http://www.learningpython.com/2006/12/03/translating-your-pythonpygtk-application/ - local_path = wpath.translations - langs = [] - osLanguage = os.environ.get('LANGUAGE', None) - if osLanguage: - langs += osLanguage.split(":") - osLanguage = None - osLanguage = os.environ.get('LC_MESSAGES', None) - if osLanguage: - langs += osLanguage.split(":") - try: - # 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" - if (lc): - langs += [lc] - langs += ["en_US"] - lang = gettext.translation('wicd', local_path, languages=langs, - fallback=True) - _ = lang.gettext - return _ - def to_unicode(x): """ Attempts to convert a string to utf-8. """ # If this is a unicode string, encode it and return @@ -478,196 +447,6 @@ def find_path(cmd): return os.path.join(path, cmd) return None -def get_language_list_gui(): - """ Returns a dict of translatable strings used by the GUI. - - Translations are done at http://wicd.net/translator. Please - translate if you can. - - """ - _ = get_gettext() - language = {} - language['connect'] = _("Connect") - language['ip'] = _("IP") - language['netmask'] = _("Netmask") - language['gateway'] = _('Gateway') - language['dns'] = _('DNS') - language['use_static_ip'] = _('Use Static IPs') - language['use_static_dns'] = _('Use Static DNS') - language['use_encryption'] = _('Use Encryption') - language['advanced_settings'] = _('Advanced Settings') - language['properties'] = _('Properties') - language['wired_network'] = _('Wired Network') - language['wired_network_instructions'] = _('To connect to a wired network,' - ' you must create a network profile. To create a network profile, type a' - ' name that describes this network, and press Add.') - language['automatic_connect'] = _('Automatically connect to this network') - language['secured'] = _('Secured') - language['unsecured'] = _('Unsecured') - language['channel'] = _('Channel') - language['preferences'] = _('Preferences') - language['wpa_supplicant_driver'] = _('WPA Supplicant Driver') - language['wireless_interface'] = _('Wireless Interface') - language['wired_interface'] = _('Wired Interface') - language['hidden_network'] = _('Hidden Network') - language['hidden_network_essid'] = _('Hidden Network ESSID') - language['connected_to_wireless'] = _('Connected to $A at $B (IP: $C)') - language['connected_to_wired'] = _('Connected to wired network (IP: $A)') - language['not_connected'] = _('Not connected') - language['no_wireless_networks_found'] = _('No wireless networks found.') - language['killswitch_enabled'] = _('Wireless Kill Switch Enabled') - language['key'] = _('Key') - language['username'] = _('Username') - language['password'] = _('Password') - language['anonymous_identity'] = _('Anonymous Identity') - language['identity'] = _('Identity') - language['authentication'] = _('Authentication') - language['path_to_pac_file'] = _('Path to PAC File') - language['select_a_network'] = _('Choose from the networks below:') - language['connecting'] = _('Connecting...') - language['wired_always_on'] = _('Always show wired interface') - language['auto_reconnect'] = _('Automatically reconnect on connection loss') - language['create_adhoc_network'] = _('Create an Ad-Hoc Network') - language['essid'] = _('ESSID') - language['use_wep_encryption'] = _('Use Encryption (WEP only)') - language['before_script'] = _('Run script before connect') - language['after_script'] = _('Run script after connect') - language['disconnect_script'] = _('Run disconnect script') - language['script_settings'] = _('Scripts') - language['use_ics'] = _('Activate Internet Connection Sharing') - language['madwifi_for_adhoc'] = _('Check if using madwifi/atheros drivers') - language['default_wired'] = _('Use as default profile (overwrites any previous default)') - language['use_debug_mode'] = _('Enable debug mode') - language['use_global_dns'] = _('Use global DNS servers') - language['use_default_profile'] = _('Use default profile on wired autoconnect') - language['show_wired_list'] = _('Prompt for profile on wired autoconnect') - language['use_last_used_profile'] = _('Use last used profile on wired autoconnect') - language['choose_wired_profile'] = _('Select or create a wired profile to connect with') - language['wired_network_found'] = _('Wired connection detected') - language['stop_showing_chooser'] = _('Stop Showing Autoconnect pop-up temporarily') - language['display_type_dialog'] = _('Use dBm to measure signal strength') - language['scripts'] = _('Scripts') - #language['invalid_address'] = _('Invalid address in $A entry.') - language['global_settings'] = _('Use these settings for all networks sharing this essid') - language['encrypt_info_missing'] = _('Required encryption information is missing.') - language['enable_encryption'] = _('This network requires encryption to be enabled.') - language['wicd_auto_config'] = _('Automatic (recommended)') - language["gen_settings"] = _("General Settings") - language["ext_programs"] = _("External Programs") - language["dhcp_client"] = _("DHCP Client") - language["wired_detect"] = _("Wired Link Detection") - language["route_flush"] = _("Route Table Flushing") - language["backend"] = _("Backend") - language["backend_alert"] = _("Changes to your backend won't occur until the daemon is restarted.") - language['dns_domain'] = _("DNS domain") - language['search_domain'] = _("Search domain") - language['global_dns_not_enabled'] = _("Global DNS has not been enabled in general preferences.") - language['scripts_need_pass'] = _('You must enter your password to configure scripts') - language['no_sudo_prog'] = _("Could not find a graphical sudo program. The script editor could not be launched." + - " You'll have to edit scripts directly your configuration file.") - - language['0'] = _('0') - language['1'] = _('1') - language['2'] = _('2') - language['3'] = _('3') - language['4'] = _('4') - language['5'] = _('5') - language['6'] = _('6') - language['7'] = _('7') - language['8'] = _('8') - language['9'] = _('9') - - language['interface_down'] = _('Putting interface down...') - language['resetting_ip_address'] = _('Resetting IP address...') - language['interface_up'] = _('Putting interface up...') - language['setting_encryption_info'] = _('Setting encryption info') - language['removing_old_connection'] = _('Removing old connection...') - language['generating_psk'] = _('Generating PSK...') - language['generating_wpa_config'] = _('Generating WPA configuration file...') - language['flushing_routing_table'] = _('Flushing the routing table...') - language['configuring_interface'] = _('Configuring wireless interface...') - language['validating_authentication'] = _('Validating authentication...') - language['setting_broadcast_address'] = _('Setting broadcast address...') - language['setting_static_dns'] = _('Setting static DNS servers...') - language['setting_static_ip'] = _('Setting static IP addresses...') - language['running_dhcp'] = _('Obtaining IP address...') - language['dhcp_failed'] = _('Connection Failed: Unable to Get IP Address') - language['no_dhcp_offers'] = _('Connection Failed: No DHCP offers received.') - language['aborted'] = _('Connection Cancelled') - language['bad_pass'] = _('Connection Failed: Could not authenticate (bad password?)') - language['done'] = _('Done connecting...') - language['scanning'] = _('Scanning') - language['scanning_stand_by'] = _('Scanning networks... stand by...') - language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface. " + \ - "This typically means there was a problem starting the daemon. " + \ - "Check the wicd log for more info") - language['lost_dbus'] = _("The wicd daemon has shut down, the UI will not function properly until it is restarted.") - language['configuring_wireless'] = _("Configuring preferences for wireless network \"$A\" ($B)") - language['configuring_wired'] = _("Configuring preferences for wired profile \"$A\"") - language['scan'] = _('Scan') - language['always_switch_to_wired'] = _("Always switch to wired connection when available") - language['wired_autoconnect_settings'] = _("Wired Autoconnect Settings") - language['always_use_wext'] = _("You should almost always use wext as the WPA supplicant driver") - language['debugging'] = _("Debugging") - language['wpa_supplicant'] = _("WPA Supplicant") - language['automatic_reconnection'] = _("Automatic Reconnection") - language['global_dns_servers'] = _("Global DNS servers") - language['network_interfaces'] = _("Network Interfaces") - language['connecting_to_daemon'] = _("Connecting to daemon...") - language['cannot_connect_to_daemon'] = _("Can't connect to the daemon, trying to start it automatically...") - language['could_not_connect'] = _("Could not connect to wicd's D-Bus interface. Check the wicd log for error messages.") - language["exception"] = _("EXCEPTION! Please report this to the maintainer and file a bug report with the backtrace below:") - language["brought_to_you"] = _("Brought to you by:") - language["cannot_edit_scripts_1"] = _('To avoid various complications, wicd-curses does not support directly editing the scripts directly. However, you can edit them manually. First, (as root), open the "$A" config file, and look for the section labeled by the $B in question. In this case, this is:') - language["cannot_edit_scripts_2"] = _('Once here, you can adjust (or add) the "beforescript", "afterscript", and "disconnectscript" variables as needed, to change the preconnect, postconnect, and disconnect scripts respectively. Alternatively, you can configure the wireless networks by ESSID, by looking for the "[]" field in the config file.') - language["add_new_profile"] = _("Add a new profile") - language["add_new_wired_profile"] = _("Add a new wired profile") - language["no_delete_last_profile"] = _("wicd-curses does not support deleting the last wired profile. Try renaming it ('F2')") - language["rename_wired_profile"] = _("Rename wired profile") - language["select_hidden_essid"] = _("Select Hidden Network ESSID") - language["esc_to_cancel"] = _("Press ESC to cancel") - language["press_to_quit"] = _("Press F8 or Q to quit.") - - language['terminated'] = _("Terminated by user") - language['wicd_curses'] = _("Wicd Curses Interface") - language['dbus_fail'] = _("DBus failure! This is most likely caused by the wicd daemon stopping while wicd-curses is running. Please restart the daemon, and then restart wicd-curses.") - - # Fix strings in wicd-curses - for i in language.keys(): - try : - language[i] = language[i].decode('utf8') - except: - print "\"%s\"" % language[i] - raise - - - return language - -def get_language_list_tray(): - """ Returns a dict of translatable strings used by the tray icon. - - Translations are done at http://wicd.net/translator. Please - translate if you can. - - """ - _ = get_gettext() - language = {} - language['connected_to_wireless'] = _('Connected to $A at $B (IP: $C)') - language['connected_to_wired'] = _('Connected to wired network (IP: $A)') - language['not_connected'] = _('Not connected') - language['killswitch_enabled'] = _('Wireless Kill Switch Enabled') - language['connecting'] = _('Connecting') - language['wired'] = _('Wired Network') - language['scanning'] = _('Scanning') - language['no_wireless_networks_found'] = _('No wireless networks found.') - language['daemon_unavailable'] = _("The wicd daemon is unavailable, so your request cannot be completed") - language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface." + \ - "This typically means there was a problem starting the daemon." + \ - "Check the wicd log for more info") - language['no_daemon_tooltip'] = _("Wicd daemon unreachable") - language['lost_dbus'] = _("The wicd daemon has shut down, the UI will not function properly until it is restarted.") - return language - def noneToBlankString(text): """ Converts NoneType or "None" to a blank string. """ if text in (None, "None"): diff --git a/wicd/netentry.py b/wicd/netentry.py index 0e1f8fc..58e0be9 100644 --- a/wicd/netentry.py +++ b/wicd/netentry.py @@ -24,7 +24,7 @@ import dbusmanager from misc import noneToString, stringToNone, noneToBlankString, to_bool from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel, string_input -language = misc.get_language_list_gui() +from translations import language # These get set when a NetworkEntry is instantiated. daemon = None @@ -57,9 +57,9 @@ class AdvancedSettingsDialog(gtk.Dialog): self.txt_gateway = LabelEntry(language['gateway']) self.txt_search_dom = LabelEntry(language['search_domain']) self.txt_domain = LabelEntry(language['dns_domain']) - self.txt_dns_1 = LabelEntry(language['dns'] + ' ' + language['1']) - self.txt_dns_2 = LabelEntry(language['dns'] + ' ' + language['2']) - self.txt_dns_3 = LabelEntry(language['dns'] + ' ' + language['3']) + self.txt_dns_1 = LabelEntry(language['dns'] + ' 1') + self.txt_dns_2 = LabelEntry(language['dns'] + ' 2') + self.txt_dns_3 = LabelEntry(language['dns'] + ' 3') self.chkbox_static_ip = gtk.CheckButton(language['use_static_ip']) self.chkbox_static_dns = gtk.CheckButton(language['use_static_dns']) self.chkbox_global_dns = gtk.CheckButton(language['use_global_dns']) diff --git a/wicd/prefs.py b/wicd/prefs.py index 2adfc6d..d25267b 100644 --- a/wicd/prefs.py +++ b/wicd/prefs.py @@ -39,7 +39,7 @@ daemon = None wireless = None wired = None -language = misc.get_language_list_gui() +from translations import language def setup_dbus(): global daemon, wireless, wired diff --git a/wicd/translations.py b/wicd/translations.py new file mode 100644 index 0000000..e9523b1 --- /dev/null +++ b/wicd/translations.py @@ -0,0 +1,226 @@ +#!/usr/bin/env python +# -* coding: utf-8 -*- +# ^^ why do I need this? + +# +# Copyright (C) 2007 - 2009 Adam Blackburn +# Copyright (C) 2007 - 2009 Dan O'Reilly +# Copyright (C) 2009 Andrew Psaltis +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License Version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +import locale +import os +import wpath +import gettext + + +def get_gettext(): + """ Set up gettext for translations. """ + # Borrowed from an excellent post on how to do this at + # http://www.learningpython.com/2006/12/03/translating-your-pythonpygtk-application/ + local_path = wpath.translations + langs = [] + osLanguage = os.environ.get('LANGUAGE', None) + if osLanguage: + langs += osLanguage.split(":") + osLanguage = None + osLanguage = os.environ.get('LC_MESSAGES', None) + if osLanguage: + langs += osLanguage.split(":") + try: + # 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" + if (lc): + langs += [lc] + langs += ["en_US"] + lang = gettext.translation('wicd', local_path, languages=langs, + fallback=True) + _ = lang.gettext + return _ + +_ = get_gettext() +language = {} +language['connect'] = _('Connect') +language['ip'] = _('IP') +language['netmask'] = _('Netmask') +language['gateway'] = _('Gateway') +language['dns'] = _('DNS') +language['use_static_ip'] = _('Use Static IPs') +language['use_static_dns'] = _('Use Static DNS') +language['use_encryption'] = _('Use Encryption') +language['advanced_settings'] = _('Advanced Settings') +language['properties'] = _('Properties') +language['wired_network'] = _('Wired Network') +language['wired_network_instructions'] = _('To connect to a wired network,' +' you must create a network profile. To create a network profile, type a' +' name that describes this network, and press Add.') +language['automatic_connect'] = _('Automatically connect to this network') +language['secured'] = _('Secured') +language['unsecured'] = _('Unsecured') +language['channel'] = _('Channel') +language['preferences'] = _('Preferences') +language['wpa_supplicant_driver'] = _('WPA Supplicant Driver') +language['wireless_interface'] = _('Wireless Interface') +language['wired_interface'] = _('Wired Interface') +language['hidden_network'] = _('Hidden Network') +language['hidden_network_essid'] = _('Hidden Network ESSID') +language['connected_to_wireless'] = _('Connected to $A at $B (IP: $C)') +language['connected_to_wired'] = _('Connected to wired network (IP: $A)') +language['not_connected'] = _('Not connected') +language['no_wireless_networks_found'] = _('No wireless networks found.') +language['killswitch_enabled'] = _('Wireless Kill Switch Enabled') +language['key'] = _('Key') +language['username'] = _('Username') +language['password'] = _('Password') +language['anonymous_identity'] = _('Anonymous Identity') +language['identity'] = _('Identity') +language['authentication'] = _('Authentication') +language['path_to_pac_file'] = _('Path to PAC File') +language['select_a_network'] = _('Choose from the networks below:') +#language['connecting...'] = _('Connecting...') +language['wired_always_on'] = _('Always show wired interface') +language['auto_reconnect'] = _('Automatically reconnect on connection loss') +language['create_adhoc_network'] = _('Create an Ad-Hoc Network') +language['essid'] = _('ESSID') +language['use_wep_encryption'] = _('Use Encryption (WEP only)') +language['before_script'] = _('Run script before connect') +language['after_script'] = _('Run script after connect') +language['disconnect_script'] = _('Run disconnect script') +language['script_settings'] = _('Scripts') +language['use_ics'] = _('Activate Internet Connection Sharing') +language['madwifi_for_adhoc'] = _('Check if using madwifi/atheros drivers') +language['default_wired'] = _('Use as default profile (overwrites any previous default)') +language['use_debug_mode'] = _('Enable debug mode') +language['use_global_dns'] = _('Use global DNS servers') +language['use_default_profile'] = _('Use default profile on wired autoconnect') +language['show_wired_list'] = _('Prompt for profile on wired autoconnect') +language['use_last_used_profile'] = _('Use last used profile on wired autoconnect') +language['choose_wired_profile'] = _('Select or create a wired profile to connect with') +language['wired_network_found'] = _('Wired connection detected') +language['stop_showing_chooser'] = _('Stop Showing Autoconnect pop-up temporarily') +language['display_type_dialog'] = _('Use dBm to measure signal strength') +language['scripts'] = _('Scripts') +language['invalid_address'] = _('Invalid address in $A entry.') +language['global_settings'] = _('Use these settings for all networks sharing this essid') +language['encrypt_info_missing'] = _('Required encryption information is missing.') +language['enable_encryption'] = _('This network requires encryption to be enabled.') +language['wicd_auto_config'] = _('Automatic (recommended)') +language["gen_settings"] = _('General Settings') +language["ext_programs"] = _('External Programs') +language["dhcp_client"] = _('DHCP Client') +language["wired_detect"] = _('Wired Link Detection') +language["route_flush"] = _('Route Table Flushing') +language["backend"] = _('Backend') +language["backend_alert"] = _('Changes to your backend won\'t occur until the daemon is restarted.') +language['dns_domain'] = _('DNS domain') +language['search_domain'] = _('Search domain') +language['global_dns_not_enabled'] = _('Global DNS has not been enabled in general preferences.') +language['scripts_need_pass'] = _('You must enter your password to configure scripts') +language['no_sudo_prog'] = _('Could not find a graphical sudo program. The script editor could not be launched.' + + ' You\'ll have to edit scripts directly your configuration file.') + +language['interface_down'] = _('Putting interface down...') +language['resetting_ip_address'] = _('Resetting IP address...') +language['interface_up'] = _('Putting interface up...') +language['setting_encryption_info'] = _('Setting encryption info') +language['removing_old_connection'] = _('Removing old connection...') +language['generating_psk'] = _('Generating PSK...') +language['generating_wpa_config'] = _('Generating WPA configuration file...') +language['flushing_routing_table'] = _('Flushing the routing table...') +language['configuring_interface'] = _('Configuring wireless interface...') +language['validating_authentication'] = _('Validating authentication...') +language['setting_broadcast_address'] = _('Setting broadcast address...') +language['setting_static_dns'] = _('Setting static DNS servers...') +language['setting_static_ip'] = _('Setting static IP addresses...') +language['running_dhcp'] = _('Obtaining IP address...') +language['dhcp_failed'] = _('Connection Failed: Unable to Get IP Address') +language['no_dhcp_offers'] = _('Connection Failed: No DHCP offers received.') +language['aborted'] = _('Connection Cancelled') +language['bad_pass'] = _('Connection Failed: Could not authenticate (bad password?)') +language['done'] = _('Done connecting...') +language['scanning'] = _('Scanning') +language['scanning_stand_by'] = _('Scanning networks... stand by...') +language['cannot_start_daemon'] = _('Unable to connect to wicd daemon DBus interface. " + \ + "This typically means there was a problem starting the daemon. " + \ + "Check the wicd log for more info') +language['lost_dbus'] = _('The wicd daemon has shut down, the UI will not function properly until it is restarted.') +language['configuring_wireless'] = _('Configuring preferences for wireless network "$A" ($B)') +language['configuring_wired'] = _('Configuring preferences for wired profile "$A"') +language['scan'] = _('Scan') +language['always_switch_to_wired'] = _('Always switch to wired connection when available') +language['wired_autoconnect_settings'] = _('Wired Autoconnect Settings') +language['always_use_wext'] = _('You should almost always use wext as the WPA supplicant driver') +language['debugging'] = _('Debugging') +language['wpa_supplicant'] = _('WPA Supplicant') +language['automatic_reconnection'] = _('Automatic Reconnection') +language['global_dns_servers'] = _('Global DNS servers') +language['network_interfaces'] = _('Network Interfaces') +language['connecting_to_daemon'] = _('Connecting to daemon...') +language['cannot_connect_to_daemon'] = _('Can\'t connect to the daemon, trying to start it automatically...') +language['could_not_connect'] = _('Could not connect to wicd\'s D-Bus interface. Check the wicd log for error messages.') +language["exception"] = _('EXCEPTION! Please report this to the maintainer and file a bug report with the backtrace below:') +language["brought_to_you"] = _('Brought to you by:') +language["add_new_profile"] = _('Add a new profile') +language["add_new_wired_profile"] = _('Add a new wired profile') +language["no_delete_last_profile"] = _('wicd-curses does not support deleting the last wired profile. Try renaming it (\'F2\')') +language["rename_wired_profile"] = _('Rename wired profile') +language["select_hidden_essid"] = _('Select Hidden Network ESSID') +language["esc_to_cancel"] = _('Press ESC to cancel') +language["press_to_quit"] = _('Press F8 or Q to quit.') + +language['terminated'] = _('Terminated by user') +language['wicd_curses'] = _('Wicd Curses Interface') +language['dbus_fail'] = _('DBus failure! This is most likely caused by the wicd daemon stopping while wicd-curses is running. Please restart the daemon, and then restart wicd-curses.') + +# These are in the tray list, but not in the non-tray list +language['connecting'] = _('Connecting') +language['daemon_unavailable'] = _('The wicd daemon is unavailable, so your request cannot be completed') +language['no_daemon_tooltip'] = _('Wicd daemon unreachable') + +# Translations added on Wed Mar 4 03:36:24 UTC 2009 +language['make_wired_profile'] = _('To connect to a wired network, you must create a network profile. To create a network profile, type a name that describes this network, and press Add.') +language['access_cards'] = _('Wicd needs to access your computer\'s network cards.') +#language['CHANGE_ME'] = _('Create Ad-Hoc network') +#language['CHANGE_ME'] = _('Wired Autoconnect Setting:') +language['bad_pass'] = _('Connection Failed: Bad password') +language['cannot_edit_scripts_1'] = _('To avoid various complications, wicd-curses does not support directly editing the scripts directly. However, you can edit them manually. First, (as root)", open the "$A" config file, and look for the section labeled by the $B in question. In this case, this is:') +language['cannot_edit_scripts_2'] = _('Once there, you can adjust (or add) the "beforescript", "afterscript", and "disconnectscript" variables as needed, to change the preconnect, postconnect, and disconnect scripts respectively. Note that you will be specifying the full path to the scripts - not the actual script contents. You will need to add/edit the script contents separately. Refer to the wicd manual page for more information.') +language['cannot_edit_scripts_3'] = _('You can also configure the wireless networks by looking for the "[]" field in the config file.') +language['wired_networks'] = _('Wired Networks') +language['wireless_networks'] = _('Wireless Networks') +language['about'] = _('About Wicd') +language['more_help'] = _('For more detailed help, consult the wicd-curses(8) man page.') +language['case_sensitive'] = _('All controls are case sensitive') +language['help_help'] = _('Display this help dialog') +language['connect_help'] = _('Connect to selected network') +language['disconn_help'] = _('Disconnect from all networks') +language['about_help'] = _('Stop a network connection in progress') +language['refresh_help'] = _('Refresh network list') +language['prefs_help'] = _('Preferences dialog') +language['scan_help'] = _('Scan for hidden networks') +language['scripts_help'] = _('Select scripts') +language['adhoc_help'] = _('Set up Ad-hoc network') +language['config_help'] = _('Configure Selected Network') +#language[''] = _('Press H or ? for help') # Defunct in curses-uimod +language['raw_screen_arg'] = _('use urwid\'s raw screen controller') +language['ok'] = _('OK') +language['cancel'] = _('Cancel') + + diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index e69c5fd..f82dd08 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -53,6 +53,8 @@ from wicd import gui from wicd import dbusmanager from wicd.guiutil import error +from wicd.translations import language + ICON_AVAIL = True USE_EGG = False # Import egg.trayicon if we're using an older gtk version @@ -72,9 +74,6 @@ if __name__ == '__main__': daemon = wireless = wired = lost_dbus_id = None DBUS_AVAIL = False -language = misc.get_language_list_tray() - - def catchdbus(func): def wrapper(*args, **kwargs): try: @@ -179,7 +178,7 @@ class TrayIcon(object): def set_connecting_state(self, info): """ Sets the icon info for a connecting state. """ if info[0] == 'wired' and len(info) == 1: - cur_network = language['wired'] + cur_network = language['wired_network'] else: cur_network = info[1] self.tr.set_tooltip(language['connecting'] + " to " +