Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/common/extensions/docs/server2/api_models.py

Issue 68873003: Docserver: Serve docs out of src/ not src/chrome/common/extensions. This allows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix samples Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import logging 5 import logging
6 import os 6 import os
7 import posixpath 7 import posixpath
8 8
9 from compiled_file_system import SingleFile 9 from compiled_file_system import SingleFile
10 from extensions_paths import API
10 from file_system import FileNotFoundError 11 from file_system import FileNotFoundError
11 from future import Gettable, Future 12 from future import Gettable, Future
12 from schema_util import ProcessSchema 13 from schema_util import ProcessSchema
13 from svn_constants import API_PATH
14 from third_party.json_schema_compiler.model import Namespace, UnixName 14 from third_party.json_schema_compiler.model import Namespace, UnixName
15 15
16 16
17 @SingleFile 17 @SingleFile
18 def _CreateAPIModel(path, data): 18 def _CreateAPIModel(path, data):
19 schema = ProcessSchema(path, data) 19 schema = ProcessSchema(path, data)
20 if os.path.splitext(path)[1] == '.json': 20 if os.path.splitext(path)[1] == '.json':
21 schema = schema[0] 21 schema = schema[0]
22 return Namespace(schema, schema['namespace']) 22 return Namespace(schema, schema['namespace'])
23 23
(...skipping 15 matching lines...) Expand all
39 api_features = self._features_bundle.GetAPIFeatures().Get() 39 api_features = self._features_bundle.GetAPIFeatures().Get()
40 return [name for name, feature in api_features.iteritems() 40 return [name for name, feature in api_features.iteritems()
41 if ('.' not in name or 41 if ('.' not in name or
42 name.rsplit('.', 1)[0] not in api_features or 42 name.rsplit('.', 1)[0] not in api_features or
43 feature.get('noparent'))] 43 feature.get('noparent'))]
44 44
45 def GetModel(self, api_name): 45 def GetModel(self, api_name):
46 # Callers sometimes specify a filename which includes .json or .idl - if 46 # Callers sometimes specify a filename which includes .json or .idl - if
47 # so, believe them. They may even include the 'api/' prefix. 47 # so, believe them. They may even include the 'api/' prefix.
48 if os.path.splitext(api_name)[1] in ('.json', '.idl'): 48 if os.path.splitext(api_name)[1] in ('.json', '.idl'):
49 if not api_name.startswith(API_PATH + '/'): 49 if not api_name.startswith(API + '/'):
50 api_name = posixpath.join(API_PATH, api_name) 50 api_name = posixpath.join(API, api_name)
51 return self._model_cache.GetFromFile(api_name) 51 return self._model_cache.GetFromFile(api_name)
52 52
53 assert not api_name.startswith(API_PATH) 53 assert not api_name.startswith(API)
54 54
55 # API names are given as declarativeContent and app.window but file names 55 # API names are given as declarativeContent and app.window but file names
56 # will be declarative_content and app_window. 56 # will be declarative_content and app_window.
57 file_name = UnixName(api_name).replace('.', '_') 57 file_name = UnixName(api_name).replace('.', '_')
58 # Devtools APIs are in API_PATH/devtools/ not API_PATH/, and have their 58 # Devtools APIs are in API/devtools/ not API/, and have their
59 # "devtools" names removed from the file names. 59 # "devtools" names removed from the file names.
60 basename = posixpath.basename(file_name) 60 basename = posixpath.basename(file_name)
61 if basename.startswith('devtools_'): 61 if basename.startswith('devtools_'):
62 file_name = posixpath.join( 62 file_name = posixpath.join(
63 'devtools', file_name.replace(basename, basename[len('devtools_'):])) 63 'devtools', file_name.replace(basename, basename[len('devtools_'):]))
64 64
65 futures = [self._model_cache.GetFromFile('%s/%s.%s' % 65 futures = [self._model_cache.GetFromFile('%s/%s.%s' % (API, file_name, ext))
66 (API_PATH, file_name, ext))
67 for ext in ('json', 'idl')] 66 for ext in ('json', 'idl')]
68 def resolve(): 67 def resolve():
69 for future in futures: 68 for future in futures:
70 try: 69 try:
71 return future.Get() 70 return future.Get()
72 except FileNotFoundError: pass 71 except FileNotFoundError: pass
73 # Propagate the first FileNotFoundError if neither were found. 72 # Propagate the first FileNotFoundError if neither were found.
74 futures[0].Get() 73 futures[0].Get()
75 return Future(delegate=Gettable(resolve)) 74 return Future(delegate=Gettable(resolve))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698