Chromium Code Reviews| 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 '''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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 'choice'), | 55 'choice'), |
| 56 'string-enum-list': ('TYPE_LIST', 'StringList', 'StringList', | 56 'string-enum-list': ('TYPE_LIST', 'StringList', 'StringList', |
| 57 'multi-select'), | 57 'multi-select'), |
| 58 } | 58 } |
| 59 | 59 |
| 60 class EnumItem: | 60 class EnumItem: |
| 61 def __init__(self, item): | 61 def __init__(self, item): |
| 62 self.caption = PolicyDetails._RemovePlaceholders(item['caption']) | 62 self.caption = PolicyDetails._RemovePlaceholders(item['caption']) |
| 63 self.value = item['value'] | 63 self.value = item['value'] |
| 64 | 64 |
| 65 def __init__(self, policy, os, is_chromium_os): | 65 def __init__(self, policy, version, os, is_chromium_os): |
| 66 self.id = policy['id'] | 66 self.id = policy['id'] |
| 67 self.name = policy['name'] | 67 self.name = policy['name'] |
| 68 features = policy.get('features', {}) | 68 features = policy.get('features', {}) |
| 69 self.can_be_recommended = features.get('can_be_recommended', False) | 69 self.can_be_recommended = features.get('can_be_recommended', False) |
| 70 self.can_be_mandatory = features.get('can_be_mandatory', True) | 70 self.can_be_mandatory = features.get('can_be_mandatory', True) |
| 71 self.is_deprecated = policy.get('deprecated', False) | 71 self.is_deprecated = policy.get('deprecated', False) |
| 72 self.is_device_only = policy.get('device_only', False) | 72 self.is_device_only = policy.get('device_only', False) |
| 73 self.schema = policy.get('schema', {}) | 73 self.schema = policy.get('schema', {}) |
| 74 self.has_enterprise_default = 'default_for_enterprise_users' in policy | 74 self.has_enterprise_default = 'default_for_enterprise_users' in policy |
| 75 if self.has_enterprise_default: | 75 if self.has_enterprise_default: |
| 76 self.enterprise_default = policy['default_for_enterprise_users'] | 76 self.enterprise_default = policy['default_for_enterprise_users'] |
| 77 | 77 |
| 78 major_version = int(version.split('.')[0]) | |
| 78 expected_platform = 'chrome_os' if is_chromium_os else os.lower() | 79 expected_platform = 'chrome_os' if is_chromium_os else os.lower() |
| 79 self.platforms = [] | 80 self.platforms = [] |
| 80 for platform, version in [ p.split(':') for p in policy['supported_on'] ]: | 81 for platform, version_range in [ p.split(':') |
| 81 if not version.endswith('-'): | 82 for p in policy['supported_on'] ]: |
| 83 split_result = version_range.split('-') | |
| 84 if len(split_result) != 2: | |
| 85 raise RuntimeError('supported_on must have exactly one dash: "%s"' % p) | |
| 86 (version_min, version_max) = split_result | |
| 87 if version_min == '': | |
| 88 raise RuntimeError('supported_on must define a start version: "%s"' % p) | |
| 89 | |
| 90 # Skip if the current Chromium version does not support the policy. | |
| 91 if (int(version_min) > major_version or | |
| 92 version_max != '' and int(version_max) < major_version): | |
| 82 continue | 93 continue |
| 83 | 94 |
| 84 if platform.startswith('chrome.'): | 95 if platform.startswith('chrome.'): |
| 85 platform_sub = platform[7:] | 96 platform_sub = platform[7:] |
| 86 if platform_sub == '*': | 97 if platform_sub == '*': |
| 87 self.platforms.extend(['win', 'mac', 'linux']) | 98 self.platforms.extend(['win', 'mac', 'linux']) |
| 88 else: | 99 else: |
| 89 self.platforms.append(platform_sub) | 100 self.platforms.append(platform_sub) |
| 90 else: | 101 else: |
| 91 self.platforms.append(platform) | 102 self.platforms.append(platform) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 help='generate C++ code decoding the cloud policy protobuf', | 159 help='generate C++ code decoding the cloud policy protobuf', |
| 149 metavar='FILE') | 160 metavar='FILE') |
| 150 parser.add_option('--ard', '--app-restrictions-definition', | 161 parser.add_option('--ard', '--app-restrictions-definition', |
| 151 dest='app_restrictions_path', | 162 dest='app_restrictions_path', |
| 152 help='generate an XML file as specified by ' | 163 help='generate an XML file as specified by ' |
| 153 'Android\'s App Restriction Schema', | 164 'Android\'s App Restriction Schema', |
| 154 metavar='FILE') | 165 metavar='FILE') |
| 155 | 166 |
| 156 (opts, args) = parser.parse_args() | 167 (opts, args) = parser.parse_args() |
| 157 | 168 |
| 158 if len(args) != 3: | 169 if len(args) != 4: |
| 159 print 'exactly platform, chromium_os flag and input file must be specified.' | 170 print('Exactly VERSION path, platform, chromium_os flag and ' |
|
Mattias Nissler (ping if slow)
2015/04/23 09:01:29
what is a VERSION path?
Thiemo Nagel
2015/04/23 09:58:00
Maybe a VERSION file?
Mattias Nissler (ping if slow)
2015/04/23 10:14:52
How about "src/chrome/VERSION file path" ?
Thiemo Nagel
2015/04/23 10:56:26
How about "path to src/chrome/VERSION"?
| |
| 171 'input file must be specified as free parameters.') | |
|
Mattias Nissler (ping if slow)
2015/04/23 09:01:29
free parameters? as opposed to bound parameters? I
Thiemo Nagel
2015/04/23 09:58:00
The correct term seems to be "positional parameter
| |
| 160 parser.print_help() | 172 parser.print_help() |
| 161 return 2 | 173 return 2 |
| 162 | 174 |
| 163 os = args[0] | 175 version_path = args[0] |
| 164 is_chromium_os = args[1] == '1' | 176 os = args[1] |
| 165 template_file_name = args[2] | 177 is_chromium_os = args[2] == '1' |
| 178 template_file_name = args[3] | |
| 179 | |
| 180 version = None | |
|
Mattias Nissler (ping if slow)
2015/04/23 09:01:29
It looks like this stuff should be broken out into
Thiemo Nagel
2015/04/23 09:58:00
Done.
| |
| 181 for line in open(version_path, 'r').readlines(): | |
| 182 key, val = line.rstrip('\r\n').split('=', 1) | |
| 183 if key == 'MAJOR': | |
| 184 version = val | |
| 185 break | |
| 186 if version == None: | |
|
Mattias Nissler (ping if slow)
2015/04/23 09:01:29
nit: if version is None
Thiemo Nagel
2015/04/23 09:58:00
Done.
| |
| 187 raise RuntimeError('VERSION file does not contain major version.') | |
| 166 | 188 |
| 167 template_file_contents = _LoadJSONFile(template_file_name) | 189 template_file_contents = _LoadJSONFile(template_file_name) |
| 168 policy_details = [ PolicyDetails(policy, os, is_chromium_os) | 190 policy_details = [ PolicyDetails(policy, version, os, is_chromium_os) |
| 169 for policy in _Flatten(template_file_contents) ] | 191 for policy in _Flatten(template_file_contents) ] |
| 170 sorted_policy_details = sorted(policy_details, key=lambda policy: policy.name) | 192 sorted_policy_details = sorted(policy_details, key=lambda policy: policy.name) |
| 171 | 193 |
| 172 def GenerateFile(path, writer, sorted=False, xml=False): | 194 def GenerateFile(path, writer, sorted=False, xml=False): |
| 173 if path: | 195 if path: |
| 174 with open(path, 'w') as f: | 196 with open(path, 'w') as f: |
| 175 _OutputGeneratedWarningHeader(f, template_file_name, xml) | 197 _OutputGeneratedWarningHeader(f, template_file_name, xml) |
| 176 writer(sorted and sorted_policy_details or policy_details, os, f) | 198 writer(sorted and sorted_policy_details or policy_details, os, f) |
| 177 | 199 |
| 178 GenerateFile(opts.header_path, _WritePolicyConstantHeader, sorted=True) | 200 GenerateFile(opts.header_path, _WritePolicyConstantHeader, sorted=True) |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 # _WriteAppRestrictions body | 1045 # _WriteAppRestrictions body |
| 1024 f.write('<restrictions xmlns:android="' | 1046 f.write('<restrictions xmlns:android="' |
| 1025 'http://schemas.android.com/apk/res/android">\n\n') | 1047 'http://schemas.android.com/apk/res/android">\n\n') |
| 1026 for policy in policies: | 1048 for policy in policies: |
| 1027 if policy.is_supported and policy.restriction_type != 'invalid': | 1049 if policy.is_supported and policy.restriction_type != 'invalid': |
| 1028 WriteAppRestriction(policy) | 1050 WriteAppRestriction(policy) |
| 1029 f.write('</restrictions>') | 1051 f.write('</restrictions>') |
| 1030 | 1052 |
| 1031 if __name__ == '__main__': | 1053 if __name__ == '__main__': |
| 1032 sys.exit(main()) | 1054 sys.exit(main()) |
| OLD | NEW |