def wifiConnect(interface): dialog = xbmcgui.Dialog() progress = xbmcgui.DialogProgress() progress.create('Scanning','Scanning for wlan on %s'%interface) #progress.update(0) #should hide progress bar, don't work networklist = xbianConfig('network','scan',interface) networks = [] for network in networklist : tmp = network.split(',') tmp[SSID] = tmp[SSID].replace('"','') networks.append(tmp) canceled = False while not canceled : if progress.iscanceled(): canceled = True else : progress.close() displaylist = [] for network in networks : name = '%s [COLOR blue](%s)[/COLOR]'%(network[SSID],network[SECURITYTYPE]) displaylist.append(name) selectedNetwork = dialog.select('Select Network',displaylist) if selectedNetwork == -1 : canceled = True else : if networks[selectedNetwork][SECURITY] == 'on' : key = getText('%s : Security Key'%networks[selectedNetwork][SSID]) if not key : continue else : key = "" progress.create('Scanning','Connecting %s to %s'%(interface,networks[selectedNetwork][SSID])) rc = xbianConfig('network','credentials',interface,networks[selectedNetwork][SECURITYTYPE],networks[selectedNetwork][SSID],key) if rc and rc[0] == '1' : rc = xbianConfig('network','restart',interface) rc = '2' while rc == '2' : rc = xbianConfig('network','progress',interface)[0] time.sleep(0.5) if rc == '1' : progress.close() return True else : progress.close() dialog.ok("Wireless",'%s : cannot connect to %s (%s)'%(interface,networks[selectedNetwork][SSID],rc)) return False
def wifiConnect(interface): dialog = xbmcgui.Dialog() progress = dialogWait('Scanning','Scanning for wlan on %s'%interface) progress.show() networklist = xbianConfig('network','scan',interface) networks = [] for network in networklist : tmp = network.split(',') tmp[SSID] = tmp[SSID].replace('"','') networks.append(tmp) progress.close() canceled = False while not canceled : displaylist = [] for network in networks : signalI = int(network[SIGNAL]) if 0 <= signalI < 20 : signal = '[[COLOR red]*[/COLOR]****]' elif 20 <= signalI < 40 : signal = '[[COLOR orange]**[/COLOR]***]' elif 40 <= signalI < 60 : signal = '[[COLOR orange]***[/COLOR]**]' elif 60 <= signalI < 80 : signal = '[[COLOR green]****[/COLOR]*]' else : signal = '[[COLOR green]*****[/COLOR]]' name = '%s %s'%(signal,network[SSID]) displaylist.append(name) selectedNetwork = dialog.select('Select Network',displaylist) if selectedNetwork == -1 : canceled = True else : if networks[selectedNetwork][SECURITY] == 'on' : key = getText('%s : Security Key'%networks[selectedNetwork][SSID]) if not key : continue else : key = "" progress = dialogWait('Connecting','Connecting %s to %s'%(interface,networks[selectedNetwork][SSID])) progress.show() retry = 2 current_try = 1 connected = False while not connected and current_try <= retry : rc = xbianConfig('network','credentials',interface,networks[selectedNetwork][SECURITYTYPE],networks[selectedNetwork][SSID],key) if rc and rc[0] == '1' : restart = xbianConfig('network','restart',interface) if restart and restart[0] == '1' : rc = '2' while rc == '2' or rc == '-12' : tmp = xbianConfig('network','progress',interface) if tmp : rc = tmp[0] time.sleep(1) if rc == '1' : progress.close() return True else : current_try += 1 else : progress.close() dialog.ok("Wireless Error",'Cannot restart %s'%interface) return False else : progress.close() dialog.ok("Wireless",'%s : cannot connect to %s (%s)'%(interface,networks[selectedNetwork][SSID],rc)) return False progress.close() dialog.ok("Wireless",'%s : cannot connect to %s (%s)'%(interface,networks[selectedNetwork][SSID],rc)) return False
#!/usr/bin/env python from xbianconfig import xbianConfig import os, sys version = sys.argv[1] lockfile = "/var/lock/XBianUpdating" resultFile = "/tmp/resultCode" # create the update status file open(lockfile, "w").close() rc = xbianConfig("updates", "update", version) update = open(resultFile, "w") update.writelines(rc) update.close() os.remove(lockfile)
def wifiConnect(interface): dialog = xbmcgui.Dialog() progress = dialogWait(_('xbian-config.network.label.scan'),_('xbian-config.network.scanning')) progress.show() networklist = xbianConfig('network','scan',interface) networks = [] for network in networklist : tmp = network.split(',') tmp[SSID] = tmp[SSID].replace('"','') networks.append(tmp) progress.close() canceled = False while not canceled : displaylist = [] for network in networks : signalI = int(network[SIGNAL]) if 0 <= signalI < 20 : signal = '[[COLOR red]*[/COLOR]****]' elif 20 <= signalI < 40 : signal = '[[COLOR orange]**[/COLOR]***]' elif 40 <= signalI < 60 : signal = '[[COLOR orange]***[/COLOR]**]' elif 60 <= signalI < 80 : signal = '[[COLOR green]****[/COLOR]*]' else : signal = '[[COLOR green]*****[/COLOR]]' name = '%s %s'%(signal,network[SSID]) displaylist.append(name) selectedNetwork = dialog.select(_('xbian-config.network.label.ssid'),displaylist) if selectedNetwork == -1 : canceled = True else : if networks[selectedNetwork][SECURITY] == 'on' : key = getText('%s : %s'%(_(xbian-config.network.credentials.enter),networks[selectedNetwork][SSID])) if not key : continue else : key = "" progress = dialogWait(interface,_('xbian-config.network.connection.updating'%(networks[selectedNetwork][SSID]))) progress.show() retry = 2 current_try = 1 connected = False while not connected and current_try <= retry : rc = xbianConfig('network','credentials',interface,networks[selectedNetwork][SECURITYTYPE],base64.b64encode(networks[selectedNetwork][SSID]),base64.b64encode(key)) if rc and rc[0] == '1' : restart = xbianConfig('network','restart',interface) if restart and restart[0] == '1' : rc = '2' while rc == '2' or rc == '-12' : tmp = xbianConfig('network','progress',interface) if tmp : rc = tmp[0] time.sleep(1) if rc == '1' : progress.close() return True else : current_try += 1 else : progress.close() #dialog.ok("Wireless Error",'Cannot restart %s'%interface) return False else : progress.close() dialog.ok(interface,_('xbian-config.network.connection.failed'%(networks[selectedNetwork][SSID],rc))) return False return False
def wifiConnect(interface): dialog = xbmcgui.Dialog() progress = dialogWait(_('Scan'), _('Scanning for available networks...')) progress.show() networklist = xbianConfig('network', 'scan', interface) networks = [] for network in networklist: tmp = network.split(',') tmp[SSID] = tmp[SSID].replace('"', '') networks.append(tmp) progress.close() canceled = False while not canceled: displaylist = [] for network in networks: signalI = int(network[SIGNAL]) if 0 <= signalI < 20: signal = '[[COLOR red]*[/COLOR]****]' elif 20 <= signalI < 40: signal = '[[COLOR orange]**[/COLOR]***]' elif 40 <= signalI < 60: signal = '[[COLOR orange]***[/COLOR]**]' elif 60 <= signalI < 80: signal = '[[COLOR green]****[/COLOR]*]' else: signal = '[[COLOR green]*****[/COLOR]]' name = '%s %s' % (signal, network[SSID]) displaylist.append(name) selectedNetwork = dialog.select(_('SSID'), displaylist) if selectedNetwork == -1: canceled = True else: if networks[selectedNetwork][SECURITY] == 'on': rc = xbianConfig('network', 'credentials', interface, networks[selectedNetwork][SECURITYTYPE], base64.b64encode(networks[selectedNetwork][SSID])) if rc: key = base64.b64decode(rc[0])[:-1] else: key = '' key = getText('%s: %s (%s)' % (_('Enter credentials for selected interface'), networks[selectedNetwork][SSID], networks[selectedNetwork][SECURITYTYPE]), key) if not key: continue else: key = "" progress = dialogWait( interface, _('Please wait. Trying to connect to %s') % ( networks[selectedNetwork][SSID], )) progress.show() retry = 2 current_try = 1 connected = False while not connected and current_try <= retry: rc = xbianConfig('network', 'credentials', interface, networks[selectedNetwork][ SECURITYTYPE], base64.b64encode(networks[selectedNetwork][SSID]), base64.b64encode(key)) if rc and rc[0] == '1': restart = xbianConfig('network', 'restart', interface) if restart and restart[0] == '1': rc = '2' lc = 0 while (rc == '2' or rc == '-12') and lc < 60: tmp = xbianConfig('network', 'progress', interface) if tmp: rc = tmp[0] time.sleep(1) lc += 1 if rc == '1': progress.close() return True else: current_try += 1 else: progress.close() # dialog.ok("Wireless Error",'Cannot restart %s'%interface) return False else: progress.close() dialog.ok(interface, _('Failed to connect to %s') % ( networks[selectedNetwork][SSID], rc, )) return False return False
def wifiConnect(interface): dialog = xbmcgui.Dialog() progress = dialogWait('Scanning', 'Scanning for wlan on %s' % interface) progress.show() networklist = xbianConfig('network', 'scan', interface) networks = [] for network in networklist: tmp = network.split(',') tmp[SSID] = tmp[SSID].replace('"', '') networks.append(tmp) progress.close() canceled = False while not canceled: displaylist = [] for network in networks: signalI = int(network[SIGNAL]) if 0 <= signalI < 20: signal = '[[COLOR red]*[/COLOR]****]' elif 20 <= signalI < 40: signal = '[[COLOR orange]**[/COLOR]***]' elif 40 <= signalI < 60: signal = '[[COLOR orange]***[/COLOR]**]' elif 60 <= signalI < 80: signal = '[[COLOR green]****[/COLOR]*]' else: signal = '[[COLOR green]*****[/COLOR]]' name = '%s %s' % (signal, network[SSID]) displaylist.append(name) selectedNetwork = dialog.select('Select Network', displaylist) if selectedNetwork == -1: canceled = True else: if networks[selectedNetwork][SECURITY] == 'on': key = getText('%s : Security Key' % networks[selectedNetwork][SSID]) if not key: continue else: key = "" progress = dialogWait( 'Connecting', 'Connecting %s to %s' % (interface, networks[selectedNetwork][SSID])) progress.show() retry = 2 current_try = 1 connected = False while not connected and current_try <= retry: rc = xbianConfig('network', 'credentials', interface, networks[selectedNetwork][SECURITYTYPE], networks[selectedNetwork][SSID], key) if rc and rc[0] == '1': restart = xbianConfig('network', 'restart', interface) if restart and restart[0] == '1': rc = '2' while rc == '2' or rc == '-12': tmp = xbianConfig('network', 'progress', interface) if tmp: rc = tmp[0] time.sleep(1) if rc == '1': progress.close() return True else: current_try += 1 else: progress.close() dialog.ok("Wireless Error", 'Cannot restart %s' % interface) return False else: progress.close() dialog.ok( "Wireless", '%s : cannot connect to %s (%s)' % (interface, networks[selectedNetwork][SSID], rc)) return False progress.close() dialog.ok( "Wireless", '%s : cannot connect to %s (%s)' % (interface, networks[selectedNetwork][SSID], rc)) return False