Ejemplo n.º 1
0
def generate_polyfilled(chrome_app_manifest, apis, web_path, ignore_dirs):
    """Generates the polyfilled section of a conversion report.

  Args:
    chrome_app_manifest: Manifest dictionary of input Chrome App.
    apis: Dictionary mapping Chrome Apps API name to polyfill manifest
      dictionaries.
    web_path: Path to output web app directory.
    ignore_dirs: Absolute directory paths to ignore for API usage.

  Returns:
    HTML
  """
    # Which APIs did we polyfill?
    polyfilled_apis = {
        api_name: api_info
        for api_name, api_info in apis.iteritems()
        if api_info['status'] != Status.NONE
    }

    usage = chrome_app.apis.usage(polyfilled_apis,
                                  web_path,
                                  ignore_dirs=ignore_dirs)

    process_usage(polyfilled_apis, usage)

    # Get the warnings for each API; split them into relevant and other warnings.
    for api_name, api_info in polyfilled_apis.iteritems():
        api_info['relevant_warnings'] = []
        for warning in manifest_warnings(api_info, apis):
            # Is this warning's member used by the app?
            # Is it the parent of a member used by the app?
            for used_member in usage[api_name]:
                if used_member.startswith(warning['member']):
                    # This test can and will match too many things, but I'd rather see a
                    # warning which might not be relevant to my code than miss a warning
                    # that might be.
                    api_info['relevant_warnings'].append(warning['text'])
                    break

    return templates.TEMPLATE_POLYFILLED.render(
        some_polyfilled=bool(polyfilled_apis),
        apis=polyfilled_apis,
        chrome_app_manifest=chrome_app_manifest,
        Status=Status)
Ejemplo n.º 2
0
def generate_polyfilled(chrome_app_manifest, apis, web_path, ignore_dirs):
  """Generates the polyfilled section of a conversion report.

  Args:
    chrome_app_manifest: Manifest dictionary of input Chrome App.
    apis: Dictionary mapping Chrome Apps API name to polyfill manifest
      dictionaries.
    web_path: Path to output web app directory.
    ignore_dirs: Absolute directory paths to ignore for API usage.

  Returns:
    HTML
  """
  # Which APIs did we polyfill?
  polyfilled_apis = {api_name: api_info
                     for api_name, api_info in apis.iteritems()
                     if api_info['status'] != Status.NONE}

  usage = chrome_app.apis.usage(
      polyfilled_apis, web_path, ignore_dirs=ignore_dirs)

  process_usage(polyfilled_apis, usage)

  # Get the warnings for each API; split them into relevant and other warnings.
  for api_name, api_info in polyfilled_apis.iteritems():
    api_info['relevant_warnings'] = []
    for warning in manifest_warnings(api_info, apis):
      # Is this warning's member used by the app?
      # Is it the parent of a member used by the app?
      for used_member in usage[api_name]:
        if used_member.startswith(warning['member']):
          # This test can and will match too many things, but I'd rather see a
          # warning which might not be relevant to my code than miss a warning
          # that might be.
          api_info['relevant_warnings'].append(warning['text'])
          break

  return templates.TEMPLATE_POLYFILLED.render(
    some_polyfilled=bool(polyfilled_apis),
    apis=polyfilled_apis,
    chrome_app_manifest=chrome_app_manifest,
    Status=Status
  )
Ejemplo n.º 3
0
def process_usage(apis, usage):
  """Populates usage element of an API dictionary with the usages of that API.

  Args:
    apis: Dictionary mapping Chrome Apps API name to polyfill manifest
      dictionaries. This will be modified.
    usage: Usage dictionary mapping API names to
      (filepath, linenum, context, context_linenum) tuples.
  """

  for api_name, api_info in apis.iteritems():
    api_info['usage'] = []
    for uses in usage[api_name].values():
      for filepath, line_num, context, start in uses:
        context = cgi.escape(context)
        context = highlight_relevant_line(context, line_num - start, apis)
        api_info['usage'].append((filepath, line_num, context, start))

    # Sort first by file, then by line number.
    api_info['usage'].sort()
Ejemplo n.º 4
0
def process_usage(apis, usage):
    """Populates usage element of an API dictionary with the usages of that API.

  Args:
    apis: Dictionary mapping Chrome Apps API name to polyfill manifest
      dictionaries. This will be modified.
    usage: Usage dictionary mapping API names to
      (filepath, linenum, context, context_linenum) tuples.
  """

    for api_name, api_info in apis.iteritems():
        api_info['usage'] = []
        for uses in usage[api_name].values():
            for filepath, line_num, context, start in uses:
                context = cgi.escape(context)
                context = highlight_relevant_line(context, line_num - start,
                                                  apis)
                api_info['usage'].append((filepath, line_num, context, start))

        # Sort first by file, then by line number.
        api_info['usage'].sort()