def get_imsi_cb(imsi): # we will setup the combobox options here items = [] network = net_manager.get_network_by_id(imsi) if not network: # we dont know anything about this network operator, we will # just show 'Unknown' in the combobox, giving no options to # the user items.append(SMSCItem(_("Unknown"))) else: if network.smsc: # we know the network and we have its SMSC if smsc != network.smsc: # as the SMSC is different that the stored one, # we are gonna append "Custom" too items.append(SMSCItem(_("Custom"))) items.append( SMSCItem(network.get_full_name(), network.smsc, active=False)) else: items.append( SMSCItem(network.get_full_name(), network.smsc)) else: # we dont know the SMSC of this network items.append(SMSCItem(_("Unknown"))) self.view.populate_smsc_combobox(items)
def get_imsi_cb(imsi): # we will setup the combobox options here items = [] network = net_manager.get_network_by_id(imsi[:5]) if not network: # we dont know anything about this network operator, we will # just show 'Unknown' in the combobox, giving no options to # the user items.append(SMSCItem(_("Unknown"))) else: if network.smsc: # we know the network and we have its SMSC if smsc != network.smsc: # as the SMSC is different that the stored one, # we are gonna append "Custom" too items.append(SMSCItem(_("Custom"))) items.append(SMSCItem(network.get_full_name(), network.smsc, active=False)) else: items.append(SMSCItem(network.get_full_name(), network.smsc)) else: # we dont know the SMSC of this network items.append(SMSCItem(_("Unknown"))) self.view.populate_smsc_combobox(items)
def get_net_info_cb(netinfo): """ Returns a (Networname, ConnType) tuple It returns None if there's no info """ if not netinfo: return None netinfo = netinfo[0] if netinfo.group('error'): # this means that we've received a response like # +COPS: 0 which means that we don't have network temporaly # we should raise an exception here raise ex.NetworkTemporalyUnavailableError try: status = int(netinfo.group('status')) conn_type = (status == 0) and 'GPRS' or '3G' except IndexError: conn_type = 'GPRS' netname = netinfo.group('netname') if netname in ['Limited Service', pack_ucs2_bytes('Limited Service')]: return netname, conn_type # netname can be in UCS2, as a string, or as a network id (int) if check_if_ucs2(netname): return unpack_ucs2_bytes(netname), conn_type else: # now can be either a string or a network id (int) try: netname = int(netname) except ValueError: # we got a string ID return netname, conn_type # if we have arrived here, that means that the network id # is a five digit integer if not process: return netname, conn_type # we got a numeric id, lets convert it from vmc.common.persistent import net_manager network = net_manager.get_network_by_id(netname) if network: return network.get_name(), conn_type # ajb: make consistent display between network returned via id or name # return network.get_full_name(), conn_type return _('Unknown Network'), conn_type
def get_profile_from_imsi_prefix(self): from vmc.common.persistent import net_manager from vmc.common.startup import attach_serial_protocol # we just need the IMSI, but the device is not setup yet. We'll setup # its sconn temporarily device = self.get_device() if not device.sconn: device = attach_serial_protocol(device) def get_imsi_eb(failure): failure.trap(ex.ATError, ex.CMEErrorSIMPINRequired, ex.CMEErrorSIMFailure) # this card doesn't likes to be asked for its IMSI if its not # authenticated, we will just return None, as we don't have any # way to get the IMSI return failure d = device.sconn.get_imsi() d.addCallback(lambda imsi: imsi[:5]) d.addCallback(lambda prefix: net_manager.get_network_by_id(prefix)) d.addErrback(get_imsi_eb) return d