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

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

Issue 10854054: Extensions Docs Server: Fix handling of nodocs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: return samples Created 8 years, 4 months 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # Example run from the server2/ directory: 6 # Example run from the server2/ directory:
7 # $ converter.py ../static/ ../../api templates/articles/ templates/intros/ 7 # $ converter.py ../static/ ../../api templates/articles/ templates/intros/
8 # templates/public/ static/images/ -r 8 # templates/public/ static/images/ -r
9 9
10 import json 10 import json
(...skipping 12 matching lines...) Expand all
23 from docs_server_utils import SanitizeAPIName 23 from docs_server_utils import SanitizeAPIName
24 24
25 IGNORED_FILES = [ 25 IGNORED_FILES = [
26 # These are custom files. 26 # These are custom files.
27 '404', 27 '404',
28 'apps_api_index', 28 'apps_api_index',
29 'api_index', 29 'api_index',
30 'experimental', 30 'experimental',
31 'samples', 31 'samples',
32 'index', 32 'index',
33 # These are APIs that should not have docs. 33 'devtools', # Has an intro, but marked as nodoc.
34 'test',
35 'experimental_idltest',
36 ] 34 ]
37 35
38 # These are mappings for APIs that have no intros. They are needed because the 36 # These are mappings for APIs that have no intros. They are needed because the
39 # names of the JSON files do not give enough information on the actual API name. 37 # names of the JSON files do not give enough information on the actual API name.
40 CUSTOM_MAPPINGS = { 38 CUSTOM_MAPPINGS = {
41 'experimental_input_virtual_keyboard': 'experimental_input_virtualKeyboard', 39 'experimental_input_virtual_keyboard': 'experimental_input_virtualKeyboard',
42 'input_ime': 'input_ime' 40 'input_ime': 'input_ime'
43 } 41 }
44 42
45 # These are the extension-only APIs that don't have explicit entries in 43 # These are the extension-only APIs that don't have explicit entries in
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 contents = contents.strip() 177 contents = contents.strip()
180 contents = HandleDocFamily(contents) 178 contents = HandleDocFamily(contents)
181 179
182 # Attempt to guess if the page has no title. 180 # Attempt to guess if the page has no title.
183 if '<h1' not in contents and not is_api: 181 if '<h1' not in contents and not is_api:
184 title = _UnixName(name) 182 title = _UnixName(name)
185 title = ' '.join([part[0].upper() + part[1:] for part in title.split('_')]) 183 title = ' '.join([part[0].upper() + part[1:] for part in title.split('_')])
186 contents = ('<h1 class="page_title">%s</h1>' % title) + contents 184 contents = ('<h1 class="page_title">%s</h1>' % title) + contents
187 return contents 185 return contents
188 186
187 def _GetNoDocs(api_dir, api_files):
188 exclude = []
189 for api in api_files:
190 try:
191 with open(os.path.join(api_dir, api), 'r') as f:
192 if os.path.splitext(api)[-1] == '.idl':
193 if '[nodoc] namespace' in f.read():
194 exclude.append(_UnixName(api))
195 else:
196 api_json = json.loads(json_comment_eater.Nom(f.read()))
197 if api_json[0].get('nodoc', False):
198 exclude.append(_UnixName(api))
199 except Exception:
200 pass
201 return exclude
202
189 def _ProcessName(name): 203 def _ProcessName(name):
190 processed_name = [] 204 processed_name = []
191 if name.startswith('experimental_'): 205 if name.startswith('experimental_'):
192 name = name[len('experimental_'):] 206 name = name[len('experimental_'):]
193 processed_name.append('experimental_') 207 processed_name.append('experimental_')
194 parts = name.split('_') 208 parts = name.split('_')
195 processed_name.append(parts[0]) 209 processed_name.append(parts[0])
196 processed_name.extend([p[0].upper() + p[1:] for p in parts[1:]]) 210 processed_name.extend([p[0].upper() + p[1:] for p in parts[1:]])
197 return ''.join(processed_name) 211 return ''.join(processed_name)
198 212
(...skipping 10 matching lines...) Expand all
209 exclude_files = [] 223 exclude_files = []
210 else: 224 else:
211 exclude_files = [_UnixName(f) for f in os.listdir(exclude_dir)] 225 exclude_files = [_UnixName(f) for f in os.listdir(exclude_dir)]
212 exclude_files.extend(IGNORED_FILES) 226 exclude_files.extend(IGNORED_FILES)
213 api_files = _ListAllAPIs(api_dir) 227 api_files = _ListAllAPIs(api_dir)
214 original_files = [] 228 original_files = []
215 for path, dirs, files in os.walk(template_dest): 229 for path, dirs, files in os.walk(template_dest):
216 original_files.extend(files) 230 original_files.extend(files)
217 if replace: 231 if replace:
218 _CleanAPIs(source_dir, api_dir, intros_dest, template_dest, exclude_files) 232 _CleanAPIs(source_dir, api_dir, intros_dest, template_dest, exclude_files)
233 exclude_files.extend(_GetNoDocs(api_dir, api_files))
219 files = set(os.listdir(source_dir)) 234 files = set(os.listdir(source_dir))
220 unix_files = [_UnixName(f) for f in files] 235 unix_files = [_UnixName(f) for f in files]
221 for name in [SanitizeAPIName(f) for f in _ListAllAPIs(api_dir)]: 236 for name in [SanitizeAPIName(f) for f in _ListAllAPIs(api_dir)]:
222 if _UnixName(name) not in unix_files: 237 if _UnixName(name) not in unix_files:
223 files.add(name + '.html') 238 files.add(name + '.html')
224 for file_ in files: 239 for file_ in files:
225 if (_UnixName(file_) in exclude_files or 240 if (_UnixName(file_) in exclude_files or
226 file_.startswith('.') or 241 file_.startswith('.') or
227 file_.startswith('_')): 242 file_.startswith('_')):
228 continue 243 continue
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if (not opts.file and len(args) != 6) or (opts.file and len(args) != 7): 350 if (not opts.file and len(args) != 6) or (opts.file and len(args) != 7):
336 parser.error('incorrect number of arguments.') 351 parser.error('incorrect number of arguments.')
337 352
338 if opts.file: 353 if opts.file:
339 _MoveSingleFile(*args, replace=opts.replace, svn=opts.svn) 354 _MoveSingleFile(*args, replace=opts.replace, svn=opts.svn)
340 else: 355 else:
341 _MoveAllFiles(*args, 356 _MoveAllFiles(*args,
342 replace=opts.replace, 357 replace=opts.replace,
343 exclude_dir=opts.exclude, 358 exclude_dir=opts.exclude,
344 svn=opts.svn) 359 svn=opts.svn)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698