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 |
| 11 template is the path to a .json policy template file.''' | 11 template is the path to a .json policy template file.''' |
| 12 | 12 |
| 13 from __future__ import with_statement | 13 from __future__ import with_statement |
| 14 import json | 14 import json |
| 15 from optparse import OptionParser | 15 from optparse import OptionParser |
| 16 import re | 16 import re |
| 17 import sys | 17 import sys |
| 18 import textwrap | 18 import textwrap |
| 19 import json | |
|
Joao da Silva
2013/09/11 11:43:37
alread in line 14
| |
| 19 | 20 |
| 20 | 21 |
| 21 CHROME_POLICY_KEY = 'SOFTWARE\\\\Policies\\\\Google\\\\Chrome' | 22 CHROME_POLICY_KEY = 'SOFTWARE\\\\Policies\\\\Google\\\\Chrome' |
| 22 CHROMIUM_POLICY_KEY = 'SOFTWARE\\\\Policies\\\\Chromium' | 23 CHROMIUM_POLICY_KEY = 'SOFTWARE\\\\Policies\\\\Chromium' |
| 23 | 24 |
| 24 | 25 |
| 25 class PolicyDetails: | 26 class PolicyDetails: |
| 26 """Parses a policy template and caches all its details.""" | 27 """Parses a policy template and caches all its details.""" |
| 27 | 28 |
| 28 # Maps policy types to a tuple with 3 other types: | 29 # Maps policy types to a tuple with 3 other types: |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 46 class EnumItem: | 47 class EnumItem: |
| 47 def __init__(self, item): | 48 def __init__(self, item): |
| 48 self.caption = PolicyDetails._RemovePlaceholders(item['caption']) | 49 self.caption = PolicyDetails._RemovePlaceholders(item['caption']) |
| 49 self.value = item['value'] | 50 self.value = item['value'] |
| 50 | 51 |
| 51 def __init__(self, policy, os, is_chromium_os): | 52 def __init__(self, policy, os, is_chromium_os): |
| 52 self.id = policy['id'] | 53 self.id = policy['id'] |
| 53 self.name = policy['name'] | 54 self.name = policy['name'] |
| 54 self.is_deprecated = policy.get('deprecated', False) | 55 self.is_deprecated = policy.get('deprecated', False) |
| 55 self.is_device_only = policy.get('device_only', False) | 56 self.is_device_only = policy.get('device_only', False) |
| 57 self.schema = policy.get('schema', {}) | |
| 56 | 58 |
| 57 if is_chromium_os: | 59 if is_chromium_os: |
| 58 expected_platform = 'chrome_os' | 60 expected_platform = 'chrome_os' |
| 59 else: | 61 else: |
| 60 expected_platform = os.lower() | 62 expected_platform = os.lower() |
| 61 | 63 |
| 62 self.platforms = [] | 64 self.platforms = [] |
| 63 for platform, version in [ p.split(':') for p in policy['supported_on'] ]: | 65 for platform, version in [ p.split(':') for p in policy['supported_on'] ]: |
| 64 if not version.endswith('-'): | 66 if not version.endswith('-'): |
| 65 continue | 67 continue |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 '#include "base/basictypes.h"\n' | 218 '#include "base/basictypes.h"\n' |
| 217 '#include "base/values.h"\n' | 219 '#include "base/values.h"\n' |
| 218 '\n' | 220 '\n' |
| 219 'namespace policy {\n\n') | 221 'namespace policy {\n\n') |
| 220 | 222 |
| 221 if os == 'win': | 223 if os == 'win': |
| 222 f.write('// The windows registry path where Chrome policy ' | 224 f.write('// The windows registry path where Chrome policy ' |
| 223 'configuration resides.\n' | 225 'configuration resides.\n' |
| 224 'extern const wchar_t kRegistryChromePolicyKey[];\n') | 226 'extern const wchar_t kRegistryChromePolicyKey[];\n') |
| 225 | 227 |
| 226 f.write('// Lists metadata such as name, expected type and id for all\n' | 228 f.write('// JSON schema for policy.\n' |
| 229 'extern const char kPolicyJsonSchema[];\n' | |
| 230 '\n' | |
| 231 '// Lists metadata such as name, expected type and id for all\n' | |
| 227 '// policies. Used to initialize ConfigurationPolicyProviders and\n' | 232 '// policies. Used to initialize ConfigurationPolicyProviders and\n' |
| 228 '// CloudExternalDataManagers.\n' | 233 '// CloudExternalDataManagers.\n' |
| 229 'struct PolicyDefinitionList {\n' | 234 'struct PolicyDefinitionList {\n' |
| 230 ' struct Entry {\n' | 235 ' struct Entry {\n' |
| 231 ' const char* name;\n' | 236 ' const char* name;\n' |
| 232 ' base::Value::Type value_type;\n' | 237 ' base::Value::Type value_type;\n' |
| 233 ' bool device_policy;\n' | 238 ' bool device_policy;\n' |
| 234 ' int id;\n' | 239 ' int id;\n' |
| 235 ' size_t max_external_data_size;\n' | 240 ' size_t max_external_data_size;\n' |
| 236 ' };\n' | 241 ' };\n' |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 | 306 |
| 302 if os == 'win': | 307 if os == 'win': |
| 303 f.write('#if defined(GOOGLE_CHROME_BUILD)\n' | 308 f.write('#if defined(GOOGLE_CHROME_BUILD)\n' |
| 304 'const wchar_t kRegistryChromePolicyKey[] = ' | 309 'const wchar_t kRegistryChromePolicyKey[] = ' |
| 305 'L"' + CHROME_POLICY_KEY + '";\n' | 310 'L"' + CHROME_POLICY_KEY + '";\n' |
| 306 '#else\n' | 311 '#else\n' |
| 307 'const wchar_t kRegistryChromePolicyKey[] = ' | 312 'const wchar_t kRegistryChromePolicyKey[] = ' |
| 308 'L"' + CHROMIUM_POLICY_KEY + '";\n' | 313 'L"' + CHROMIUM_POLICY_KEY + '";\n' |
| 309 '#endif\n\n') | 314 '#endif\n\n') |
| 310 | 315 |
| 316 # Inline the JSON schema for policy. | |
| 317 schema = {} | |
| 318 schema['$schema'] = 'http://json-schema.org/draft-03/schema#' | |
| 319 schema['type'] = 'object' | |
| 320 schema['properties'] = {} | |
| 321 for policy in policies: | |
| 322 schema['properties'][policy.name] = policy.schema | |
|
Joao da Silva
2013/09/11 11:43:37
make this conditional on policy.is_supported.
| |
| 323 f.write('const char kPolicyJsonSchema[] = %s;\n\n' % | |
| 324 json.dumps(json.dumps(schema))) | |
|
Joao da Silva
2013/09/11 11:59:00
pass separators=(',', ':') to these 2 calls. It wi
| |
| 325 | |
| 311 f.write('bool IsDeprecatedPolicy(const std::string& policy) {\n') | 326 f.write('bool IsDeprecatedPolicy(const std::string& policy) {\n') |
| 312 if has_deprecated_policies: | 327 if has_deprecated_policies: |
| 313 # arraysize() doesn't work with empty arrays. | 328 # arraysize() doesn't work with empty arrays. |
| 314 f.write(' for (size_t i = 0; i < arraysize(kDeprecatedPolicyList);' | 329 f.write(' for (size_t i = 0; i < arraysize(kDeprecatedPolicyList);' |
| 315 ' ++i) {\n' | 330 ' ++i) {\n' |
| 316 ' if (policy == kDeprecatedPolicyList[i])\n' | 331 ' if (policy == kDeprecatedPolicyList[i])\n' |
| 317 ' return true;\n' | 332 ' return true;\n' |
| 318 ' }\n') | 333 ' }\n') |
| 319 f.write(' return false;\n' | 334 f.write(' return false;\n' |
| 320 '}\n\n') | 335 '}\n\n') |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 def _WriteCloudPolicyDecoder(policies, os, f): | 593 def _WriteCloudPolicyDecoder(policies, os, f): |
| 579 f.write(CPP_HEAD) | 594 f.write(CPP_HEAD) |
| 580 for policy in policies: | 595 for policy in policies: |
| 581 if policy.is_supported and not policy.is_device_only: | 596 if policy.is_supported and not policy.is_device_only: |
| 582 _WritePolicyCode(f, policy) | 597 _WritePolicyCode(f, policy) |
| 583 f.write(CPP_FOOT) | 598 f.write(CPP_FOOT) |
| 584 | 599 |
| 585 | 600 |
| 586 if __name__ == '__main__': | 601 if __name__ == '__main__': |
| 587 sys.exit(main()) | 602 sys.exit(main()) |
| OLD | NEW |