def validate_file_path(path, channel): """Run the validator against a file at the given path, and return the results, which should be a json string. Should only be called directly by `validate_upload` or `validate_file` tasks. Search plugins don't call the linter but get linted by `annotate_search_plugin_validation`. All legacy extensions (including dictionaries, themes etc) are unsupported. """ if path.endswith('.xml'): # search plugins are validated directly by addons-server # so that we don't have to call the linter or validator results = deepcopy(amo.VALIDATOR_SKELETON_RESULTS) annotations.annotate_search_plugin_restriction(results=results, file_path=path, channel=channel) return json.dumps(results) # Annotate results with potential legacy add-ons restrictions. try: parse_addon(path, minimal=True) except NoManifestFound: # If no manifest is found the linter will pick it up and # will know what message to return to the developer. pass except InvalidManifest: # Similarly, if we can't parse the manifest, let the linter pick that # up. pass log.info('Running linter on %s', path) return run_addons_linter(path, channel=channel)
def validate_file_path(path, channel): """Run the validator against a file at the given path, and return the results, which should be a json string. Should only be called directly by `validate_upload` or `validate_file` tasks. Search plugins don't call the linter but get linted by `annotate_search_plugin_validation`. All legacy extensions (including dictionaries, themes etc) are disabled via `annotate_legacy_addon_restrictions` except if they're signed by Mozilla. """ if path.endswith('.xml'): # search plugins are validated directly by addons-server # so that we don't have to call the linter or validator results = deepcopy(amo.VALIDATOR_SKELETON_RESULTS) annotations.annotate_search_plugin_restriction(results=results, file_path=path, channel=channel) return json.dumps(results) # Annotate results with potential legacy add-ons restrictions. try: data = parse_addon(path, minimal=True) except NoManifestFound: # If no manifest is found, return empty data; the check below # explicitly looks for is_webextension is False, so it will not be # considered a legacy extension, and the linter will pick it up and # will know what message to return to the developer. data = {} except InvalidManifest: # Similarly, if we can't parse the manifest, let the linter pick that # up. data = {} is_legacy_extension = data.get('is_webextension', None) is False is_mozilla_signed = data.get('is_mozilla_signed_extension', None) is True if is_legacy_extension: results = deepcopy(amo.VALIDATOR_SKELETON_RESULTS) annotations.annotate_legacy_addon_restrictions( path=path, results=results, parsed_data=data, error=not is_mozilla_signed) return json.dumps(results) log.info('Running linter on %s', path) return run_addons_linter(path, channel=channel)