Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / server2 / compiled_file_system.py
index e9b43eb..58ab967 100644 (file)
@@ -8,7 +8,7 @@ import schema_util
 from docs_server_utils import ToUnicode
 from file_system import FileNotFoundError
 from future import Future
-from path_util import AssertIsDirectory, AssertIsFile
+from path_util import AssertIsDirectory, AssertIsFile, ToDirectory
 from third_party.handlebar import Handlebar
 from third_party.json_schema_compiler import json_parse
 from third_party.json_schema_compiler.memoize import memoize
@@ -106,17 +106,6 @@ class CompiledFileSystem(object):
                          category='json')
 
     @memoize
-    def ForAPISchema(self, file_system):
-      '''Creates a CompiledFileSystem for parsing raw JSON or IDL API schema
-      data and formatting it so that it can be used by other classes, such
-      as Model and APISchemaGraph.
-      '''
-      return self.Create(file_system,
-                         SingleFile(Unicode(schema_util.ProcessSchema)),
-                         CompiledFileSystem,
-                         category='api-schema')
-
-    @memoize
     def ForTemplates(self, file_system):
       '''Creates a CompiledFileSystem for parsing templates.
       '''
@@ -173,32 +162,28 @@ class CompiledFileSystem(object):
     if not first_layer_dirs:
       return Future(value=first_layer_files)
 
-    second_layer_listing = self._file_system.Read(
-        add_prefix(path, first_layer_dirs))
-
-    def resolve():
-      def get_from_future_listing(futures):
-        '''Recursively lists files from directory listing |futures|.
-        '''
-        dirs, files = [], []
-        for dir_name, listing in futures.Get().iteritems():
-          new_dirs, new_files = split_dirs_from_files(listing)
-          # |dirs| are paths for reading. Add the full prefix relative to
-          # |path| so that |file_system| can find the files.
-          dirs += add_prefix(dir_name, new_dirs)
-          # |files| are not for reading, they are for returning to the caller.
-          # This entire function set (i.e. GetFromFileListing) is defined to
-          # not include the fetched-path in the result, however, |dir_name|
-          # will be prefixed with |path|. Strip it.
-          assert dir_name.startswith(path)
-          files += add_prefix(dir_name[len(path):], new_files)
-        if dirs:
-          files += get_from_future_listing(self._file_system.Read(dirs))
-        return files
-
-      return first_layer_files + get_from_future_listing(second_layer_listing)
-
-    return Future(callback=resolve)
+    def get_from_future_listing(listings):
+      '''Recursively lists files from directory listing |futures|.
+      '''
+      dirs, files = [], []
+      for dir_name, listing in listings.iteritems():
+        new_dirs, new_files = split_dirs_from_files(listing)
+        # |dirs| are paths for reading. Add the full prefix relative to
+        # |path| so that |file_system| can find the files.
+        dirs += add_prefix(dir_name, new_dirs)
+        # |files| are not for reading, they are for returning to the caller.
+        # This entire function set (i.e. GetFromFileListing) is defined to
+        # not include the fetched-path in the result, however, |dir_name|
+        # will be prefixed with |path|. Strip it.
+        assert dir_name.startswith(path)
+        files += add_prefix(dir_name[len(path):], new_files)
+      if dirs:
+        files += self._file_system.Read(dirs).Then(
+            lambda results: get_from_future_listing(results)).Get()
+      return files
+
+    return self._file_system.Read(add_prefix(path, first_layer_dirs)).Then(
+        lambda results: first_layer_files + get_from_future_listing(results))
 
   def GetFromFile(self, path):
     '''Calls |compilation_function| on the contents of the file at |path|.  If
@@ -217,12 +202,11 @@ class CompiledFileSystem(object):
     if (cache_entry is not None) and (version == cache_entry.version):
       return Future(value=cache_entry._cache_data)
 
-    future_files = self._file_system.ReadSingle(path)
-    def resolve():
-      cache_data = self._compilation_function(path, future_files.Get())
+    def next(files):
+      cache_data = self._compilation_function(path, files)
       self._file_object_store.Set(path, _CacheEntry(cache_data, version))
       return cache_data
-    return Future(callback=resolve)
+    return self._file_system.ReadSingle(path).Then(next)
 
   def GetFromFileListing(self, path):
     '''Calls |compilation_function| on the listing of the files at |path|.
@@ -239,12 +223,11 @@ class CompiledFileSystem(object):
     if (cache_entry is not None) and (version == cache_entry.version):
       return Future(value=cache_entry._cache_data)
 
-    recursive_list_future = self._RecursiveList(path)
-    def resolve():
-      cache_data = self._compilation_function(path, recursive_list_future.Get())
+    def next(files):
+      cache_data = self._compilation_function(path, files)
       self._list_object_store.Set(path, _CacheEntry(cache_data, version))
       return cache_data
-    return Future(callback=resolve)
+    return self._RecursiveList(path).Then(next)
 
   def GetFileVersion(self, path):
     cache_entry = self._file_object_store.Get(path).Get()
@@ -253,8 +236,7 @@ class CompiledFileSystem(object):
     return self._file_system.Stat(path).version
 
   def GetFileListingVersion(self, path):
-    if not path.endswith('/'):
-      path += '/'
+    path = ToDirectory(path)
     cache_entry = self._list_object_store.Get(path).Get()
     if cache_entry is not None:
       return cache_entry.version