<s> import glob <EOL> import os <EOL> from serial . tools import list_ports_common <EOL> class SysFS ( list_ports_common . ListPortInfo ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , device ) : <EOL> super ( SysFS , self ) . __init__ ( device ) <EOL> self . name = os . path . basename ( device ) <EOL> self . usb_device_path = None <EOL> if os . path . exists ( '<STR_LIT>' % ( self . name , ) ) : <EOL> self . device_path = os . path . realpath ( '<STR_LIT>' % ( self . name , ) ) <EOL> self . subsystem = os . path . basename ( os . path . realpath ( os . path . join ( self . device_path , '<STR_LIT>' ) ) ) <EOL> else : <EOL> self . device_path = None <EOL> self . subsystem = None <EOL> if self . subsystem == '<STR_LIT>' : <EOL> self . usb_device_path = os . path . dirname ( os . path . dirname ( self . device_path ) ) <EOL> elif self . subsystem == '<STR_LIT>' : <EOL> self . usb_device_path = os . path . dirname ( self . device_path ) <EOL> else : <EOL> self . usb_device_path = None <EOL> if self . usb_device_path is not None : <EOL> self . vid = int ( self . read_line ( self . usb_device_path , '<STR_LIT>' ) , <NUM_LIT:16> ) <EOL> self . pid = int ( self . read_line ( self . usb_device_path , '<STR_LIT>' ) , <NUM_LIT:16> ) <EOL> self . serial_number = self . read_line ( self . usb_device_path , '<STR_LIT>' ) <EOL> self . location = os . path . basename ( self . usb_device_path ) <EOL> self . manufacturer = self . read_line ( self . usb_device_path , '<STR_LIT>' ) <EOL> self . product = self . read_line ( self . usb_device_path , '<STR_LIT>' ) <EOL> self . interface = self . read_line ( self . device_path , '<STR_LIT>' ) <EOL> if self . subsystem in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . apply_usb_info ( ) <EOL> elif self . subsystem == '<STR_LIT>' : <EOL> self . description = self . name <EOL> self . hwid = self . read_line ( self . device_path , '<STR_LIT:id>' ) <EOL> elif self . subsystem == '<STR_LIT>' : <EOL> self . description = self . name <EOL> self . hwid = os . path . basename ( self . device_path ) <EOL> def read_line ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> with open ( os . path . join ( * args ) ) as f : <EOL> line = f . readline ( ) . strip ( ) <EOL> return line <EOL> except IOError : <EOL> return None <EOL> def comports ( ) : <EOL> devices = glob . glob ( '<STR_LIT>' ) <EOL> devices . extend ( glob . glob ( '<STR_LIT>' ) ) <EOL> devices . extend ( glob . glob ( '<STR_LIT>' ) ) <EOL> devices . extend ( glob . glob ( '<STR_LIT>' ) ) <EOL> devices . extend ( glob . glob ( '<STR_LIT>' ) ) <EOL> return [ info <EOL> for info in [ SysFS ( d ) for d in devices ] <EOL> if info . subsystem != "<STR_LIT>" ] <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> for port , desc , hwid in sorted ( comports ( ) ) : <EOL> print ( "<STR_LIT>" % ( port , desc , hwid ) ) </s>
