def _ConvertBuiltinsToIncludes(included_from, app_include, state, runtime):
    """Converts builtins directives to includes directives.

  Moves all builtins directives in app_include into the includes
  directives list.  Modifies class excludes dict if any builtins are
  switched off.  Class includes dict is used to determine if an excluded
  builtin was previously included.

  Args:
    included_from: file that builtin directive was found in
    app_include: the AppInclude object currently being processed.
    state: contains the list of included and excluded files as well as the
           directives of all encountered AppInclude objects.
    runtime: name of the runtime.

  Returns:
    list of the absolute paths to the include files for builtins where
    "x: on" directive was specified, e.g. "builtins:\n  default: on" ->
    ['/google/appengine/ext/builtins/default/include.yaml']
  """
    includes_list = []
    if app_include.builtins:
        builtins_list = appinfo.BuiltinHandler.ListToTuples(app_include.builtins)
        for builtin_name, on_or_off in builtins_list:

            if not on_or_off:
                continue

            yaml_path = builtins.get_yaml_path(builtin_name, runtime)

            if on_or_off == "on":
                includes_list.append(yaml_path)
            elif on_or_off == "off":
                if yaml_path in state.includes:
                    logging.warning(
                        "%s already included by %s but later disabled by %s",
                        yaml_path,
                        state.includes[yaml_path],
                        included_from,
                    )
                state.excludes[yaml_path] = included_from
            else:
                logging.error(
                    "Invalid state for AppInclude object loaded from %s; " 'builtins directive "%s: %s" ignored.',
                    included_from,
                    builtin_name,
                    on_or_off,
                )

    return includes_list
Esempio n. 2
0
def _ConvertBuiltinsToIncludes(included_from, app_include, state, runtime):
    """Converts builtins directives to includes directives.

  Moves all builtins directives in app_include into the includes
  directives list.  Modifies class excludes dict if any builtins are
  switched off.  Class includes dict is used to determine if an excluded
  builtin was previously included.

  Args:
    included_from: file that builtin directive was found in
    app_include: the AppInclude object currently being processed.
    state: contains the list of included and excluded files as well as the
           directives of all encountered AppInclude objects.
    runtime: name of the runtime.

  Returns:
    list of the absolute paths to the include files for builtins where
    "x: on" directive was specified, e.g. "builtins:\n  default: on" ->
    ['/google/appengine/ext/builtins/default/include.yaml']
  """
    includes_list = []
    if app_include.builtins:
        builtins_list = appinfo.BuiltinHandler.ListToTuples(
            app_include.builtins)
        for builtin_name, on_or_off in builtins_list:

            if not on_or_off:
                continue

            yaml_path = builtins.get_yaml_path(builtin_name, runtime)

            if on_or_off == 'on':
                includes_list.append(yaml_path)
            elif on_or_off == 'off':
                if yaml_path in state.includes:
                    logging.warning(
                        '%s already included by %s but later disabled by %s',
                        yaml_path, state.includes[yaml_path], included_from)
                state.excludes[yaml_path] = included_from
            else:
                logging.error(
                    'Invalid state for AppInclude object loaded from %s; '
                    'builtins directive "%s: %s" ignored.', included_from,
                    builtin_name, on_or_off)

    return includes_list