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

Side by Side Diff: components/policy/tools/generate_policy_source.py

Issue 929353002: Fix generate_policy_source.py to honour supported_on ranges. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add some error handling for malformatted supported_on version ranges. Created 5 years, 10 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
« components/policy/BUILD.gn ('K') | « components/policy/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '''python %prog [options] platform chromium_os_flag template 6 '''python %prog [options] platform chromium_os_flag template
7 7
8 platform specifies which platform source is being generated for 8 platform specifies which platform source is being generated for
9 and can be one of (win, mac, linux) 9 and can be one of (win, mac, linux)
10 chromium_os_flag should be 1 if this is a Chromium OS build 10 chromium_os_flag should be 1 if this is a Chromium OS build
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 'choice', True), 56 'choice', True),
57 'string-enum-list': ('TYPE_LIST', 'StringList', 'StringList', 57 'string-enum-list': ('TYPE_LIST', 'StringList', 'StringList',
58 'multi-select', True), 58 'multi-select', True),
59 } 59 }
60 60
61 class EnumItem: 61 class EnumItem:
62 def __init__(self, item): 62 def __init__(self, item):
63 self.caption = PolicyDetails._RemovePlaceholders(item['caption']) 63 self.caption = PolicyDetails._RemovePlaceholders(item['caption'])
64 self.value = item['value'] 64 self.value = item['value']
65 65
66 def __init__(self, policy, os, is_chromium_os): 66 def __init__(self, policy, version, os, is_chromium_os):
67 self.id = policy['id'] 67 self.id = policy['id']
68 self.name = policy['name'] 68 self.name = policy['name']
69 features = policy.get('features', {}) 69 features = policy.get('features', {})
70 self.can_be_recommended = features.get('can_be_recommended', False) 70 self.can_be_recommended = features.get('can_be_recommended', False)
71 self.can_be_mandatory = features.get('can_be_mandatory', True) 71 self.can_be_mandatory = features.get('can_be_mandatory', True)
72 self.is_deprecated = policy.get('deprecated', False) 72 self.is_deprecated = policy.get('deprecated', False)
73 self.is_device_only = policy.get('device_only', False) 73 self.is_device_only = policy.get('device_only', False)
74 self.schema = policy.get('schema', {}) 74 self.schema = policy.get('schema', {})
75 self.has_enterprise_default = 'default_for_enterprise_users' in policy 75 self.has_enterprise_default = 'default_for_enterprise_users' in policy
76 if self.has_enterprise_default: 76 if self.has_enterprise_default:
77 self.enterprise_default = policy['default_for_enterprise_users'] 77 self.enterprise_default = policy['default_for_enterprise_users']
78 78
79 major_version = int(version.split('.')[0])
79 expected_platform = 'chrome_os' if is_chromium_os else os.lower() 80 expected_platform = 'chrome_os' if is_chromium_os else os.lower()
80 self.platforms = [] 81 self.platforms = []
81 for platform, version in [ p.split(':') for p in policy['supported_on'] ]: 82 for platform, version_range in [ p.split(':')
82 if not version.endswith('-'): 83 for p in policy['supported_on'] ]:
84 split_result = version_range.split('-')
85 if len(split_result) != 2:
86 raise RuntimeError('supported_on must have exactly one dash: "%s"' % p)
87 (version_min, version_max) = split_result
88 if version_min == '':
89 raise RuntimeError('supported_on must define a start version: "%s"' % p)
90
91 # Skip if the current Chromium version does not support the policy.
92 if (int(version_min) > major_version or
93 version_max != '' and int(version_max) < major_version):
83 continue 94 continue
84 95
85 if platform.startswith('chrome.'): 96 if platform.startswith('chrome.'):
86 platform_sub = platform[7:] 97 platform_sub = platform[7:]
87 if platform_sub == '*': 98 if platform_sub == '*':
88 self.platforms.extend(['win', 'mac', 'linux']) 99 self.platforms.extend(['win', 'mac', 'linux'])
89 else: 100 else:
90 self.platforms.append(platform_sub) 101 self.platforms.append(platform_sub)
91 else: 102 else:
92 self.platforms.append(platform) 103 self.platforms.append(platform)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 metavar='FILE') 167 metavar='FILE')
157 parser.add_option('--arr', '--app-restrictions-resources', 168 parser.add_option('--arr', '--app-restrictions-resources',
158 dest='app_resources_path', 169 dest='app_resources_path',
159 help='generate an XML file with resources supporting the ' 170 help='generate an XML file with resources supporting the '
160 'restrictions defined in --app-restrictions-definition ' 171 'restrictions defined in --app-restrictions-definition '
161 'parameter', 172 'parameter',
162 metavar='FILE') 173 metavar='FILE')
163 174
164 (opts, args) = parser.parse_args() 175 (opts, args) = parser.parse_args()
165 176
166 if len(args) != 3: 177 if len(args) != 4:
167 print 'exactly platform, chromium_os flag and input file must be specified.' 178 print('Exactly version string, platform, chromium_os flag and '
179 'input file must be specified as free parameters.')
168 parser.print_help() 180 parser.print_help()
169 return 2 181 return 2
170 182
171 os = args[0] 183 version = args[0]
172 is_chromium_os = args[1] == '1' 184 os = args[1]
173 template_file_name = args[2] 185 is_chromium_os = args[2] == '1'
186 template_file_name = args[3]
174 187
175 template_file_contents = _LoadJSONFile(template_file_name) 188 template_file_contents = _LoadJSONFile(template_file_name)
176 policy_details = [ PolicyDetails(policy, os, is_chromium_os) 189 policy_details = [ PolicyDetails(policy, version, os, is_chromium_os)
177 for policy in _Flatten(template_file_contents) ] 190 for policy in _Flatten(template_file_contents) ]
178 sorted_policy_details = sorted(policy_details, key=lambda policy: policy.name) 191 sorted_policy_details = sorted(policy_details, key=lambda policy: policy.name)
179 192
180 def GenerateFile(path, writer, sorted=False, xml=False): 193 def GenerateFile(path, writer, sorted=False, xml=False):
181 if path: 194 if path:
182 with open(path, 'w') as f: 195 with open(path, 'w') as f:
183 _OutputGeneratedWarningHeader(f, template_file_name, xml) 196 _OutputGeneratedWarningHeader(f, template_file_name, xml)
184 writer(sorted and sorted_policy_details or policy_details, os, f) 197 writer(sorted and sorted_policy_details or policy_details, os, f)
185 198
186 GenerateFile(opts.header_path, _WritePolicyConstantHeader, sorted=True) 199 GenerateFile(opts.header_path, _WritePolicyConstantHeader, sorted=True)
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 # _WriteResourcesForPolicies body 1092 # _WriteResourcesForPolicies body
1080 f.write('<resources>\n\n') 1093 f.write('<resources>\n\n')
1081 for policy in policies: 1094 for policy in policies:
1082 if policy.is_supported and policy.restriction_type != 'invalid': 1095 if policy.is_supported and policy.restriction_type != 'invalid':
1083 WriteResourceForPolicy(policy) 1096 WriteResourceForPolicy(policy)
1084 f.write('</resources>') 1097 f.write('</resources>')
1085 1098
1086 1099
1087 if __name__ == '__main__': 1100 if __name__ == '__main__':
1088 sys.exit(main()) 1101 sys.exit(main())
OLDNEW
« components/policy/BUILD.gn ('K') | « components/policy/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698