<s> import subprocess <EOL> from openhtf . plugs . usb import local_usb <EOL> class EtherSync ( object ) : <EOL> """<STR_LIT>""" <EOL> port_map = { <EOL> '<STR_LIT:1>' : '<STR_LIT>' , <EOL> '<STR_LIT:2>' : '<STR_LIT>' , <EOL> '<STR_LIT:3>' : '<STR_LIT>' , <EOL> '<STR_LIT:4>' : '<STR_LIT>' , <EOL> '<STR_LIT:5>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def __init__ ( self , mac_addr ) : <EOL> """<STR_LIT>""" <EOL> addr_info = mac_addr . lower ( ) . split ( '<STR_LIT::>' ) <EOL> if ( len ( addr_info ) < <NUM_LIT:6> ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> addr_info [ <NUM_LIT:2> ] = '<STR_LIT>' <EOL> self . _addr = '<STR_LIT>' . join ( addr_info [ <NUM_LIT:2> : ] ) <EOL> def GetUSBSerial ( self , port_num ) : <EOL> """<STR_LIT>""" <EOL> port = self . port_map [ str ( port_num ) ] <EOL> arg = '<STR_LIT>' . join ( [ '<STR_LIT>' , self . _addr , '<STR_LIT:.>' , port ] ) <EOL> cmd = ( [ '<STR_LIT>' , '<STR_LIT>' , arg ] ) <EOL> info = subprocess . check_output ( cmd , stderr = subprocess . STDOUT ) <EOL> serial = None <EOL> if "<STR_LIT>" in info : <EOL> serial_info = info . split ( '<STR_LIT>' ) [ <NUM_LIT:1> ] <EOL> serial = serial_info . split ( '<STR_LIT:\n>' ) [ <NUM_LIT:0> ] . strip ( ) <EOL> use_info = info . split ( '<STR_LIT>' ) [ <NUM_LIT:1> ] . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:1> ] <EOL> if use_info == '<STR_LIT>' : <EOL> cmd = ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> subprocess . check_output ( cmd , stderr = subprocess . STDOUT ) <EOL> time . sleep ( <NUM_LIT> / <NUM_LIT> ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return serial <EOL> def OpenUSBHandle ( self , port_num ) : <EOL> """<STR_LIT>""" <EOL> serial = self . GetUSBSerial ( port_num ) <EOL> return local_usb . LibUsbHandle . Open ( serial_number = serial ) </s>
