mirror of
https://github.com/gryf/wicd.git
synced 2026-02-13 12:25:56 +01:00
Merged with r342 of mainline 1.6.
This commit is contained in:
18
wicd/misc.py
18
wicd/misc.py
@@ -73,7 +73,6 @@ class WicdError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
__LANG = None
|
|
||||||
def Run(cmd, include_stderr=False, return_pipe=False,
|
def Run(cmd, include_stderr=False, return_pipe=False,
|
||||||
return_obj=False, return_retcode=True):
|
return_obj=False, return_retcode=True):
|
||||||
""" Run a command.
|
""" Run a command.
|
||||||
@@ -93,7 +92,6 @@ def Run(cmd, include_stderr=False, return_pipe=False,
|
|||||||
for the command that was run.
|
for the command that was run.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
global __LANG
|
|
||||||
if not isinstance(cmd, list):
|
if not isinstance(cmd, list):
|
||||||
cmd = to_unicode(str(cmd))
|
cmd = to_unicode(str(cmd))
|
||||||
cmd = cmd.split()
|
cmd = cmd.split()
|
||||||
@@ -110,11 +108,9 @@ def Run(cmd, include_stderr=False, return_pipe=False,
|
|||||||
|
|
||||||
# We need to make sure that the results of the command we run
|
# We need to make sure that the results of the command we run
|
||||||
# are in English, so we set up a temporary environment.
|
# are in English, so we set up a temporary environment.
|
||||||
if not __LANG:
|
|
||||||
__LANG = get_good_lang()
|
|
||||||
tmpenv = os.environ.copy()
|
tmpenv = os.environ.copy()
|
||||||
tmpenv["LC_ALL"] = __LANG
|
tmpenv["LC_ALL"] = "C"
|
||||||
tmpenv["LANG"] = __LANG
|
tmpenv["LANG"] = "C"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = Popen(cmd, shell=False, stdout=PIPE, stdin=std_in, stderr=err,
|
f = Popen(cmd, shell=False, stdout=PIPE, stdin=std_in, stderr=err,
|
||||||
@@ -123,7 +119,6 @@ def Run(cmd, include_stderr=False, return_pipe=False,
|
|||||||
print "Running command %s failed: %s" % (str(cmd), str(e))
|
print "Running command %s failed: %s" % (str(cmd), str(e))
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
if return_obj:
|
if return_obj:
|
||||||
return f
|
return f
|
||||||
if return_pipe:
|
if return_pipe:
|
||||||
@@ -131,14 +126,6 @@ def Run(cmd, include_stderr=False, return_pipe=False,
|
|||||||
else:
|
else:
|
||||||
return f.communicate()[0]
|
return f.communicate()[0]
|
||||||
|
|
||||||
def get_good_lang():
|
|
||||||
""" Check if en_US.utf8 is an available locale, if not use C. """
|
|
||||||
output = Popen(["locale", "-a"], shell=False, stdout=PIPE).communicate()[0]
|
|
||||||
if "en_US.utf8" in output:
|
|
||||||
return "en_US.utf8"
|
|
||||||
else:
|
|
||||||
return "C"
|
|
||||||
|
|
||||||
def LaunchAndWait(cmd):
|
def LaunchAndWait(cmd):
|
||||||
""" Launches the given program with the given arguments, then blocks.
|
""" Launches the given program with the given arguments, then blocks.
|
||||||
|
|
||||||
@@ -553,4 +540,3 @@ def grouper(n, iterable, fillvalue=None):
|
|||||||
"""
|
"""
|
||||||
args = [iter(iterable)] * n
|
args = [iter(iterable)] * n
|
||||||
return izip_longest(fillvalue=fillvalue, *args)
|
return izip_longest(fillvalue=fillvalue, *args)
|
||||||
|
|
||||||
|
|||||||
@@ -1170,18 +1170,17 @@ class WirelessDaemon(dbus.service.Object):
|
|||||||
|
|
||||||
cur_network["has_profile"] = True
|
cur_network["has_profile"] = True
|
||||||
|
|
||||||
# Read the essid because we need to name those hidden
|
|
||||||
# wireless networks now - but only read it if it is hidden.
|
|
||||||
if cur_network["hidden"]:
|
|
||||||
cur_network["essid"] = self.config.get(section, "essid")
|
|
||||||
if cur_network["essid"] in ["", "Hidden", "<hidden>"]:
|
|
||||||
cur_network["essid"] = "<hidden>"
|
|
||||||
for x in self.config.options(section):
|
for x in self.config.options(section):
|
||||||
if not cur_network.has_key(x) or x.endswith("script"):
|
if not cur_network.has_key(x) or x.endswith("script"):
|
||||||
cur_network[x] = misc.Noneify(self.config.get(section, x))
|
cur_network[x] = misc.Noneify(self.config.get(section, x))
|
||||||
for option in ['use_static_dns', 'use_global_dns', 'encryption',
|
for option in ['use_static_dns', 'use_global_dns', 'encryption',
|
||||||
'use_settings_globally']:
|
'use_settings_globally']:
|
||||||
cur_network[option] = bool(cur_network.get(option))
|
cur_network[option] = bool(cur_network.get(option))
|
||||||
|
# Read the essid because we need to name those hidden
|
||||||
|
# wireless networks now - but only read it if it is hidden.
|
||||||
|
if cur_network["hidden"]:
|
||||||
|
if cur_network.get("essid") in ["", "Hidden", "<hidden>", None]:
|
||||||
|
cur_network["essid"] = "<hidden>"
|
||||||
return "100: Loaded Profile"
|
return "100: Loaded Profile"
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.wireless')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
|
|||||||
@@ -1094,7 +1094,8 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
except (UnicodeDecodeError, UnicodeEncodeError):
|
except (UnicodeDecodeError, UnicodeEncodeError):
|
||||||
print 'Unicode problem with current network essid, ignoring!!'
|
print 'Unicode problem with current network essid, ignoring!!'
|
||||||
return None
|
return None
|
||||||
if ap['essid'] in ['<hidden>', ""]:
|
if ap['essid'] in ['<hidden>', "", None]:
|
||||||
|
print 'hidden'
|
||||||
ap['hidden'] = True
|
ap['hidden'] = True
|
||||||
ap['essid'] = "<hidden>"
|
ap['essid'] = "<hidden>"
|
||||||
else:
|
else:
|
||||||
@@ -1176,6 +1177,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
MAX_TIME = 35
|
MAX_TIME = 35
|
||||||
MAX_DISCONNECTED_TIME = 3
|
MAX_DISCONNECTED_TIME = 3
|
||||||
disconnected_time = 0
|
disconnected_time = 0
|
||||||
|
forced_rescan = False
|
||||||
while (time.time() - auth_time) < MAX_TIME:
|
while (time.time() - auth_time) < MAX_TIME:
|
||||||
cmd = '%s -i %s status' % (self.wpa_cli_cmd, self.iface)
|
cmd = '%s -i %s status' % (self.wpa_cli_cmd, self.iface)
|
||||||
output = misc.Run(cmd)
|
output = misc.Run(cmd)
|
||||||
@@ -1187,11 +1189,12 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
return False
|
return False
|
||||||
if result == "COMPLETED":
|
if result == "COMPLETED":
|
||||||
return True
|
return True
|
||||||
elif result == "DISCONNECTED":
|
elif result == "DISCONNECTED" and not forced_rescan:
|
||||||
disconnected_time += 1
|
disconnected_time += 1
|
||||||
if disconnected_time > MAX_DISCONNECTED_TIME:
|
if disconnected_time > MAX_DISCONNECTED_TIME:
|
||||||
disconnected_time = 0
|
disconnected_time = 0
|
||||||
# Force a rescan to get wpa_supplicant moving again.
|
# Force a rescan to get wpa_supplicant moving again.
|
||||||
|
forced_rescan = True
|
||||||
self._ForceSupplicantScan()
|
self._ForceSupplicantScan()
|
||||||
MAX_TIME += 5
|
MAX_TIME += 5
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user