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 from collections import namedtuple | 14 from collections import namedtuple |
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 | 19 |
20 | 20 |
21 CHROME_MANDATORY_SUBKEY = 'SOFTWARE\\\\Policies\\\\Google\\\\Chrome' | 21 CHROME_POLICY_KEY = 'SOFTWARE\\\\Policies\\\\Google\\\\Chrome' |
22 CHROME_RECOMMENDED_SUBKEY = CHROME_MANDATORY_SUBKEY + '\\\\Recommended' | 22 CHROMIUM_POLICY_KEY = 'SOFTWARE\\\\Policies\\\\Chromium' |
23 CHROMIUM_MANDATORY_SUBKEY = 'SOFTWARE\\\\Policies\\\\Chromium' | |
24 CHROMIUM_RECOMMENDED_SUBKEY = CHROMIUM_MANDATORY_SUBKEY + '\\\\Recommended' | |
25 | 23 |
26 TYPE_MAP = { | 24 TYPE_MAP = { |
27 'dict': 'TYPE_DICTIONARY', | 25 'dict': 'TYPE_DICTIONARY', |
28 'int': 'TYPE_INTEGER', | 26 'int': 'TYPE_INTEGER', |
29 'int-enum': 'TYPE_INTEGER', | 27 'int-enum': 'TYPE_INTEGER', |
30 'list': 'TYPE_LIST', | 28 'list': 'TYPE_LIST', |
31 'main': 'TYPE_BOOLEAN', | 29 'main': 'TYPE_BOOLEAN', |
32 'string': 'TYPE_STRING', | 30 'string': 'TYPE_STRING', |
33 'string-enum': 'TYPE_STRING', | 31 'string-enum': 'TYPE_STRING', |
34 } | 32 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 f.write('#ifndef CHROME_COMMON_POLICY_CONSTANTS_H_\n' | 168 f.write('#ifndef CHROME_COMMON_POLICY_CONSTANTS_H_\n' |
171 '#define CHROME_COMMON_POLICY_CONSTANTS_H_\n' | 169 '#define CHROME_COMMON_POLICY_CONSTANTS_H_\n' |
172 '\n' | 170 '\n' |
173 '#include <string>\n' | 171 '#include <string>\n' |
174 '\n' | 172 '\n' |
175 '#include "base/values.h"\n' | 173 '#include "base/values.h"\n' |
176 '\n' | 174 '\n' |
177 'namespace policy {\n\n') | 175 'namespace policy {\n\n') |
178 | 176 |
179 if os == 'win': | 177 if os == 'win': |
180 f.write('// The windows registry path where mandatory policy ' | 178 f.write('// The windows registry path where Chrome policy ' |
181 'configuration resides.\n' | 179 'configuration resides.\n' |
182 'extern const wchar_t kRegistryMandatorySubKey[];\n' | 180 'extern const wchar_t kRegistryChromePolicyKey[];\n') |
183 '// The windows registry path where recommended policy ' | |
184 'configuration resides.\n' | |
185 'extern const wchar_t kRegistryRecommendedSubKey[];\n\n') | |
186 | 181 |
187 f.write('// Lists policy types mapped to their names and expected types.\n' | 182 f.write('// Lists policy types mapped to their names and expected types.\n' |
188 '// Used to initialize ConfigurationPolicyProviders.\n' | 183 '// Used to initialize ConfigurationPolicyProviders.\n' |
189 'struct PolicyDefinitionList {\n' | 184 'struct PolicyDefinitionList {\n' |
190 ' struct Entry {\n' | 185 ' struct Entry {\n' |
191 ' const char* name;\n' | 186 ' const char* name;\n' |
192 ' base::Value::Type value_type;\n' | 187 ' base::Value::Type value_type;\n' |
193 ' bool device_policy;\n' | 188 ' bool device_policy;\n' |
194 ' int id;\n' | 189 ' int id;\n' |
195 ' };\n' | 190 ' };\n' |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 'const char* kDeprecatedPolicyList[] = {\n') | 247 'const char* kDeprecatedPolicyList[] = {\n') |
253 for policy in _GetPolicyList(template_file_contents): | 248 for policy in _GetPolicyList(template_file_contents): |
254 if policy.is_deprecated: | 249 if policy.is_deprecated: |
255 f.write(' key::k%s,\n' % policy.name) | 250 f.write(' key::k%s,\n' % policy.name) |
256 f.write('};\n\n') | 251 f.write('};\n\n') |
257 | 252 |
258 f.write('} // namespace\n\n') | 253 f.write('} // namespace\n\n') |
259 | 254 |
260 if os == 'win': | 255 if os == 'win': |
261 f.write('#if defined(GOOGLE_CHROME_BUILD)\n' | 256 f.write('#if defined(GOOGLE_CHROME_BUILD)\n' |
262 'const wchar_t kRegistryMandatorySubKey[] = ' | 257 'const wchar_t kRegistryChromePolicyKey[] = ' |
263 'L"' + CHROME_MANDATORY_SUBKEY + '";\n' | 258 'L"' + CHROME_POLICY_KEY + '";\n' |
264 'const wchar_t kRegistryRecommendedSubKey[] = ' | |
265 'L"' + CHROME_RECOMMENDED_SUBKEY + '";\n' | |
266 '#else\n' | 259 '#else\n' |
267 'const wchar_t kRegistryMandatorySubKey[] = ' | 260 'const wchar_t kRegistryChromePolicyKey[] = ' |
268 'L"' + CHROMIUM_MANDATORY_SUBKEY + '";\n' | 261 'L"' + CHROMIUM_POLICY_KEY + '";\n' |
269 'const wchar_t kRegistryRecommendedSubKey[] = ' | |
270 'L"' + CHROMIUM_RECOMMENDED_SUBKEY + '";\n' | |
271 '#endif\n\n') | 262 '#endif\n\n') |
272 | 263 |
273 f.write('bool IsDeprecatedPolicy(const std::string& policy) {\n' | 264 f.write('bool IsDeprecatedPolicy(const std::string& policy) {\n' |
274 ' for (size_t i = 0; i < arraysize(kDeprecatedPolicyList);' | 265 ' for (size_t i = 0; i < arraysize(kDeprecatedPolicyList);' |
275 ' ++i) {\n' | 266 ' ++i) {\n' |
276 ' if (policy == kDeprecatedPolicyList[i])\n' | 267 ' if (policy == kDeprecatedPolicyList[i])\n' |
277 ' return true;\n' | 268 ' return true;\n' |
278 ' }\n' | 269 ' }\n' |
279 ' return false;\n' | 270 ' return false;\n' |
280 '}\n' | 271 '}\n' |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 with open(outfilepath, 'w') as f: | 518 with open(outfilepath, 'w') as f: |
528 _OutputGeneratedWarningForC(f, args[2]) | 519 _OutputGeneratedWarningForC(f, args[2]) |
529 f.write(CPP_HEAD) | 520 f.write(CPP_HEAD) |
530 for policy in _Flatten(template_file_contents): | 521 for policy in _Flatten(template_file_contents): |
531 _WritePolicyCode(f, policy) | 522 _WritePolicyCode(f, policy) |
532 f.write(CPP_FOOT) | 523 f.write(CPP_FOOT) |
533 | 524 |
534 | 525 |
535 if __name__ == '__main__': | 526 if __name__ == '__main__': |
536 sys.exit(main()) | 527 sys.exit(main()) |
OLD | NEW |