<s> from os import getenv , listdir <EOL> from os . path import join <EOL> from platform import system <EOL> from sys import exit as sys_exit <EOL> from traceback import format_exc <EOL> import click <EOL> import requests <EOL> from platformio import __version__ , exception , maintenance <EOL> from platformio . util import get_source_dir <EOL> class PlatformioCLI ( click . MultiCommand ) : <EOL> def list_commands ( self , ctx ) : <EOL> cmds = [ ] <EOL> for filename in listdir ( join ( get_source_dir ( ) , "<STR_LIT>" ) ) : <EOL> if filename . startswith ( "<STR_LIT>" ) : <EOL> continue <EOL> if filename . endswith ( "<STR_LIT>" ) : <EOL> cmds . append ( filename [ : - <NUM_LIT:3> ] ) <EOL> cmds . sort ( ) <EOL> return cmds <EOL> def get_command ( self , ctx , name ) : <EOL> mod = None <EOL> try : <EOL> mod = __import__ ( "<STR_LIT>" + name , <EOL> None , None , [ "<STR_LIT>" ] ) <EOL> except ImportError : <EOL> try : <EOL> return self . _handle_obsolate_command ( name ) <EOL> except AttributeError : <EOL> raise click . UsageError ( '<STR_LIT>' % name , ctx ) <EOL> return mod . cli <EOL> @ staticmethod <EOL> def _handle_obsolate_command ( name ) : <EOL> if name in ( "<STR_LIT>" , "<STR_LIT:list>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> click . secho ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( name , name ) , <EOL> fg = "<STR_LIT>" <EOL> ) <EOL> from platformio . commands import platforms <EOL> return getattr ( platforms , "<STR_LIT>" + name ) <EOL> raise AttributeError ( ) <EOL> @ click . command ( cls = PlatformioCLI , <EOL> context_settings = dict ( help_option_names = [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> @ click . version_option ( __version__ , prog_name = "<STR_LIT>" ) <EOL> @ click . option ( "<STR_LIT>" , "<STR_LIT>" , is_flag = True , <EOL> help = "<STR_LIT>" ) <EOL> @ click . option ( "<STR_LIT>" , "<STR_LIT:-c>" , help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def cli ( ctx , force , caller ) : <EOL> if not caller and getenv ( "<STR_LIT>" ) : <EOL> caller = getenv ( "<STR_LIT>" ) <EOL> maintenance . on_platformio_start ( ctx , force , caller ) <EOL> @ cli . resultcallback ( ) <EOL> @ click . pass_context <EOL> def process_result ( ctx , result , force , caller ) : <EOL> maintenance . on_platformio_end ( ctx , result ) <EOL> def main ( ) : <EOL> try : <EOL> if "<STR_LIT>" in system ( ) . lower ( ) : <EOL> raise exception . CygwinEnvDetected ( ) <EOL> try : <EOL> requests . packages . urllib3 . disable_warnings ( ) <EOL> except AttributeError : <EOL> raise exception . PlatformioException ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if str ( getenv ( "<STR_LIT>" , "<STR_LIT>" ) ) . lower ( ) == "<STR_LIT:true>" : <EOL> try : <EOL> click . _compat . isatty = lambda stream : True <EOL> except : <EOL> pass <EOL> cli ( None , None , None ) <EOL> except Exception as e : <EOL> if not isinstance ( e , exception . ReturnErrorCode ) : <EOL> maintenance . on_platformio_exception ( e ) <EOL> error_str = "<STR_LIT>" <EOL> if isinstance ( e , exception . PlatformioException ) : <EOL> error_str += str ( e ) <EOL> else : <EOL> error_str += format_exc ( ) <EOL> error_str += """<STR_LIT>""" <EOL> click . secho ( error_str , fg = "<STR_LIT>" , err = True ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys_exit ( main ( ) ) </s>
