示例#1
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]
示例#2
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
示例#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_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))
示例#4
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))
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
示例#6
0
  def Canonicalize(self, path):
    starts_with_channel, path_without_channel = (False, path)
    if path.startswith('%s/' % self._channel):
      starts_with_channel, path_without_channel = (
          True, path[len(self._channel) + 1:])

    if any(path.startswith(prefix)
           for prefix in ('extensions/', 'apps/', 'static/')):
      return path

    if '/' in path_without_channel or path_without_channel == '404.html':
      return path

    apps_templates = self._identity_fs.GetFromFileListing(
        '/'.join((svn_constants.PUBLIC_TEMPLATE_PATH, 'apps')))
    extensions_templates = self._identity_fs.GetFromFileListing(
        '/'.join((svn_constants.PUBLIC_TEMPLATE_PATH, 'extensions')))

    if self._channel is None or not starts_with_channel:
      apps_path = 'apps/%s' % path_without_channel
      extensions_path = 'extensions/%s' % path_without_channel
    else:
      apps_path = '%s/apps/%s' % (self._channel, path_without_channel)
      extensions_path = '%s/extensions/%s' % (self._channel,
                                              path_without_channel)

    unix_path = UnixName(os.path.splitext(path_without_channel)[0])
    if unix_path in extensions_templates:
      return extensions_path
    if unix_path in apps_templates:
      return apps_path
    return extensions_path
示例#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 = 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)
示例#8
0
 def GetRefreshPaths(self):
     tasks = []
     for platform in GetPlatforms():
         tasks += [
             '%s/%s' % (platform, UnixName(api)) for api in
             self._platform_bundle.GetAPIModels(platform).GetNames()
         ]
     return tasks
示例#9
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)
示例#10
0
文件: handler.py 项目: ftanx/k2cro4
 def _RedirectBadPaths(self, path, channel_name, default):
     if '/' in path or path == '404.html':
         return False
     apps_templates = APPS_COMPILED_FILE_SYSTEM.GetFromFileListing(
         PUBLIC_TEMPLATE_PATH + '/apps')
     extensions_templates = EXTENSIONS_COMPILED_FILE_SYSTEM.GetFromFileListing(
         PUBLIC_TEMPLATE_PATH + '/extensions')
     unix_path = UnixName(os.path.splitext(path)[0])
     if default:
         apps_path = '/apps/%s' % path
         extensions_path = '/extensions/%s' % path
     else:
         apps_path = '/%s/apps/%s' % (channel_name, path)
         extensions_path = '/%s/extensions/%s' % (channel_name, path)
     if unix_path in extensions_templates:
         self.redirect(extensions_path)
     elif unix_path in apps_templates:
         self.redirect(apps_path)
     else:
         self.redirect(extensions_path)
     return True
示例#11
0
    def _GetApiSchemaFilename(self, 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)

        found_files = file_system.Read(API_PATHS, skip_not_found=True)
        for path, filenames in found_files.Get().iteritems():
            try:
                for ext in ('json', 'idl'):
                    filename = '%s.%s' % (api_name, ext)
                    if filename in filenames:
                        return path + filename
                    if _EXTENSION_API in filenames:
                        return path + _EXTENSION_API
            except FileNotFoundError:
                pass
        return None
示例#12
0
    def _GetApiSchemaFilename(self, 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.
    '''
        def under_api_path(path):
            return API + path

        if version == 'trunk' or version > _ORIGINAL_FEATURES_MIN_VERSION:
            # API schema filenames switch format to unix_hacker_style.
            api_name = UnixName(api_name)

        # |file_system| will cache the results from the ReadSingle() call.
        filenames = file_system.ReadSingle(API).Get()

        for ext in ('json', 'idl'):
            filename = '%s.%s' % (api_name, ext)
            if filename in filenames:
                return under_api_path(filename)
        if _EXTENSION_API in filenames:
            return under_api_path(_EXTENSION_API)
        # API schema data could not be found in any .json or .idl file.
        return None
示例#13
0
def _GetApiSchemaFilename(api_name, schema_fs):
    '''Gets the name of the file which contains the schema for |api_name| in
  |schema_fs|, 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.
  '''
    def under_api_path(path):
        return '%s/%s' % (API_PATH, path)

    try:
        # Prior to Chrome version 18, _EXTENSION_API contained all API schema
        # data, which replaced the current implementation of individual API files.
        # We're forced to parse this (very large) file to determine if the API
        # exists in it.
        extension_api_path = under_api_path(_EXTENSION_API)
        extension_api_json = schema_fs.GetFromFile(extension_api_path).Get()
        if any(api['namespace'] == api_name for api in extension_api_json):
            return extension_api_path
        return None
    except FileNotFoundError:
        pass

    for file_name in (api_name, UnixName(api_name)):
        # From Chrome version 19 and onwards, each API schema is contained within
        # an individual file.
        for ext in ('json', 'idl'):
            try:
                api_file_name = under_api_path('%s.%s' % (file_name, ext))
                schema_fs.GetFromFile(api_file_name).Get()
                return api_file_name
            except FileNotFoundError:
                # The current format of the API filename does not exist in this
                # filesystem.
                pass
    # API schema data could not be found in _EXTENSION_API or in a standalone
    # schema file.
    return None
示例#14
0
def _GetChannelFromManifestFeatures(api_name, json_fs):
    return _GetChannelFromFeatures(  #_manifest_features uses unix_style API names
        UnixName(api_name), json_fs, '%s/_manifest_features.json' % API_PATH)
示例#15
0
def _GetChannelFromManifestFeatures(api_name, json_fs):
    # _manifest_features.json uses unix_style API names.
    api_name = UnixName(api_name)
    return _GetChannelFromFeatures(api_name, json_fs,
                                   '_manifest_features.json')
示例#16
0
def _GetChannelFromManifestFeatures(api_name, features_bundle):
    # _manifest_features.json uses unix_style API names.
    api_name = UnixName(api_name)
    return _GetChannelFromFeatures(api_name,
                                   features_bundle.GetManifestFeatures())
示例#17
0
文件: handler.py 项目: ftanx/k2cro4
def _SplitFilenameUnix(files):
    return [UnixName(os.path.splitext(f.split('/')[-1])[0]) for f in files]