o
                         @   s   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	e
ZejedZeejvr9ejde ejerFejde dd Zd	d
 Zdd ZdZejdr\dndZdd Zejdd Zdd Zedkrve  dS dS )zgcloud command line tool.    )absolute_import)division)unicode_literalsNthird_partyc                  C   sL   dt jvrdS ddl} zt|  W dS  ty%   ddl}||  Y dS 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    r   #/tmp/google-cloud-sdk/lib/gcloud.py_fix_google_module)   s   
	r   c                 C   sT   dt jv r(g }g }| D ]}d|v rd|vr|| q|| q|| |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pathr   r   r   reorder_sys_path<   s   

r   c                  C   s   ddl } | jS )z(Returns reference to gcloud_main module.r   N)googlecloudsdk.gcloud_maingcloud_main)googlecloudsdkr   r   r   _import_gcloud_mainW   s   r   )   	   )ENABLE_MAX_GCLOUD_PYTHON_VERSION_OVERRIDE)r      )r      c                 C   s   d | d | d S )Nz{}.{}r      )format)python_versionr   r   r   python_version_stringf   s   r%   c                  c   s    zdV  W dS  t yo   tjdd } | tk s| tkr8d}| tkr&d}nd}djt| |ttttd}nd}d	jtjttttd
}tj	dj|d |rgddl
}tj	dd|   td Y dS 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%   r*   stderrwrite	tracebackjoin
format_exc
splitlinesexit)r$   valid_python_versionr'   r+   r3   r   r   r   gcloud_exception_handlerj   s\   
r9   c                  C   s   t   ttjt_ddlm}  W d    n1 sw   Y  | tjdrGzddl	m
} |  W d S  tyF   | tjddkrD Y nw t   t  t }W d    n1 s[w   Y  t|  d S )Nr   )encoding_ARGCOMPLETE)lookup_ARGCOMPLETE_TRACEstatic)r9   r   r   r   googlecloudsdk.core.utilr:   GetEncodedValuer   r   ,googlecloudsdk.command_lib.static_completionr<   Completer-   r   r   r7   main)r:   r<   r   r   r   r   rC      s.   rC   __main__)__doc__
__future__r   r   r   
contextlibr   r   r   dirname__file___GCLOUD_PY_DIRr4   _THIRD_PARTY_DIRinsertisdirr   r   r   r/   r   getr0   r%   contextmanagerr9   rC   __name__r   r   r   r   <module>   s:   

=
