diff --git a/daemon.py b/daemon.py index 22e3570..09463c5 100644 --- a/daemon.py +++ b/daemon.py @@ -6,9 +6,11 @@ ############ #change to the directory that the file lives in -import os,sys +import os +import sys +import wpath if __name__ == '__main__': - os.chdir(os.path.dirname(os.path.normpath(os.path.join(os.getcwd(),sys.argv[0])))) + wpath.chdir(__file__) #import the dbus stuff import gobject import dbus @@ -58,7 +60,7 @@ logging_enabled = True class FlushWriter: def __init__(self): print os.getcwd() - self.file = open('data/wicd.log','w') + self.file = open(wpath.log + 'wicd.log','w') self.file.write(self.__getPrettyTime() + ' :: ') def write(self,data): @@ -104,9 +106,9 @@ class ConnectionWizard(dbus.service.Object): dbus.service.Object.__init__(self, bus_name, object_path) #set variables needed to run - these probably won't be changed too often - self.app_conf = "data/manager-settings.conf" - self.wireless_conf = "data/wireless-settings.conf" - self.wired_conf = "data/wired-settings.conf" + self.app_conf = wpath.etc + 'manager-settings.conf' + self.wireless_conf = wpath.etc + 'wireless-settings.conf' + self.wired_conf = wpath.etc + 'wired-settings.conf' self.hidden_essid = None self.wifi = networking.Wireless() self.wired = networking.Wired() diff --git a/dapper.py b/dapper.py index d8e7b25..3c07d78 100644 --- a/dapper.py +++ b/dapper.py @@ -3,9 +3,11 @@ ## USE TRAY.PY INSTEAD ## nothing bad will happen if you do ## but that is not the preferred method -import os,sys +import os +import sys +import wpath if __name__ == '__main__': - os.chdir(os.path.dirname(os.path.normpath(os.path.join(os.getcwd(),sys.argv[0])))) + wpath.chdir(__file__) import gtk,locale,gettext,signal import egg.trayicon import gobject, dbus, dbus.service diff --git a/edgy.py b/edgy.py index c3eff5b..81e4035 100755 --- a/edgy.py +++ b/edgy.py @@ -14,9 +14,11 @@ ##this will only work in Edgy and above because of gtk requirements ##to run the tray icon ######## -import os,sys +import os +import sys +import wpath if __name__ == '__main__': - os.chdir(os.path.dirname(os.path.normpath(os.path.join(os.getcwd(),sys.argv[0])))) + wpath.chdir(__file__) import gtk, gobject, dbus, dbus.service, os, sys, locale, gettext, signal, time if getattr(dbus, 'version', (0,0,0)) >= (0,41,0): import dbus.glib diff --git a/gui.py b/gui.py index 7f709cc..f89f78a 100644 --- a/gui.py +++ b/gui.py @@ -1,7 +1,9 @@ #!/usr/bin/python -import os,sys +import os +import sys +import wpath if __name__ == '__main__': - os.chdir(os.path.dirname(os.path.normpath(os.path.join(os.getcwd(),sys.argv[0])))) + wpath.chdir(__file__) try: import pygtk pygtk.require("2.0") @@ -337,22 +339,22 @@ class PrettyWirelessNetworkEntry(PrettyNetworkEntry): strength = int(strength) if daemon.GetWPADriver() == 'ralink legacy': if strength <= 60: - self.image.set_from_file("images/signal-100.png") + self.image.set_from_file(wpath.images + 'signal-100.png') elif strength <= 70: - self.image.set_from_file("images/signal-75.png") + self.image.set_from_file(wpath.images + 'signal-75.png') elif strength <= 80: - self.image.set_from_file("images/signal-50.png") + self.image.set_from_file(wpath.images + 'signal-50.png') else: - self.image.set_from_file("images/signal-25.png") + self.image.set_from_file(wpath.images + 'signal-25.png') else: if strength > 75: - self.image.set_from_file("images/signal-100.png") + self.image.set_from_file(wpath.images + 'signal-100.png') elif strength > 50: - self.image.set_from_file("images/signal-75.png") + self.image.set_from_file(wpath.images + 'signal-75.png') elif strength > 25: - self.image.set_from_file("images/signal-50.png") + self.image.set_from_file(wpath.images + 'signal-50.png') else: - self.image.set_from_file("images/signal-25.png") + self.image.set_from_file(wpath.images + 'signal-25.png') self.expander.setSignalStrength(strength) def setMACAddress(self,address): diff --git a/misc.py b/misc.py index 2c45416..477784b 100644 --- a/misc.py +++ b/misc.py @@ -10,9 +10,11 @@ # Copyright (C) 2007 Adam Blackburn # -import os,sys +import os +import sys +import wpath if __name__ == '__main__': - os.chdir(os.path.dirname(os.path.normpath(os.path.join(os.getcwd(),sys.argv[0])))) + wpath.chdir(__file__) import re def Run(cmd,include_std_error=False): if not include_std_error: @@ -91,9 +93,9 @@ def ParseEncryption(network): y+=1 #write the data to the files #then chmod them so they can't be read by evil little munchkins - fileness = open("encryption/configurations/" + network["bssid"].replace(":","").lower(),"w") - os.chmod("encryption/configurations/" + network["bssid"].replace(":","").lower(),0600) - os.chown("encryption/configurations/" + network["bssid"].replace(":","").lower(), 0, 0) + fileness = open(wpath.networks + network["bssid"].replace(":","").lower(),"w") + os.chmod(wpath.networks + network["bssid"].replace(":","").lower(),0600) + os.chown(wpath.networks + network["bssid"].replace(":","").lower(), 0, 0) #we could do this above, but we'd like to permod (permission mod) them before we write, so that it can't be read fileness.write(z) fileness.close() diff --git a/networking.py b/networking.py index e554c82..86d9417 100644 --- a/networking.py +++ b/networking.py @@ -6,9 +6,11 @@ ## MUST BE IMPORTED VIA import networking ## TO ANOTHER PROJECT IF YOU WISH TO USE IT -import os,sys +import os +import sys +import wpath if __name__ == '__main__': - os.chdir(os.path.dirname(os.path.normpath(os.path.join(os.getcwd(),sys.argv[0])))) + wpath.chdir(__file__) #import the library of random functions that we need here #this is also written by me, for this purpose @@ -351,8 +353,8 @@ class Wireless: print "generating wpa_supplicant configuration file..." misc.ParseEncryption(network) - print "wpa_supplicant -B -i " + self.wireless_interface + " -c \"encryption/configurations/" + network["bssid"].replace(":","").lower() + "\" -D " + self.wpa_driver - misc.Run("wpa_supplicant -B -i " + self.wireless_interface + " -c \"encryption/configurations/" + network["bssid"].replace(":","").lower() + "\" -D " + self.wpa_driver) + print 'wpa_supplicant -B -i ' + self.wireless_interface + ' -c "' + wpath.networks + network["bssid"].replace(":","").lower() + '" -D ' + self.wpa_driver + misc.Run('wpa_supplicant -B -i ' + self.wireless_interface + ' -c "' + wpath.networks + network["bssid"].replace(":","").lower() + '" -D ' + self.wpa_driver) print "flushing the routing table..." self.lock.acquire() diff --git a/tray.py b/tray.py index e060956..420b548 100644 --- a/tray.py +++ b/tray.py @@ -1,7 +1,9 @@ #!/usr/bin/python -import os,sys +import os +import sys +import wpath if __name__ == '__main__': - os.chdir(os.path.dirname(os.path.normpath(os.path.join(os.getcwd(),sys.argv[0])))) + wpath.chdir(__file__) import gtk if gtk.gtk_version[0] >= 2 and gtk.gtk_version[1] >= 10: import edgy diff --git a/wpath.py b/wpath.py new file mode 100644 index 0000000..25e5b06 --- /dev/null +++ b/wpath.py @@ -0,0 +1,31 @@ +"""Path configuration and functions for the wicd daemon and gui clients. + +chdir() -- Change directory to the location of the current file. + +""" + +import os + +# The path containing the wpath.py file. +current = os.path.dirname(os.path.realpath(__file__)) + '/' + +# These paths can easily be modified to handle system wide installs, or +# they can be left as is if all files remain with the source directory +# layout. +lib = current +images = lib + 'images/' +encryption = lib + 'encryption/templates/' +bin = current +etc = current + 'data/' +networks = lib + 'encryption/configurations/' +log = current + 'data/' + +def chdir(file): + """Change directory to the location of the specified file. + + Keyword arguments: + file -- the file to switch to (usually __file__) + + """ + os.chdir(os.path.dirname(os.path.realpath(file))) +