Home | History | Annotate | Download | only in utils
      1 #!/usr/bin/env python
      2 
      3 # Copyright 2016 The Chromium Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 import argparse
      8 import sys
      9 
     10 from devil.utils import battor_device_mapping
     11 
     12 def parse_options():
     13   """Parses and checks the command-line options.
     14 
     15   Returns:
     16     A tuple containing the options structure.
     17   """
     18   usage = 'Usage: ./update_mapping.py [options]'
     19   desc = ('Example: ./update_mapping.py -o mapping.json.\n'
     20   'This script generates and stores a file that gives the\n'
     21   'mapping between phone serial numbers and BattOr serial numbers\n'
     22   'Mapping is based on which physical ports on the USB hubs the\n'
     23   'devices are plugged in to. For instance, if there are two hubs,\n'
     24   'the phone connected to port N on the first hub is mapped to the\n'
     25   'BattOr connected to port N on the second hub, for each N.')
     26   parser = argparse.ArgumentParser(usage=usage, description=desc)
     27   parser.add_argument('-o', '--output', dest='out_file',
     28                       default='mapping.json', type=str,
     29                       action='store', help='mapping file name')
     30   parser.add_argument('-u', '--hub', dest='hub_types',
     31                       action='append', choices=['plugable_7port',
     32                                                 'plugable_7port_usb3_part2',
     33                                                 'plugable_7port_usb3_part3'],
     34                       help='USB hub types.')
     35   options = parser.parse_args()
     36   if not options.hub_types:
     37     options.hub_types = ['plugable_7port', 'plugable_7port_usb3_part2',
     38                          'plugable_7port_usb3_part3']
     39   return options
     40 
     41 def main():
     42   options = parse_options()
     43   battor_device_mapping.GenerateSerialMapFile(options.out_file,
     44                                               options.hub_types)
     45 
     46 if __name__ == "__main__":
     47   sys.exit(main())
     48