def main():
    sys.path = reorder_sys_path(sys.path)
    # pylint:disable=g-import-not-at-top
    from googlecloudsdk.core.util import encoding

    if encoding.GetEncodedValue(os.environ, '_ARGCOMPLETE'):
        try:
            # pylint:disable=g-import-not-at-top
            import googlecloudsdk.command_lib.static_completion.lookup as lookup
            lookup.Complete()
            return
        except Exception:  # pylint:disable=broad-except, hide completion errors
            if encoding.GetEncodedValue(os.environ,
                                        '_ARGCOMPLETE_TRACE') == 'static':
                raise

    try:
        _fix_google_module()
        gcloud_main = _import_gcloud_main()
    except Exception as err:  # pylint: disable=broad-except
        # We want to catch *everything* here to display a nice message to the user
        # pylint:disable=g-import-not-at-top
        import traceback
        # We DON'T want to suggest `gcloud components reinstall` here (ex. as
        # opposed to the similar message in gcloud_main.py), as we know that no
        # commands will work.
        sys.stderr.write((
            'ERROR: gcloud failed to load: {0}\n{1}\n\n'
            'This usually indicates corruption in your gcloud installation or '
            'problems with your Python interpreter.\n\n'
            'Please verify that the following is the path to a working Python 2.7 '
            'or 3.5+ executable:\n'
            '    {2}\n\n'
            'If it is not, please set the CLOUDSDK_PYTHON environment variable to '
            'point to a working Python 2.7 or 3.5+ executable.\n\n'
            'If you are still experiencing problems, please reinstall the Cloud '
            'SDK using the instructions here:\n'
            '    https://cloud.google.com/sdk/\n').format(
                err, '\n'.join(traceback.format_exc().splitlines()[2::2]),
                sys.executable))
        sys.exit(1)
    sys.exit(gcloud_main.main())
Exemplo n.º 2
0
def main():

  if '_ARGCOMPLETE' in os.environ:
    try:
      # pylint:disable=g-import-not-at-top
      import googlecloudsdk.command_lib.static_completion.lookup as lookup
      lookup.Complete()
      return
    except Exception:  # pylint:disable=broad-except, hide completion errors
      if os.environ.get('_ARGCOMPLETE_TRACE') == 'static':
        raise

  try:
    gcloud_main = _import_gcloud_main()
  except Exception as err:  # pylint: disable=broad-except
    # We want to catch *everything* here to display a nice message to the user
    # pylint:disable=g-import-not-at-top
    import traceback
    # We DON'T want to suggest `gcloud components reinstall` here (ex. as
    # opposed to the similar message in gcloud_main.py), as we know that no
    # commands will work.
    sys.stderr.write(
        ('ERROR: gcloud failed to load: {0}\n{1}\n\n'
         'This usually indicates corruption in your gcloud installation or '
         'problems with your Python interpreter.\n\n'
         'Please verify that the following is the path to a working Python 2.7 '
         'executable:\n'
         '    {2}\n\n'
         'If it is not, please set the CLOUDSDK_PYTHON environment variable to '
         'point to a working Python 2.7 executable.\n\n'
         'If you are still experiencing problems, please reinstall the Cloud '
         'SDK using the instructions here:\n'
         '    https://cloud.google.com/sdk/\n').format(
             err,
             '\n'.join(traceback.format_exc().splitlines()[2::2]),
             sys.executable))
    sys.exit(1)
  sys.exit(gcloud_main.main())