def _CheckPolicyTemplatesSyntax(input_api, output_api): local_path = input_api.PresubmitLocalPath() filepath = input_api.os_path.join(local_path, 'policy_templates.json') if any(f.AbsoluteLocalPath() == filepath for f in input_api.AffectedFiles()): old_sys_path = sys.path try: tools_path = input_api.os_path.normpath( input_api.os_path.join(local_path, input_api.os_path.pardir, 'tools')) sys.path = [tools_path] + sys.path # Optimization: only load this when it's needed. import syntax_check_policy_template_json device_policy_proto_path = input_api.os_path.join( local_path, '../proto/chrome_device_policy.proto') args = ["--device_policy_proto_path=" + device_policy_proto_path] checker = syntax_check_policy_template_json.PolicyTemplateChecker() if checker.Run(args, filepath) > 0: return [ output_api.PresubmitError('Syntax error(s) in file:', [filepath]) ] finally: sys.path = old_sys_path return []
def _CheckPolicyTemplatesSyntax(input_api, output_api): filepath = input_api.os_path.join(input_api.PresubmitLocalPath(), 'policy_templates.json') if any(f.AbsoluteLocalPath() == filepath for f in input_api.AffectedFiles()): import sys old_sys_path = sys.path try: sys.path = [input_api.PresubmitLocalPath()] + sys.path # Optimization: only load this when it's needed. import syntax_check_policy_template_json checker = syntax_check_policy_template_json.PolicyTemplateChecker() if checker.Run([], filepath) > 0: return [output_api.PresubmitError('Syntax error(s) in file:', [filepath])] finally: sys.path = old_sys_path return []
def _CheckPolicyTemplatesSyntax(input_api, output_api): local_path = input_api.PresubmitLocalPath() filepath = input_api.os_path.join(input_api.change.RepositoryRoot() + \ '/components/policy/resources/policy_templates.json') try: template_affected_file = next(iter(f \ for f in input_api.change.AffectedFiles() \ if f.AbsoluteLocalPath() == filepath)) except: template_affected_file = None old_sys_path = sys.path try: tools_path = input_api.os_path.normpath( input_api.os_path.join(local_path, input_api.os_path.pardir, 'tools')) sys.path = [tools_path] + sys.path # Optimization: only load this when it's needed. import syntax_check_policy_template_json device_policy_proto_path = input_api.os_path.join( local_path, '../proto/chrome_device_policy.proto') args = ["--device_policy_proto_path=" + device_policy_proto_path] root = input_api.change.RepositoryRoot() current_version = None original_file_contents = None # Check if there is a tag that allows us to bypass compatibility checks. # This can be used in situations where there is a bug in the validation # code or if a policy change needs to urgently be submitted. if not input_api.change.tags.get('BYPASS_POLICY_COMPATIBILITY_CHECK'): # Get the current version from the VERSION file so that we can check # which policies are un-released and thus can be changed at will. try: version_path = input_api.os_path.join(root, 'chrome', 'VERSION') with open(version_path, "rb") as f: current_version = int(f.readline().split("=")[1]) print('Checking policies against current version: ' + current_version) except: pass # Get the original file contents of the policy file so that we can check # the compatibility of template changes in it if template_affected_file is not None: original_file_contents = '\n'.join( template_affected_file.OldContents()) checker = syntax_check_policy_template_json.PolicyTemplateChecker() if checker.Run(args, filepath, original_file_contents, current_version) > 0: return [ output_api.PresubmitError('Syntax error(s) in file:', [filepath]) ] finally: sys.path = old_sys_path return []