mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 12:58:07 +01:00
Fix issue where signal strength wouldn't be reported correctly if the first link quality regex didn't match.
Add some helper methods that will eventually be used for encryption template parsing. Use more specific exception checking in a few places.
This commit is contained in:
38
wicd/misc.py
38
wicd/misc.py
@@ -26,6 +26,7 @@ import gobject
|
||||
from threading import Thread
|
||||
from subprocess import Popen, STDOUT, PIPE, call
|
||||
from commands import getoutput
|
||||
from itertools import repeat, chain, izip
|
||||
|
||||
# wicd imports
|
||||
import wpath
|
||||
@@ -243,9 +244,11 @@ def ParseEncryption(network):
|
||||
|
||||
# Write the data to the files then chmod them so they can't be read
|
||||
# by normal users.
|
||||
f = 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)
|
||||
file_loc = os.path.join(wpath.networks,
|
||||
network['bssid'].replace(":", "").lower())
|
||||
f = open(file_loc, "w")
|
||||
os.chmod(file_loc, 0600)
|
||||
os.chown(file_loc, 0, 0)
|
||||
# We could do this above, but we'd like to read protect
|
||||
# them before we write, so that it can't be read.
|
||||
f.write(config_file)
|
||||
@@ -690,4 +693,31 @@ def timeout_add(time, func, milli=False):
|
||||
else:
|
||||
if not milli: time = time * 1000
|
||||
return gobject.timeout_add(time, func)
|
||||
|
||||
|
||||
def izip_longest(*args, **kwds):
|
||||
""" Implement the itertools.izip_longest method.
|
||||
|
||||
We implement the method here because its new in Python 2.6.
|
||||
|
||||
"""
|
||||
# izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
|
||||
fillvalue = kwds.get('fillvalue')
|
||||
def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
|
||||
yield counter() # yields the fillvalue, or raises IndexError
|
||||
fillers = repeat(fillvalue)
|
||||
iters = [chain(it, sentinel(), fillers) for it in args]
|
||||
try:
|
||||
for tup in izip(*iters):
|
||||
yield tup
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
def grouper(n, iterable, fillvalue=None):
|
||||
""" Iterate over several elements at once
|
||||
|
||||
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
|
||||
|
||||
"""
|
||||
args = [iter(iterable)] * n
|
||||
return izip_longest(fillvalue=fillvalue, *args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user