コード例 #1
0
 def _GetConfigInstructions():
     command = _GSUTIL_PATH
     if util.IsRunningOnCrosDevice():
         command = 'HOME=%s %s' % (_CROS_GSUTIL_HOME_WAR, _GSUTIL_PATH)
     return ('To configure your credentials:\n'
             '  1. Run "%s config" and follow its instructions.\n'
             '  2. If you have a @google.com account, use that account.\n'
             '  3. For the project-id, just enter 0.' % command)
コード例 #2
0
def _RunCommand(args):
    # On cros device, as telemetry is running as root, home will be set to /root/,
    # which is not writable. gsutil will attempt to create a download tracker dir
    # in home dir and fail. To avoid this, override HOME dir to something writable
    # when running on cros device.
    #
    # TODO(tbarzic): Figure out a better way to handle gsutil on cros.
    #     http://crbug.com/386416, http://crbug.com/359293.
    gsutil_env = None
    if util.IsRunningOnCrosDevice():
        gsutil_env = os.environ.copy()
        gsutil_env['HOME'] = _CROS_GSUTIL_HOME_WAR

    if os.name == 'nt':
        # If Windows, prepend python. Python scripts aren't directly executable.
        args = [sys.executable, _GSUTIL_PATH] + args
    else:
        # Don't do it on POSIX, in case someone is using a shell script to redirect.
        args = [_GSUTIL_PATH] + args
        _EnsureExecutable(_GSUTIL_PATH)

    disable_cloud_storage_env_val = os.getenv(DISABLE_CLOUD_STORAGE_IO)
    if disable_cloud_storage_env_val and disable_cloud_storage_env_val != '1':
        logging.error(
            'Unsupported value of environment variable '
            'DISABLE_CLOUD_STORAGE_IO. Expected None or \'1\' but got %s.',
            disable_cloud_storage_env_val)
    if (disable_cloud_storage_env_val == '1'
            and args[0] not in ('help', 'hash', 'version')):
        raise CloudStorageIODisabled(
            "Environment variable DISABLE_CLOUD_STORAGE_IO is set to 1. "
            'Command %s is not allowed to run' % args)

    gsutil = subprocess.Popen(args,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              env=gsutil_env)
    stdout, stderr = gsutil.communicate()

    if gsutil.returncode:
        if stderr.startswith(
            ('You are attempting to access protected data with no configured',
             'Failure: No handler was ready to authenticate.')):
            raise CredentialsError()
        if ('status=403' in stderr or 'status 403' in stderr
                or '403 Forbidden' in stderr):
            raise PermissionError()
        if (stderr.startswith('InvalidUriError') or 'No such object' in stderr
                or 'No URLs matched' in stderr
                or 'One or more URLs matched no' in stderr):
            raise NotFoundError(stderr)
        if '500 Internal Server Error' in stderr:
            raise ServerError(stderr)
        raise CloudStorageError(stderr)

    return stdout
コード例 #3
0
def GetOSNameForCurrentDesktopPlatform():
  if util.IsRunningOnCrosDevice():
    return 'chromeos'
  if sys.platform.startswith('linux'):
    return 'linux'
  if sys.platform == 'darwin':
    return 'mac'
  if sys.platform == 'win32':
    return 'win'
  return sys.platform