| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/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 """Class for parsing metadata about extension samples.""" | 6 """Class for parsing metadata about extension samples.""" |
| 7 | 7 |
| 8 import locale | 8 import locale |
| 9 import os | 9 import os |
| 10 import os.path | 10 import os.path |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 methods to parse, and what kind of documentation URL to generate. | 100 methods to parse, and what kind of documentation URL to generate. |
| 101 | 101 |
| 102 Returns: | 102 Returns: |
| 103 A dict of extension methods mapped to file and hash URL parts for the | 103 A dict of extension methods mapped to file and hash URL parts for the |
| 104 corresponding documentation links, like: | 104 corresponding documentation links, like: |
| 105 { | 105 { |
| 106 "chrome.tabs.remove": "tabs.html#method-remove", | 106 "chrome.tabs.remove": "tabs.html#method-remove", |
| 107 "chrome.tabs.onDetached" : "tabs.html#event-onDetatched" | 107 "chrome.tabs.onDetached" : "tabs.html#event-onDetatched" |
| 108 } | 108 } |
| 109 | 109 |
| 110 If the API namespace is defined "nodoc" then an empty dict is returned. | 110 If the API namespace is defined "nodoc" or "internal" then an empty dict |
| 111 is returned. |
| 111 | 112 |
| 112 Raises: | 113 Raises: |
| 113 Exception: If the key supplied is not a member of _MODULE_DOC_KEYS. | 114 Exception: If the key supplied is not a member of _MODULE_DOC_KEYS. |
| 114 """ | 115 """ |
| 115 methods = [] | 116 methods = [] |
| 116 api_dict = {} | 117 api_dict = {} |
| 117 namespace = module['namespace'] | 118 namespace = module['namespace'] |
| 118 if module.has_key('nodoc'): | 119 if self._disableDocs(module): |
| 119 return api_dict | 120 return api_dict |
| 120 if key not in self._MODULE_DOC_KEYS: | 121 if key not in self._MODULE_DOC_KEYS: |
| 121 raise Exception("key %s must be one of %s" % (key, self._MODULE_DOC_KEYS)) | 122 raise Exception("key %s must be one of %s" % (key, self._MODULE_DOC_KEYS)) |
| 122 if module.has_key(key): | 123 if module.has_key(key): |
| 123 methods.extend(module[key]) | 124 methods.extend(module[key]) |
| 124 for method in methods: | 125 for method in methods: |
| 125 if method.has_key('nodoc'): | 126 if self._disableDocs(method): |
| 126 continue | 127 continue |
| 127 method_name = 'chrome.%s.%s' % (namespace, method['name']) | 128 method_name = 'chrome.%s.%s' % (namespace, method['name']) |
| 128 hashprefix = 'method' | 129 hashprefix = 'method' |
| 129 if key == 'events': | 130 if key == 'events': |
| 130 hashprefix = 'event' | 131 hashprefix = 'event' |
| 131 api_dict[method_name] = self._getDocLink(method_name, hashprefix) | 132 api_dict[method_name] = self._getDocLink(method_name, hashprefix) |
| 132 return api_dict | 133 return api_dict |
| 133 | 134 |
| 134 def getModuleNames(self): | 135 def getModuleNames(self): |
| 135 """ Returns the names of individual modules in the API. | 136 """ Returns the names of individual modules in the API. |
| 136 | 137 |
| 137 Returns: | 138 Returns: |
| 138 The namespace """ | 139 The namespace """ |
| 139 # Exclude modules with a "nodoc" property. | 140 # Exclude modules with documentation disabled. |
| 140 return set(module['namespace'].encode() for module in self._manifest | 141 return set(module['namespace'].encode() for module in self._manifest |
| 141 if "nodoc" not in module) | 142 if not self._disableDocs(module)) |
| 143 |
| 144 def _disableDocs(self, obj): |
| 145 for key in ['nodoc', 'internal']: |
| 146 if key in obj and obj[key]: |
| 147 return True |
| 148 return False |
| 142 | 149 |
| 143 def getDocumentationLinks(self): | 150 def getDocumentationLinks(self): |
| 144 """ Parses the extension API JSON manifest and returns a dict of all | 151 """ Parses the extension API JSON manifest and returns a dict of all |
| 145 events and methods for every module, mapped to relative documentation links. | 152 events and methods for every module, mapped to relative documentation links. |
| 146 | 153 |
| 147 Returns: | 154 Returns: |
| 148 A dict of methods/events => partial doc links for every module. | 155 A dict of methods/events => partial doc links for every module. |
| 149 """ | 156 """ |
| 150 api_dict = {} | 157 api_dict = {} |
| 151 for module in self._manifest: | 158 for module in self._manifest: |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 zip_file.write(abspath, relpath) | 727 zip_file.write(abspath, relpath) |
| 721 if file == 'manifest.json': | 728 if file == 'manifest.json': |
| 722 info = zip_file.getinfo(zip_manifest_path) | 729 info = zip_file.getinfo(zip_manifest_path) |
| 723 info.comment = self['source_hash'] | 730 info.comment = self['source_hash'] |
| 724 except RuntimeError, msg: | 731 except RuntimeError, msg: |
| 725 raise Exception("Could not write zip at %s: %s" % (zip_path, msg)) | 732 raise Exception("Could not write zip at %s: %s" % (zip_path, msg)) |
| 726 finally: | 733 finally: |
| 727 zip_file.close() | 734 zip_file.close() |
| 728 | 735 |
| 729 return self._get_relative_zip_path() | 736 return self._get_relative_zip_path() |
| OLD | NEW |