<s> import os <EOL> import sys <EOL> import click <EOL> import requests <EOL> from platformio import __version__ , exception , util <EOL> @ click . command ( "<STR_LIT>" , <EOL> short_help = "<STR_LIT>" ) <EOL> def cli ( ) : <EOL> last = get_latest_version ( ) <EOL> if __version__ == last : <EOL> return click . secho ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % __version__ , fg = "<STR_LIT>" <EOL> ) <EOL> else : <EOL> click . secho ( "<STR_LIT>" , <EOL> fg = "<STR_LIT>" ) <EOL> to_develop = False <EOL> try : <EOL> from pkg_resources import parse_version <EOL> to_develop = parse_version ( last ) < parse_version ( __version__ ) <EOL> except ImportError : <EOL> pass <EOL> cmds = ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> if to_develop else "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ) <EOL> cmd = None <EOL> r = None <EOL> try : <EOL> for cmd in cmds : <EOL> cmd = [ os . path . normpath ( sys . executable ) , "<STR_LIT>" ] + cmd <EOL> r = None <EOL> r = util . exec_command ( cmd ) <EOL> if r [ '<STR_LIT>' ] != <NUM_LIT:0> and cmd [ <NUM_LIT:2> ] == "<STR_LIT>" : <EOL> cmd . insert ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> r = util . exec_command ( cmd ) <EOL> assert r [ '<STR_LIT>' ] == <NUM_LIT:0> <EOL> assert "<STR_LIT:version>" in r [ '<STR_LIT>' ] <EOL> actual_version = r [ '<STR_LIT>' ] . strip ( ) . split ( "<STR_LIT:version>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> click . secho ( <EOL> "<STR_LIT>" % <EOL> actual_version , fg = "<STR_LIT>" ) <EOL> click . echo ( "<STR_LIT>" , nl = False ) <EOL> click . secho ( "<STR_LIT>" , <EOL> fg = "<STR_LIT>" ) <EOL> except Exception as e : <EOL> if not r : <EOL> raise exception . UpgradeError ( <EOL> "<STR_LIT:\n>" . join ( [ str ( cmd ) , str ( e ) ] ) ) <EOL> permission_errors = ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ) <EOL> if ( any ( [ m in r [ '<STR_LIT>' ] . lower ( ) for m in permission_errors ] ) and <EOL> "<STR_LIT>" not in util . get_systype ( ) ) : <EOL> click . secho ( """<STR_LIT>""" , fg = "<STR_LIT>" , err = True ) <EOL> raise exception . ReturnErrorCode ( ) <EOL> else : <EOL> raise exception . UpgradeError ( <EOL> "<STR_LIT:\n>" . join ( [ str ( cmd ) , r [ '<STR_LIT>' ] , r [ '<STR_LIT>' ] ] ) ) <EOL> def get_latest_version ( ) : <EOL> try : <EOL> pkgdata = requests . get ( <EOL> "<STR_LIT>" , <EOL> headers = util . get_request_defheaders ( ) <EOL> ) . json ( ) <EOL> return pkgdata [ '<STR_LIT:info>' ] [ '<STR_LIT:version>' ] <EOL> except : <EOL> raise exception . GetLatestVersionError ( ) </s>
