Exemplo n.º 1
0
 def testReadSerialMapFile(self):
     curr_dir = os.path.dirname(os.path.realpath(__file__))
     map_dict = battor_device_mapping.ReadSerialMapFile(
         os.path.join(curr_dir, 'test', 'data', 'test_serial_map.json'))
     self.assertEquals(len(map_dict.keys()), 3)
     self.assertEquals(map_dict['Phone1'], 'Battor1')
     self.assertEquals(map_dict['Phone2'], 'Battor2')
     self.assertEquals(map_dict['Phone3'], 'Battor3')
Exemplo n.º 2
0
def IsBattOrConnected(test_platform,
                      android_device=None,
                      android_device_map=None,
                      android_device_file=None):
    """Returns True if BattOr is detected."""
    if test_platform == 'android':
        if not android_device:
            raise ValueError(
                'Must pass android device serial when determining '
                'support on android platform')

        if not android_device_map:
            device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap()
            if device_tree:
                logging.warning('Device tree:')
                for _, node in sorted(device_tree.iteritems()):
                    node.Display()
            else:
                logging.warning('Empty device tree.')
            if len(battor_device_mapping.GetBattOrList(device_tree)) == 1:
                return True
            if android_device_file:
                android_device_map = battor_device_mapping.ReadSerialMapFile(
                    android_device_file)
            else:
                try:
                    android_device_map = battor_device_mapping.GenerateSerialMap(
                    )
                    logging.warning('Android device map: %s',
                                    android_device_map)
                except battor_error.BattOrError:
                    logging.exception('Error generating serial map')
                    return False

        # If neither if statement above is triggered, it means that an
        # android_device_map was passed in and will be used.
        return str(android_device) in android_device_map

    elif test_platform == 'win':
        for (_1, desc, _2) in serial.tools.list_ports.comports():
            if 'USB Serial Port' in desc:
                return True
        logging.info('No usb serial port discovered. Available ones are: %s' %
                     list(serial.tools.list_ports.comports()))
        return False

    elif test_platform == 'mac':
        for (_1, desc, _2) in serial.tools.list_ports.comports():
            if 'BattOr' in desc:
                return True
        return False

    elif test_platform == 'linux':
        device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap(fast=True)
        return bool(battor_device_mapping.GetBattOrList(device_tree))

    return False
Exemplo n.º 3
0
def IsBattOrConnected(test_platform,
                      android_device=None,
                      android_device_map=None,
                      android_device_file=None):
    """Returns True if BattOr is detected."""
    if test_platform == 'android':
        if not android_device:
            raise ValueError(
                'Must pass android device serial when determining '
                'support on android platform')

        if not android_device_map:
            device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap()
            if len(battor_device_mapping.GetBattorList(device_tree)) == 1:
                return True
            if android_device_file:
                android_device_map = battor_device_mapping.ReadSerialMapFile(
                    android_device_file)
            else:
                try:
                    android_device_map = battor_device_mapping.GenerateSerialMap(
                    )
                except battor_error.BattorError:
                    return False

        # If neither if statement above is triggered, it means that an
        # android_device_map was passed in and will be used.
        return str(android_device) in android_device_map

    elif test_platform == 'win':
        for (_1, desc, _2) in serial.tools.list_ports.comports():
            if 'USB Serial Port' in desc:
                return True
        logging.info('No usb serial port discovered. Available ones are: %s' %
                     list(serial.tools.list_ports.comports()))
        return False

    elif test_platform == 'mac':
        # TODO(rnephew): When we have a BattOr that can attach to mac, find a way
        # to detect BattOrs on mac.
        return False

    elif test_platform == 'linux':
        device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap(fast=True)
        return bool(battor_device_mapping.GetBattorList(device_tree))

    return False