1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-20 04:48:00 +01:00

Centralise path configuration into a single file.

Path configuration was distributed throughout wicd, making it difficult
to move around project files. Centralise the configuration into
wpath.py.
This commit is contained in:
metrics
2007-08-12 00:30:01 +00:00
parent 4e4e87423d
commit ca8810aa4a
8 changed files with 76 additions and 31 deletions

View File

@@ -6,9 +6,11 @@
############ ############
#change to the directory that the file lives in #change to the directory that the file lives in
import os,sys import os
import sys
import wpath
if __name__ == '__main__': 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 the dbus stuff
import gobject import gobject
import dbus import dbus
@@ -58,7 +60,7 @@ logging_enabled = True
class FlushWriter: class FlushWriter:
def __init__(self): def __init__(self):
print os.getcwd() print os.getcwd()
self.file = open('data/wicd.log','w') self.file = open(wpath.log + 'wicd.log','w')
self.file.write(self.__getPrettyTime() + ' :: ') self.file.write(self.__getPrettyTime() + ' :: ')
def write(self,data): def write(self,data):
@@ -104,9 +106,9 @@ class ConnectionWizard(dbus.service.Object):
dbus.service.Object.__init__(self, bus_name, object_path) dbus.service.Object.__init__(self, bus_name, object_path)
#set variables needed to run - these probably won't be changed too often #set variables needed to run - these probably won't be changed too often
self.app_conf = "data/manager-settings.conf" self.app_conf = wpath.etc + 'manager-settings.conf'
self.wireless_conf = "data/wireless-settings.conf" self.wireless_conf = wpath.etc + 'wireless-settings.conf'
self.wired_conf = "data/wired-settings.conf" self.wired_conf = wpath.etc + 'wired-settings.conf'
self.hidden_essid = None self.hidden_essid = None
self.wifi = networking.Wireless() self.wifi = networking.Wireless()
self.wired = networking.Wired() self.wired = networking.Wired()

View File

@@ -3,9 +3,11 @@
## USE TRAY.PY INSTEAD ## USE TRAY.PY INSTEAD
## nothing bad will happen if you do ## nothing bad will happen if you do
## but that is not the preferred method ## but that is not the preferred method
import os,sys import os
import sys
import wpath
if __name__ == '__main__': 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 gtk,locale,gettext,signal
import egg.trayicon import egg.trayicon
import gobject, dbus, dbus.service import gobject, dbus, dbus.service

View File

@@ -14,9 +14,11 @@
##this will only work in Edgy and above because of gtk requirements ##this will only work in Edgy and above because of gtk requirements
##to run the tray icon ##to run the tray icon
######## ########
import os,sys import os
import sys
import wpath
if __name__ == '__main__': 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 import gtk, gobject, dbus, dbus.service, os, sys, locale, gettext, signal, time
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0): if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib import dbus.glib

22
gui.py
View File

@@ -1,7 +1,9 @@
#!/usr/bin/python #!/usr/bin/python
import os,sys import os
import sys
import wpath
if __name__ == '__main__': if __name__ == '__main__':
os.chdir(os.path.dirname(os.path.normpath(os.path.join(os.getcwd(),sys.argv[0])))) wpath.chdir(__file__)
try: try:
import pygtk import pygtk
pygtk.require("2.0") pygtk.require("2.0")
@@ -337,22 +339,22 @@ class PrettyWirelessNetworkEntry(PrettyNetworkEntry):
strength = int(strength) strength = int(strength)
if daemon.GetWPADriver() == 'ralink legacy': if daemon.GetWPADriver() == 'ralink legacy':
if strength <= 60: 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: 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: elif strength <= 80:
self.image.set_from_file("images/signal-50.png") self.image.set_from_file(wpath.images + 'signal-50.png')
else: else:
self.image.set_from_file("images/signal-25.png") self.image.set_from_file(wpath.images + 'signal-25.png')
else: else:
if strength > 75: 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: 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: elif strength > 25:
self.image.set_from_file("images/signal-50.png") self.image.set_from_file(wpath.images + 'signal-50.png')
else: else:
self.image.set_from_file("images/signal-25.png") self.image.set_from_file(wpath.images + 'signal-25.png')
self.expander.setSignalStrength(strength) self.expander.setSignalStrength(strength)
def setMACAddress(self,address): def setMACAddress(self,address):

12
misc.py
View File

@@ -10,9 +10,11 @@
# Copyright (C) 2007 Adam Blackburn # Copyright (C) 2007 Adam Blackburn
# #
import os,sys import os
import sys
import wpath
if __name__ == '__main__': if __name__ == '__main__':
os.chdir(os.path.dirname(os.path.normpath(os.path.join(os.getcwd(),sys.argv[0])))) wpath.chdir(__file__)
import re import re
def Run(cmd,include_std_error=False): def Run(cmd,include_std_error=False):
if not include_std_error: if not include_std_error:
@@ -91,9 +93,9 @@ def ParseEncryption(network):
y+=1 y+=1
#write the data to the files #write the data to the files
#then chmod them so they can't be read by evil little munchkins #then chmod them so they can't be read by evil little munchkins
fileness = open("encryption/configurations/" + network["bssid"].replace(":","").lower(),"w") fileness = open(wpath.networks + network["bssid"].replace(":","").lower(),"w")
os.chmod("encryption/configurations/" + network["bssid"].replace(":","").lower(),0600) os.chmod(wpath.networks + network["bssid"].replace(":","").lower(),0600)
os.chown("encryption/configurations/" + network["bssid"].replace(":","").lower(), 0, 0) 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 #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.write(z)
fileness.close() fileness.close()

View File

@@ -6,9 +6,11 @@
## MUST BE IMPORTED VIA import networking ## MUST BE IMPORTED VIA import networking
## TO ANOTHER PROJECT IF YOU WISH TO USE IT ## TO ANOTHER PROJECT IF YOU WISH TO USE IT
import os,sys import os
import sys
import wpath
if __name__ == '__main__': 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 #import the library of random functions that we need here
#this is also written by me, for this purpose #this is also written by me, for this purpose
@@ -351,8 +353,8 @@ class Wireless:
print "generating wpa_supplicant configuration file..." print "generating wpa_supplicant configuration file..."
misc.ParseEncryption(network) misc.ParseEncryption(network)
print "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 \"encryption/configurations/" + 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..." print "flushing the routing table..."
self.lock.acquire() self.lock.acquire()

View File

@@ -1,7 +1,9 @@
#!/usr/bin/python #!/usr/bin/python
import os,sys import os
import sys
import wpath
if __name__ == '__main__': if __name__ == '__main__':
os.chdir(os.path.dirname(os.path.normpath(os.path.join(os.getcwd(),sys.argv[0])))) wpath.chdir(__file__)
import gtk import gtk
if gtk.gtk_version[0] >= 2 and gtk.gtk_version[1] >= 10: if gtk.gtk_version[0] >= 2 and gtk.gtk_version[1] >= 10:
import edgy import edgy

31
wpath.py Normal file
View File

@@ -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)))