a X @sdZddlZddlZddlZejdkr4ddlmZn(ejdkrLddlmZned ejd dd Z d d Z e d kr|e dS)aAThis module will provide a function called comports that returns an iterable (generator or list) that will enumerate available com ports. Note that on some systems non-existent ports may be listed. Additionally a grep function is supplied that can be used to search for ports based on their descriptions or hardware ID. Nnt)comportsposixz;Sorry: no implementation for your platform ('{}') availableFccsNt|tj}t|D]2}|\}}}||sB||sB||r|VqdS)z Search for ports using a regular expression. Port name, description and hardware ID are searched. The function returns an iterable that returns the same tuples as comport() would do. N)recompileIrsearch)regexp include_linksrinfoportdeschwidr;/usr/lib/python3.9/site-packages/serial/tools/list_ports.pygrep%s   rc Csdddl}|jdd}|jdddd|jdd d d d |jd dd dd |jdtdd|jddd dd |}d}|jr|jstj d |jt t |j|j d}nt t|j d}t|dD]j\}\}}}|jdus|j|kr(tj d ||jr(tj d |tj d ||d7}q|js`|rTtj d |n tj ddS)NrzSerial port enumeration) descriptionr ?z%only show ports that match this regex)nargshelpz-vz --verbose store_truezshow more messages)actionrz-qz--quietzsuppress all messagesz-nzonly output the N-th entry)typerz-sz--include-linksz1include entries that are symlinks to real devicesz Filtered list with regexp: {!r} )r z{:20} z desc: {} z hwid: {} z{} ports found zno ports found )argparseArgumentParser add_argumentint parse_argsr quietsysstderrwriteformatsortedrr r enumeratenstdoutverbose) rparserargshitsiteratorr'r rrrrrmain3sZ  r.__main__)F) __doc__r!osrnameZserial.tools.list_ports_windowsrZserial.tools.list_ports_posix ImportErrorr$rr.__name__rrrr s    8