GeoView : Replacing ping command by a socket connexion to test the network.
svn: r14406
This commit is contained in:
parent
b29f2504db
commit
f68b3b5164
@ -43,6 +43,7 @@ import const
|
|||||||
import operator
|
import operator
|
||||||
import locale
|
import locale
|
||||||
from gtk.keysyms import Tab as KEY_TAB
|
from gtk.keysyms import Tab as KEY_TAB
|
||||||
|
import socket
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -814,7 +815,7 @@ class GeoView(HtmlView):
|
|||||||
self._goto_active_person()
|
self._goto_active_person()
|
||||||
self.filter.hide() # hide the filter
|
self.filter.hide() # hide the filter
|
||||||
self.active = True
|
self.active = True
|
||||||
self._test_network('maps.google.com')
|
self._test_network()
|
||||||
|
|
||||||
def set_inactive(self):
|
def set_inactive(self):
|
||||||
"""
|
"""
|
||||||
@ -2285,34 +2286,26 @@ class GeoView(HtmlView):
|
|||||||
URL_SEP.join(filename.split(os.sep)),
|
URL_SEP.join(filename.split(os.sep)),
|
||||||
'', ''))
|
'', ''))
|
||||||
|
|
||||||
def _test_network(self, host):
|
def _test_network(self):
|
||||||
"""
|
"""
|
||||||
This function is used to test if we are connected to a network.
|
This function is used to test if we are connected to a network.
|
||||||
"""
|
"""
|
||||||
if constfunc.win():
|
try:
|
||||||
command = "ping -n 2 "
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
stringtosearch = "([0-9]*)%.*"
|
sock.connect(('216.239.59.106', 80)) # google
|
||||||
#elif constfunc.mac():
|
if sock != None:
|
||||||
# command = "ping -c 2 "
|
if self.no_network == True:
|
||||||
else:
|
self.no_network = False
|
||||||
stringtosearch = ".*, (.*)% packet loss.*"
|
self._change_map(self.usedmap)
|
||||||
command = "ping -c 2 "
|
sock.close()
|
||||||
|
else:
|
||||||
pinghost = os.popen(command + host, "r")
|
self.no_network = True
|
||||||
line = pinghost.read()
|
except:
|
||||||
if not line:
|
|
||||||
self.no_network = True
|
|
||||||
result = re.search(stringtosearch, line)
|
|
||||||
if result != None and int(result.group(1)) == 0:
|
|
||||||
if self.no_network == True:
|
|
||||||
self.no_network = False
|
|
||||||
self._change_map(self.usedmap)
|
|
||||||
else:
|
|
||||||
self.no_network = True
|
self.no_network = True
|
||||||
|
|
||||||
if self.active:
|
if self.active:
|
||||||
gobject.timeout_add(30000, # Every 30 seconds
|
gobject.timeout_add(10000, # Every 10 seconds
|
||||||
self._test_network, host)
|
self._test_network)
|
||||||
if self.no_network:
|
if self.no_network:
|
||||||
self.open(self._create_message_page(
|
self.open(self._create_message_page(
|
||||||
'No network connection found.<br>A connection to the'
|
'No network connection found.<br>A connection to the'
|
||||||
|
Loading…
Reference in New Issue
Block a user