OLD | NEW |
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 19 matching lines...) Expand all Loading... |
30 'experimental', | 30 'experimental', |
31 'samples', | 31 'samples', |
32 'index', | 32 'index', |
33 'devtools', # Has an intro, but marked as nodoc. | 33 'devtools', # Has an intro, but marked as nodoc. |
34 ] | 34 ] |
35 | 35 |
36 # 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 |
37 # 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. |
38 CUSTOM_MAPPINGS = { | 38 CUSTOM_MAPPINGS = { |
39 'experimental_input_virtual_keyboard': 'experimental_input_virtualKeyboard', | 39 'experimental_input_virtual_keyboard': 'experimental_input_virtualKeyboard', |
| 40 'experimental_system_info_cpu': 'experimental_systemInfo_cpu', |
| 41 'experimental_system_info_storage': 'experimental_systemInfo_storage', |
40 'input_ime': 'input_ime', | 42 'input_ime': 'input_ime', |
41 'app_window': 'app_window' | 43 'app_runtime': 'app_runtime', |
| 44 'app_window': 'app_window', |
42 } | 45 } |
43 | 46 |
44 # These are the extension-only APIs that don't have explicit entries in | 47 # These are the extension-only APIs that don't have explicit entries in |
45 # _permission_features.json, so we can't programmatically figure out that it's | 48 # _permission_features.json, so we can't programmatically figure out that it's |
46 # extension-only. | 49 # extension-only. |
47 # From api_page_generator.js:548. | 50 # From api_page_generator.js:548. |
48 EXTENSIONS_ONLY = [ | 51 EXTENSIONS_ONLY = [ |
49 'browserAction', | 52 'browserAction', |
50 'extension', | 53 'extension', |
51 'input_ime', | 54 'input_ime', |
(...skipping 28 matching lines...) Expand all Loading... |
80 Shamelessly stolen from json_schema_compiler/model.py. | 83 Shamelessly stolen from json_schema_compiler/model.py. |
81 """ | 84 """ |
82 name = os.path.splitext(name)[0] | 85 name = os.path.splitext(name)[0] |
83 s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name) | 86 s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name) |
84 s2 = re.sub('([A-Z]+)([A-Z][a-z])', r'\1_\2', s1) | 87 s2 = re.sub('([A-Z]+)([A-Z][a-z])', r'\1_\2', s1) |
85 return s2.replace('.', '_').lower() | 88 return s2.replace('.', '_').lower() |
86 | 89 |
87 def _GetDestinations(api_name, api_dir): | 90 def _GetDestinations(api_name, api_dir): |
88 if api_name in EXTENSIONS_ONLY: | 91 if api_name in EXTENSIONS_ONLY: |
89 return ['extensions'] | 92 return ['extensions'] |
90 if api_name.startswith('app'): | 93 if api_name.count('app') > 0: |
91 return ['apps'] | 94 return ['apps'] |
92 with open(os.path.join(api_dir, '_permission_features.json')) as f: | 95 with open(os.path.join(api_dir, '_permission_features.json')) as f: |
93 permissions = json.loads(json_comment_eater.Nom(f.read())) | 96 permissions = json.loads(json_comment_eater.Nom(f.read())) |
94 permissions_key = api_name.replace('experimental_', '').replace('_', '.') | 97 permissions_key = api_name.replace('experimental_', '').replace('_', '.') |
95 if permissions_key in permissions: | 98 if permissions_key in permissions: |
96 return_list = [] | 99 return_list = [] |
97 types = permissions[permissions_key]['extension_types'] | 100 types = permissions[permissions_key]['extension_types'] |
98 if 'platform_app' in types: | 101 if 'platform_app' in types: |
99 return_list.append('apps') | 102 return_list.append('apps') |
100 if 'extension' in types: | 103 if 'extension' in types: |
101 return_list.append('extensions') | 104 return_list.append('extensions') |
102 return return_list | 105 return return_list |
103 return ['extensions', 'apps'] | 106 return ['extensions', 'apps'] |
104 | 107 |
105 def _ListAllAPIs(dirname): | 108 def _ListAllAPIs(dirname): |
106 all_files = [] | 109 all_files = [] |
107 for path, dirs, files in os.walk(dirname): | 110 for path, dirs, files in os.walk(dirname): |
108 if path == '.': | 111 if path == '.': |
109 all_files.extend([f for f in files | 112 all_files.extend([f for f in files |
110 if f.endswith('.json') or f.endswith('.idl')]) | 113 if f.endswith('.json') or f.endswith('.idl')]) |
111 else: | 114 else: |
112 all_files.extend([os.path.join(path, f) for f in files | 115 all_files.extend([os.path.join(path, f) for f in files |
113 if f.endswith('.json') or f.endswith('.idl')]) | 116 if f.endswith('.json') or f.endswith('.idl')]) |
114 dirname = dirname.rstrip('/') + '/' | 117 dirname = dirname.rstrip('/') + '/' |
115 return [f[len(dirname):] for f in all_files | 118 return [f[len(dirname):] for f in all_files |
116 if os.path.splitext(f)[0].split('_')[-1] not in ['private', | 119 if os.path.splitext(f)[0].split('_')[-1] not in ['private', |
117 'internal']] | 120 'internal']] |
118 | 121 |
119 def _MakeArticleTemplate(filename, path): | 122 def _MakeArticleTemplate(filename, path): |
120 return ('{{+partials.standard_%s_article article:intros.%s}}' % | 123 return ('{{+partials.standard_%s_article article:intros.%s}}\n' % |
121 (path, filename)) | 124 (path, filename)) |
122 | 125 |
123 def _MakeAPITemplate(intro_name, path, api_name, has_intro): | 126 def _MakeAPITemplate(intro_name, path, api_name, has_intro): |
124 if has_intro: | 127 if has_intro: |
125 return ('{{+partials.standard_%s_api api:apis.%s intro:intros.%s}}' % | 128 return ('{{+partials.standard_%s_api api:apis.%s intro:intros.%s}}\n' % |
126 (path, api_name, intro_name)) | 129 (path, api_name, intro_name)) |
127 else: | 130 else: |
128 return ('{{+partials.standard_%s_api api:apis.%s}}' % | 131 return ('{{+partials.standard_%s_api api:apis.%s}}\n' % |
129 (path, api_name)) | 132 (path, api_name)) |
130 | 133 |
131 def _GetAPIPath(name, api_dir): | 134 def _GetAPIPath(name, api_dir): |
132 api_files = _ListAllAPIs(api_dir) | 135 api_files = _ListAllAPIs(api_dir) |
133 for filename in api_files: | 136 for filename in api_files: |
134 if name == _UnixName(SanitizeAPIName(filename)): | 137 if name == _UnixName(SanitizeAPIName(filename)): |
135 return _UnixName(filename) | 138 return _UnixName(filename) |
136 | 139 |
137 def _CleanAPIs(source_dir, api_dir, intros_dest, template_dest, exclude): | 140 def _CleanAPIs(source_dir, api_dir, intros_dest, template_dest, exclude): |
138 source_files = os.listdir(source_dir) | 141 source_files = os.listdir(source_dir) |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 if (not opts.file and len(args) != 6) or (opts.file and len(args) != 7): | 357 if (not opts.file and len(args) != 6) or (opts.file and len(args) != 7): |
355 parser.error('incorrect number of arguments.') | 358 parser.error('incorrect number of arguments.') |
356 | 359 |
357 if opts.file: | 360 if opts.file: |
358 _MoveSingleFile(*args, replace=opts.replace, svn=opts.svn) | 361 _MoveSingleFile(*args, replace=opts.replace, svn=opts.svn) |
359 else: | 362 else: |
360 _MoveAllFiles(*args, | 363 _MoveAllFiles(*args, |
361 replace=opts.replace, | 364 replace=opts.replace, |
362 exclude_dir=opts.exclude, | 365 exclude_dir=opts.exclude, |
363 svn=opts.svn) | 366 svn=opts.svn) |
OLD | NEW |