예제 #1
0
    def test_natsort(self):
        """
        Test that the ``natsort`` function works as expected
        """
        l = []
        for i in range(15):
            l.append("ttyUSB%d" % i)

        unordered = l[:]
        shuffle(unordered)

        self.assertNotIdentical(l, unordered)
        natsort(unordered)
        self.assertEqual(l, unordered)
예제 #2
0
파일: linux.py 프로젝트: andrewbird/wader
    def _get_device_from_info(self, sysfs_path, info):
        """Returns a `DevicePlugin` out of ``info``"""
        # order the ports before probing
        ports = info['DEVICES']
        natsort(ports)

        query = [info.get(key) for key in [VENDOR, MODEL]]
        plugin = PluginManager.get_plugin_by_vendor_product_id(*query)
        if plugin:
            dport = cport = None

            plugin.sysfs_path = sysfs_path
            plugin.opath = self._generate_opath()
            set_property = partial(plugin.set_property, emit=False)
            # set DBus properties (Modem interface)
            set_property(consts.MDM_INTFACE, 'IpMethod',
                         consts.MM_IP_METHOD_PPP)
            set_property(consts.MDM_INTFACE, 'MasterDevice',
                         'udev:%s' % sysfs_path)
            # XXX: Fix CDMA
            set_property(consts.MDM_INTFACE, 'Type',
                         consts.MM_MODEM_TYPE_REV['GSM'])
            set_property(consts.MDM_INTFACE, 'Driver', info[DRIVER])

            set_property(consts.MDM_INTFACE, 'Enabled', dbus.Boolean(False))

            # set to unknown
            set_property(consts.NET_INTFACE, 'AccessTechnology',
                            dbus.UInt32(0))
            # set to preposterous initial number so any comparison will fail
            set_property(consts.NET_INTFACE, 'AllowedMode',
                            dbus.UInt32(0xffff))
            set_property(consts.NET_INTFACE, 'LastApn', '')

            # preprobe stuff
            if hasattr(plugin, 'preprobe_init'):
                # this plugin requires special initialisation before probing
                plugin.preprobe_init(ports, info)

            # now get the ports
            ports_need_probe = True

            if info[DRIVER] == 'hso':
                dport, cport = self._get_hso_ports(ports)
                ports_need_probe = False

            # if these two properties are present, use them right away and
            # do not probe
            if ('ID_MM_PORT_TYPE_MODEM' in info
                    or 'ID_MM_PORT_TYPE_AUX' in info):
                try:
                    dport = info['ID_MM_PORT_TYPE_MODEM']
                    log.msg("%s: ID_MM_PORT_TYPE_MODEM" % dport)
                except KeyError:
                    pass
                try:
                    cport = info['ID_MM_PORT_TYPE_AUX']
                    log.msg("%s: ID_MM_PORT_TYPE_AUX" % cport)
                except KeyError:
                    pass
                ports_need_probe = False

            if ports_need_probe:
                # the ports were not hardcoded nor was an HSO device
                dport, cport = probe_ports(ports)

            if not dport and not cport:
                # this shouldn't happen
                msg = 'No data port and no control port with ports: %s'
                raise RuntimeError(msg % ports)

            if dport is not None:
                set_property(consts.MDM_INTFACE, 'Device',
                                                        dport.split('/')[-1])

            if info[DRIVER] == 'cdc_acm':
                # MBM device
                # XXX: Not all CDC devices support DHCP, to override see
                #      plugin attribute 'ipmethod'
                # XXX: Also need to support Ericsson devices via 'hso' dialer
                #      so that we can use the plain backend. At least F3607GW
                #      supports a get_ip4_config() style AT command to get
                #      network info, else we need to implement a DHCP client
                # set DBus properties (Modem.Gsm.Hso interface)
                hso_device = self._get_hso_device(sysfs_path)
                set_property(consts.MDM_INTFACE, 'Device', hso_device)

                set_property(consts.MDM_INTFACE, 'IpMethod',
                             consts.MM_IP_METHOD_DHCP)

            if plugin.dialer in 'hso':
                # set DBus properties (Modem.Gsm.Hso interface)
                hso_device = self._get_hso_device(sysfs_path)
                set_property(consts.MDM_INTFACE, 'Device', hso_device)

                if hasattr(plugin, 'ipmethod'):
                    # allows us to specify a method in a driver independent way
                    set_property(consts.MDM_INTFACE, 'IpMethod',
                                 plugin.ipmethod)

            if hasattr(plugin, 'conntype') and plugin.conntype:
                set_property(consts.MDM_INTFACE, 'ConnType',
                                dbus.UInt32(plugin.conntype))
            else:
                set_property(consts.MDM_INTFACE, 'ConnType',
                                dbus.UInt32(consts.WADER_CONNTYPE_UNKNOWN))

            plugin.ports = Ports(dport, cport)
            return plugin

        log.msg("Could not find a plugin with info %s" % info)
        return None