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

Unified 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 side-by-side diff with in-line comments
Download patch
« components/policy/BUILD.gn ('K') | « components/policy/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/policy/tools/generate_policy_source.py
diff --git a/components/policy/tools/generate_policy_source.py b/components/policy/tools/generate_policy_source.py
index e343e33785d4824bcc99b0afda691c0873a8b4cc..8b8bac97452499dec984bb5957d1561a2e93d16d 100755
--- a/components/policy/tools/generate_policy_source.py
+++ b/components/policy/tools/generate_policy_source.py
@@ -63,7 +63,7 @@ class PolicyDetails:
self.caption = PolicyDetails._RemovePlaceholders(item['caption'])
self.value = item['value']
- def __init__(self, policy, os, is_chromium_os):
+ def __init__(self, policy, version, os, is_chromium_os):
self.id = policy['id']
self.name = policy['name']
features = policy.get('features', {})
@@ -76,10 +76,21 @@ class PolicyDetails:
if self.has_enterprise_default:
self.enterprise_default = policy['default_for_enterprise_users']
+ major_version = int(version.split('.')[0])
expected_platform = 'chrome_os' if is_chromium_os else os.lower()
self.platforms = []
- for platform, version in [ p.split(':') for p in policy['supported_on'] ]:
- if not version.endswith('-'):
+ for platform, version_range in [ p.split(':')
+ for p in policy['supported_on'] ]:
+ split_result = version_range.split('-')
+ if len(split_result) != 2:
+ raise RuntimeError('supported_on must have exactly one dash: "%s"' % p)
+ (version_min, version_max) = split_result
+ if version_min == '':
+ raise RuntimeError('supported_on must define a start version: "%s"' % p)
+
+ # Skip if the current Chromium version does not support the policy.
+ if (int(version_min) > major_version or
+ version_max != '' and int(version_max) < major_version):
continue
if platform.startswith('chrome.'):
@@ -163,17 +174,19 @@ def main():
(opts, args) = parser.parse_args()
- if len(args) != 3:
- print 'exactly platform, chromium_os flag and input file must be specified.'
+ if len(args) != 4:
+ print('Exactly version string, platform, chromium_os flag and '
+ 'input file must be specified as free parameters.')
parser.print_help()
return 2
- os = args[0]
- is_chromium_os = args[1] == '1'
- template_file_name = args[2]
+ version = args[0]
+ os = args[1]
+ is_chromium_os = args[2] == '1'
+ template_file_name = args[3]
template_file_contents = _LoadJSONFile(template_file_name)
- policy_details = [ PolicyDetails(policy, os, is_chromium_os)
+ policy_details = [ PolicyDetails(policy, version, os, is_chromium_os)
for policy in _Flatten(template_file_contents) ]
sorted_policy_details = sorted(policy_details, key=lambda policy: policy.name)
« 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