
                            d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZej                  j                  e
      Zej                  j                  ed      Zeej                  vrej                  j                  de       ej                  j                  e      rej                  j                  de       d Zd Zd	 Zd
Zej(                  j+                  d      rdndZd Zej0                  d        Zd Zedk(  r e        yy)zgcloud command line tool.    )absolute_import)division)unicode_literalsNthird_partyc                      dt         j                  vryddl} 	 t        |        y# t        $ r ddl}|j                  |        Y yw xY w)a  Reloads the google module to prefer our vendored copy.

  When python is not invoked with the -S option, it can preload google module
  via .pth file setting its __path__. After this happens, our vendored google
  package may not in the __path__. After our vendored dependency directory is
  put at the first place in the sys.path, google module should be reloaded,
  so that our vendored copy can be preferred.
  googleNr   )sysmodulesr   reload	NameError	importlib)r   r   s     lib/gcloud.py_fix_google_moduler   )   sB     S[[ 

6N	 Vs   % AAc                     dt         j                  v rIg }g }| D ]-  }d|v rd|vr|j                  |       |j                  |       / |j                  |       |S | S )al  If site packages are enabled reorder them.

  Make sure bundled_python site-packages appear first in the sys.path.

  Args:
    sys_path: list current sys path

  Returns:
    modified syspath if CLOUDSDK_PYTHON_SITEPACKAGES is on, prefer bundled
    python site packages over all other. Note the returns syspath has the same
    elements but a different order.
  CLOUDSDK_PYTHON_SITEPACKAGESzsite-packageszplatform/bundledpythonunix)osenvironappendextend)sys_pathnew_pathother_site_packagespaths       r   reorder_sys_pathr   <   sh     $rzz1H	D	 %A%M""4(	 
 OO'(OO    c                  "    ddl } | j                  S )z(Returns reference to gcloud_main module.r   N)googlecloudsdk.gcloud_maingcloud_main)googlecloudsdks    r   _import_gcloud_mainr    W   s     $		#	##r   )   	   )ENABLE_MAX_GCLOUD_PYTHON_VERSION_OVERRIDE)r!      )r!      c                 2    dj                  | d   | d         S )Nz{}.{}r      )format)python_versions    r   python_version_stringr*   f   s    	q)>!+<	==r   c            	   #     K   	 d y# t         $ rR t        j                  dd } | t        k  s	| t        kD  rId}| t        kD  rd}nd}dj                  t        |       |t        t              t        t                    }n>d}d	j                  t        j                  t        t              t        t              
      }t        j                  j                  dj                  |             |r]ddl
}t        j                  j                  dj                  dj                  |j                         j                                            t        j                  d       Y yw xY ww)z<Handles exceptions from gcloud to provide a helpful message.N   Fz!not currently supported by gcloudzno longer supported by gcloudzYou are running gcloud with Python {python_version}, which is {support_message}.
Install a compatible version of Python {min_python_version}-{max_python_version} and set the CLOUDSDK_PYTHON environment variable to point to it.)r)   support_messagemin_python_versionmax_python_versionTa\  This usually indicates corruption in your gcloud installation or problems with your Python interpreter.

Please verify that the following is the path to a working Python {min_python_version}-{max_python_version} executable:
    {executable}

If it is not, please set the CLOUDSDK_PYTHON environment variable to point to a working Python executable.)
executabler.   r/   zERROR: gcloud failed to load. {error_message}

If you are still experiencing problems, please reinstall the Google Cloud CLI using the instructions here:
    https://cloud.google.com/sdk/docs/install
)error_messager   z

{}

r'   )	Exceptionr	   version_infoMIN_SUPPORTED_PY3_VERSIONMAX_SUPPORTED_PY3_VERSIONr(   r*   r0   stderrwrite	tracebackjoin
format_exc
splitlinesexit)r)   valid_python_versionr-   r1   r9   s        r   gcloud_exception_handlerr?   j   sU    8		 6 %%bq)N2222"	3	3=9A BH2>B-!6+"-!6+"- BH B.	  "  !6+"-!6+"-	   . " JJ: &}&
- 	jjz((
))I((*557
8: ;HHQKm6s&   E(	 E(EE%"E($E%%E(c                     t               5  t        t        j                        t        _        ddlm}  d d d         j                  t        j                  d      r	 ddl	m
} |j                          y t               5  t                t               }d d d        t        j                  j!                                y # 1 sw Y   xY w# t        $ r' | j                  t        j                  d      dk(  r Y w xY w# 1 sw Y   lxY w)Nr   )encoding_ARGCOMPLETE)lookup_ARGCOMPLETE_TRACEstatic)r?   r   r	   r   googlecloudsdk.core.utilrA   GetEncodedValuer   r   ,googlecloudsdk.command_lib.static_completionrC   Completer3   r   r    r=   main)rA   rC   r   s      r   rJ   rJ      s    !)CH1 "
 bjj.9Eoo  !%'K " ((;) "!  		!	!"**"6
8;C
D
D
 "!s)   )B?C >C>?C-C;:C;>D__main__)__doc__
__future__r   r   r   
contextlibr   r	   r   dirname__file___GCLOUD_PY_DIRr:   _THIRD_PARTY_DIRinsertisdirr   r   r    r5   r   getr6   r*   contextmanagerr?   rJ   __name__ r   r   <module>rY      s   $   &  '  	 
*77<<> 
 !((//!^$77==!"((//!%&&6$ # zz~~3G > : :z0 z& r   