Exemple #1
0
def _GetAPISchemaFilename(api_name, file_system, version):
    '''Gets the name of the file which may contain the schema for |api_name| in
  |file_system|, or None if the API is not found. Note that this may be the
  single _EXTENSION_API file which all APIs share in older versions of Chrome,
  in which case it is unknown whether the API actually exists there.
  '''
    if version == 'master' or version > _ORIGINAL_FEATURES_MIN_VERSION:
        # API schema filenames switch format to unix_hacker_style.
        api_name = UnixName(api_name)

    # Devtools API names have 'devtools.' prepended to them.
    # The corresponding filenames do not.
    if 'devtools_' in api_name:
        api_name = api_name.replace('devtools_', '')

    for api_path in API_PATHS:
        try:
            for base, _, filenames in file_system.Walk(api_path):
                for ext in ('json', 'idl'):
                    filename = '%s.%s' % (api_name, ext)
                    if filename in filenames:
                        return posixpath.join(api_path, base, filename)
                    if _EXTENSION_API in filenames:
                        return posixpath.join(api_path, base, _EXTENSION_API)
        except FileNotFoundError:
            continue
    return None
def _GetAPISchemaFilename(api_name, file_system, version):
  '''Gets the name of the file which may contain the schema for |api_name| in
  |file_system|, or None if the API is not found. Note that this may be the
  single _EXTENSION_API file which all APIs share in older versions of Chrome,
  in which case it is unknown whether the API actually exists there.
  '''
  if version == 'trunk' or version > _ORIGINAL_FEATURES_MIN_VERSION:
    # API schema filenames switch format to unix_hacker_style.
    api_name = UnixName(api_name)

  # Devtools API names have 'devtools.' prepended to them.
  # The corresponding filenames do not.
  if 'devtools_' in api_name:
    api_name = api_name.replace('devtools_', '')

  for api_path in API_PATHS:
    try:
      for base, _, filenames in file_system.Walk(api_path):
        for ext in ('json', 'idl'):
          filename = '%s.%s' % (api_name, ext)
          if filename in filenames:
            return posixpath.join(api_path, base, filename)
          if _EXTENSION_API in filenames:
            return posixpath.join(api_path, base, _EXTENSION_API)
    except FileNotFoundError:
      continue
  return None
Exemple #3
0
    def GetModel(self, api_name):
        # Callers sometimes specify a filename which includes .json or .idl - if
        # so, believe them. They may even include the 'api/' prefix.
        if os.path.splitext(api_name)[1] in (".json", ".idl"):
            if not api_name.startswith(API):
                api_name = posixpath.join(API, api_name)
            return self._model_cache.GetFromFile(api_name)

        assert not api_name.startswith(API)

        # API names are given as declarativeContent and app.window but file names
        # will be declarative_content and app_window.
        file_name = UnixName(api_name).replace(".", "_")
        # Devtools APIs are in API/devtools/ not API/, and have their
        # "devtools" names removed from the file names.
        basename = posixpath.basename(file_name)
        if "devtools_" in basename:
            file_name = posixpath.join("devtools", file_name.replace(basename, basename.replace("devtools_", "")))

        futures = [
            self._model_cache.GetFromFile(posixpath.join(API, "%s.%s" % (file_name, ext))) for ext in ("json", "idl")
        ]

        def resolve():
            for future in futures:
                try:
                    return future.Get()
                except FileNotFoundError:
                    pass
            # Propagate the first FileNotFoundError if neither were found.
            futures[0].Get()

        return Future(delegate=Gettable(resolve))
Exemple #4
0
  def _GetPotentialPathsForModel(self, api_name):
    '''Returns the list of file system paths that the model for |api_name|
    might be located at.
    '''
    # By default |api_name| is assumed to be given without a path or extension,
    # so combinations of known paths and extension types will be searched.
    api_extensions = ('.json', '.idl')
    api_paths = API_PATHS

    # Callers sometimes include a file extension and/or prefix path with the
    # |api_name| argument. We believe them and narrow the search space
    # accordingly.
    name, ext = posixpath.splitext(api_name)
    if ext in api_extensions:
      api_extensions = (ext,)
      api_name = name
    for api_path in api_paths:
      if api_name.startswith(api_path):
        api_name = api_name[len(api_path):]
        api_paths = (api_path,)
        break

    # API names are given as declarativeContent and app.window but file names
    # will be declarative_content and app_window.
    file_name = UnixName(api_name).replace('.', '_')
    # Devtools APIs are in API/devtools/ not API/, and have their
    # "devtools" names removed from the file names.
    basename = posixpath.basename(file_name)
    if 'devtools_' in basename:
      file_name = posixpath.join(
          'devtools', file_name.replace(basename,
                                        basename.replace('devtools_' , '')))

    return [Join(path, file_name + ext) for ext in api_extensions
                                        for path in api_paths]
