<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import json <EOL> import os <EOL> import StringIO <EOL> import sys <EOL> import urllib2 <EOL> import zipfile <EOL> _SDK_URL = ( <EOL> '<STR_LIT>' ) <EOL> def get_gae_versions ( ) : <EOL> try : <EOL> version_info_json = urllib2 . urlopen ( _SDK_URL ) . read ( ) <EOL> except : <EOL> return { } <EOL> try : <EOL> version_info = json . loads ( version_info_json ) <EOL> except : <EOL> return { } <EOL> return version_info . get ( '<STR_LIT>' , { } ) <EOL> def _version_tuple ( v ) : <EOL> version_string = os . path . splitext ( v [ '<STR_LIT:name>' ] ) [ <NUM_LIT:0> ] . rpartition ( '<STR_LIT:_>' ) [ <NUM_LIT:2> ] <EOL> return tuple ( int ( x ) for x in version_string . split ( '<STR_LIT:.>' ) ) <EOL> def get_sdk_urls ( sdk_versions ) : <EOL> python_releases = [ v for v in sdk_versions <EOL> if v [ '<STR_LIT:name>' ] . startswith ( '<STR_LIT>' ) ] <EOL> current_releases = sorted ( python_releases , key = _version_tuple , <EOL> reverse = True ) <EOL> return [ release [ '<STR_LIT>' ] for release in current_releases ] <EOL> def main ( argv ) : <EOL> if len ( argv ) > <NUM_LIT:2> : <EOL> print ( '<STR_LIT>' . format ( argv [ <NUM_LIT:0> ] ) ) <EOL> return <NUM_LIT:1> <EOL> dest_dir = argv [ <NUM_LIT:1> ] if len ( argv ) > <NUM_LIT:1> else '<STR_LIT:.>' <EOL> if not os . path . exists ( dest_dir ) : <EOL> os . makedirs ( dest_dir ) <EOL> if os . path . exists ( os . path . join ( dest_dir , '<STR_LIT>' ) ) : <EOL> print ( '<STR_LIT>' . format ( dest_dir ) ) <EOL> return <NUM_LIT:0> <EOL> sdk_versions = get_gae_versions ( ) <EOL> if not sdk_versions : <EOL> print ( '<STR_LIT>' ) <EOL> return <NUM_LIT:1> <EOL> sdk_urls = get_sdk_urls ( sdk_versions ) <EOL> for sdk_url in sdk_urls : <EOL> try : <EOL> sdk_contents = StringIO . StringIO ( urllib2 . urlopen ( sdk_url ) . read ( ) ) <EOL> break <EOL> except : <EOL> pass <EOL> else : <EOL> print ( '<STR_LIT>' , sdk_urls ) <EOL> return <NUM_LIT:1> <EOL> sdk_contents . seek ( <NUM_LIT:0> ) <EOL> try : <EOL> zip_contents = zipfile . ZipFile ( sdk_contents ) <EOL> zip_contents . extractall ( dest_dir ) <EOL> except : <EOL> print ( '<STR_LIT>' ) <EOL> return <NUM_LIT:1> <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( main ( sys . argv [ : ] ) ) </s>
