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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 class EnumItem: | 49 class EnumItem: |
50 def __init__(self, item): | 50 def __init__(self, item): |
51 self.caption = PolicyDetails._RemovePlaceholders(item['caption']) | 51 self.caption = PolicyDetails._RemovePlaceholders(item['caption']) |
52 self.value = item['value'] | 52 self.value = item['value'] |
53 | 53 |
54 def __init__(self, policy, os, is_chromium_os): | 54 def __init__(self, policy, os, is_chromium_os): |
55 self.id = policy['id'] | 55 self.id = policy['id'] |
56 self.name = policy['name'] | 56 self.name = policy['name'] |
| 57 features = policy.get('features', {}) |
| 58 self.can_be_recommended = features.get('can_be_recommended', False) |
| 59 self.can_be_mandatory = features.get('can_be_mandatory', True) |
57 self.is_deprecated = policy.get('deprecated', False) | 60 self.is_deprecated = policy.get('deprecated', False) |
58 self.is_device_only = policy.get('device_only', False) | 61 self.is_device_only = policy.get('device_only', False) |
59 self.schema = policy.get('schema', {}) | 62 self.schema = policy.get('schema', {}) |
60 self.has_enterprise_default = 'default_for_enterprise_users' in policy | 63 self.has_enterprise_default = 'default_for_enterprise_users' in policy |
61 if self.has_enterprise_default: | 64 if self.has_enterprise_default: |
62 self.enterprise_default = policy['default_for_enterprise_users'] | 65 self.enterprise_default = policy['default_for_enterprise_users'] |
63 | 66 |
64 expected_platform = 'chrome_os' if is_chromium_os else os.lower() | 67 expected_platform = 'chrome_os' if is_chromium_os else os.lower() |
65 self.platforms = [] | 68 self.platforms = [] |
66 for platform, version in [ p.split(':') for p in policy['supported_on'] ]: | 69 for platform, version in [ p.split(':') for p in policy['supported_on'] ]: |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 _OutputComment(f, policy.caption + '\n\n' + policy.desc) | 781 _OutputComment(f, policy.caption + '\n\n' + policy.desc) |
779 if policy.items is not None: | 782 if policy.items is not None: |
780 _OutputComment(f, '\nValid values:') | 783 _OutputComment(f, '\nValid values:') |
781 for item in policy.items: | 784 for item in policy.items: |
782 _OutputComment(f, ' %s: %s' % (str(item.value), item.caption)) | 785 _OutputComment(f, ' %s: %s' % (str(item.value), item.caption)) |
783 if policy.policy_type == 'TYPE_DICTIONARY': | 786 if policy.policy_type == 'TYPE_DICTIONARY': |
784 _OutputComment(f, '\nValue schema:\n%s' % | 787 _OutputComment(f, '\nValue schema:\n%s' % |
785 json.dumps(policy.schema, sort_keys=True, indent=4, | 788 json.dumps(policy.schema, sort_keys=True, indent=4, |
786 separators=(',', ': '))) | 789 separators=(',', ': '))) |
787 _OutputComment(f, '\nSupported on: %s' % ', '.join(policy.platforms)) | 790 _OutputComment(f, '\nSupported on: %s' % ', '.join(policy.platforms)) |
| 791 if policy.can_be_recommended and not policy.can_be_mandatory: |
| 792 _OutputComment(f, '\nNote: this policy must have a RECOMMENDED ' +\ |
| 793 'PolicyMode set in PolicyOptions.') |
788 f.write('message %sProto {\n' % policy.name) | 794 f.write('message %sProto {\n' % policy.name) |
789 f.write(' optional PolicyOptions policy_options = 1;\n') | 795 f.write(' optional PolicyOptions policy_options = 1;\n') |
790 f.write(' optional %s %s = 2;\n' % (policy.protobuf_type, policy.name)) | 796 f.write(' optional %s %s = 2;\n' % (policy.protobuf_type, policy.name)) |
791 f.write('}\n\n') | 797 f.write('}\n\n') |
792 fields += [ ' optional %sProto %s = %s;\n' % | 798 fields += [ ' optional %sProto %s = %s;\n' % |
793 (policy.name, policy.name, policy.id + RESERVED_IDS) ] | 799 (policy.name, policy.name, policy.id + RESERVED_IDS) ] |
794 | 800 |
795 | 801 |
796 def _WriteChromeSettingsProtobuf(policies, os, f): | 802 def _WriteChromeSettingsProtobuf(policies, os, f): |
797 f.write(CHROME_SETTINGS_PROTO_HEAD) | 803 f.write(CHROME_SETTINGS_PROTO_HEAD) |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 def _WriteCloudPolicyDecoder(policies, os, f): | 963 def _WriteCloudPolicyDecoder(policies, os, f): |
958 f.write(CPP_HEAD) | 964 f.write(CPP_HEAD) |
959 for policy in policies: | 965 for policy in policies: |
960 if policy.is_supported and not policy.is_device_only: | 966 if policy.is_supported and not policy.is_device_only: |
961 _WritePolicyCode(f, policy) | 967 _WritePolicyCode(f, policy) |
962 f.write(CPP_FOOT) | 968 f.write(CPP_FOOT) |
963 | 969 |
964 | 970 |
965 if __name__ == '__main__': | 971 if __name__ == '__main__': |
966 sys.exit(main()) | 972 sys.exit(main()) |
OLD | NEW |