Exemple #5
0
  def GetModel(self, api_name):
    # Callers sometimes specify a filename which includes .json or .idl - if
    # so, believe them. They may even include the 'api/' prefix.
    if os.path.splitext(api_name)[1] in ('.json', '.idl'):
      if not api_name.startswith(API_PATH + '/'):
        api_name = posixpath.join(API_PATH, api_name)
      return self._model_cache.GetFromFile(api_name)

    assert not api_name.startswith(API_PATH)

    # API names are given as declarativeContent and app.window but file names
    # will be declarative_content and app_window.
    file_name = UnixName(api_name).replace('.', '_')
    # Devtools APIs are in API_PATH/devtools/ not API_PATH/, and have their
    # "devtools" names removed from the file names.
    basename = posixpath.basename(file_name)
    if basename.startswith('devtools_'):
      file_name = posixpath.join(
          'devtools', file_name.replace(basename, basename[len('devtools_'):]))

    futures = [self._model_cache.GetFromFile('%s/%s.%s' %
                                             (API_PATH, file_name, ext))
               for ext in ('json', 'idl')]
    def resolve():
      for future in futures:
        try:
          return future.Get()
        except FileNotFoundError: pass
      # Propagate the first FileNotFoundError if neither were found.
      futures[0].Get()
    return Future(delegate=Gettable(resolve))
Exemple #6
0
    def GetModel(self, api_name):
        # By default |api_name| is assumed to be given without a path or extension,
        # so combinations of known paths and extension types will be searched.
        api_extensions = ('.json', '.idl')
        api_paths = API_PATHS

        # Callers sometimes include a file extension and/or prefix path with the
        # |api_name| argument. We believe them and narrow the search space
        # accordingly.
        name, ext = posixpath.splitext(api_name)
        if ext in api_extensions:
            api_extensions = (ext, )
            api_name = name
        for api_path in api_paths:
            if api_name.startswith(api_path):
                api_name = api_name[len(api_path):]
                api_paths = (api_path, )
                break

        # API names are given as declarativeContent and app.window but file names
        # will be declarative_content and app_window.
        file_name = UnixName(api_name).replace('.', '_')
        # Devtools APIs are in API/devtools/ not API/, and have their
        # "devtools" names removed from the file names.
        basename = posixpath.basename(file_name)
        if 'devtools_' in basename:
            file_name = posixpath.join(
                'devtools',
                file_name.replace(basename, basename.replace('devtools_', '')))

        futures = [
            self._model_cache.GetFromFile(
                posixpath.join(path, '%s%s' % (file_name, ext)))
            for ext in api_extensions for path in api_paths
        ]

        def resolve():
            for future in futures:
                try:
                    return future.Get()
                # Either the file wasn't found or there was no schema for the file
                except (FileNotFoundError, ValueError):
                    pass
            # Propagate the first error if neither were found.
            futures[0].Get()

        return Future(callback=resolve)
Exemple #7
0
    def GetModel(self, api_name):
        # By default |api_name| is assumed to be given without a path or extension,
        # so combinations of known paths and extension types will be searched.
        api_extensions = (".json", ".idl")
        api_paths = (CHROME_API, API)

        # Callers sometimes include a file extension and/or prefix path with the
        # |api_name| argument. We believe them and narrow the search space
        # accordingly.
        name, ext = posixpath.splitext(api_name)
        if ext in api_extensions:
            api_extensions = (ext,)
            api_name = name
        for api_path in api_paths:
            if api_name.startswith(api_path):
                api_name = api_name[len(api_path) :]
                api_paths = (api_path,)
                break

        # API names are given as declarativeContent and app.window but file names
        # will be declarative_content and app_window.
        file_name = UnixName(api_name).replace(".", "_")
        # Devtools APIs are in API/devtools/ not API/, and have their
        # "devtools" names removed from the file names.
        basename = posixpath.basename(file_name)
        if "devtools_" in basename:
            file_name = posixpath.join("devtools", file_name.replace(basename, basename.replace("devtools_", "")))

        futures = [
            self._model_cache.GetFromFile(posixpath.join(path, "%s%s" % (file_name, ext)))
            for ext in api_extensions
            for path in api_paths
        ]

        def resolve():
            for future in futures:
                try:
                    return future.Get()
                except FileNotFoundError:
                    pass
            # Propagate the first FileNotFoundError if neither were found.
            futures[0].Get()

        return Future(callback=resolve)