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..b3a723b72e6da0c8dea5acb2698afd9028d6c1f3 100755 |
--- a/components/policy/tools/generate_policy_source.py |
+++ b/components/policy/tools/generate_policy_source.py |
@@ -28,34 +28,33 @@ CHROMIUM_POLICY_KEY = 'SOFTWARE\\\\Policies\\\\Chromium' |
class PolicyDetails: |
"""Parses a policy template and caches all its details.""" |
- # Maps policy types to a tuple with 5 other types: |
+ # Maps policy types to a tuple with 4 other types: |
# - the equivalent base::Value::Type or 'TYPE_EXTERNAL' if the policy |
# references external data |
# - the equivalent Protobuf field type |
# - the name of one of the protobufs for shared policy types |
# - the equivalent type in Android's App Restriction Schema |
- # - whether the equivalent app restriction type needs supporting resources |
# TODO(joaodasilva): refactor the 'dict' type into a more generic 'json' type |
# that can also be used to represent lists of other JSON objects. |
TYPE_MAP = { |
'dict': ('TYPE_DICTIONARY', 'string', 'String', |
- 'string', False), |
+ 'string'), |
'external': ('TYPE_EXTERNAL', 'string', 'String', |
- 'invalid', False), |
+ 'invalid'), |
'int': ('TYPE_INTEGER', 'int64', 'Integer', |
- 'integer', False), |
+ 'integer'), |
'int-enum': ('TYPE_INTEGER', 'int64', 'Integer', |
- 'choice', True), |
+ 'choice'), |
'list': ('TYPE_LIST', 'StringList', 'StringList', |
- 'string', False), |
+ 'string'), |
'main': ('TYPE_BOOLEAN', 'bool', 'Boolean', |
- 'bool', False), |
+ 'bool'), |
'string': ('TYPE_STRING', 'string', 'String', |
- 'string', False), |
+ 'string'), |
'string-enum': ('TYPE_STRING', 'string', 'String', |
- 'choice', True), |
+ 'choice'), |
'string-enum-list': ('TYPE_LIST', 'StringList', 'StringList', |
- 'multi-select', True), |
+ 'multi-select'), |
} |
class EnumItem: |
@@ -98,8 +97,7 @@ class PolicyDetails: |
raise NotImplementedError('Unknown policy type for %s: %s' % |
(policy['name'], policy['type'])) |
self.policy_type, self.protobuf_type, self.policy_protobuf_type, \ |
- self.restriction_type, self.has_restriction_resources = \ |
- PolicyDetails.TYPE_MAP[policy['type']] |
+ self.restriction_type = PolicyDetails.TYPE_MAP[policy['type']] |
self.schema = policy['schema'] |
self.desc = '\n'.join( |
@@ -154,12 +152,6 @@ def main(): |
help='generate an XML file as specified by ' |
'Android\'s App Restriction Schema', |
metavar='FILE') |
- parser.add_option('--arr', '--app-restrictions-resources', |
- dest='app_resources_path', |
- help='generate an XML file with resources supporting the ' |
- 'restrictions defined in --app-restrictions-definition ' |
- 'parameter', |
- metavar='FILE') |
(opts, args) = parser.parse_args() |
@@ -191,7 +183,6 @@ def main(): |
if os == 'android': |
GenerateFile(opts.app_restrictions_path, _WriteAppRestrictions, xml=True) |
- GenerateFile(opts.app_resources_path, _WriteResourcesForPolicies, xml=True) |
return 0 |
@@ -1007,14 +998,6 @@ def _WriteCloudPolicyDecoder(policies, os, f): |
f.write(CPP_FOOT) |
-def _EscapeResourceString(raw_resource): |
- if type(raw_resource) == int: |
- return raw_resource |
- return xml_escape(raw_resource)\ |
- .replace('\\', '\\\\')\ |
- .replace('\"','\\\"')\ |
- .replace('\'','\\\'') |
- |
def _WriteAppRestrictions(policies, os, f): |
def WriteRestrictionCommon(key): |
@@ -1031,7 +1014,7 @@ def _WriteAppRestrictions(policies, os, f): |
policy_name = policy.name |
WriteRestrictionCommon(policy_name) |
- if policy.has_restriction_resources: |
+ if policy.items is not None: |
WriteItemsDefinition(policy_name) |
f.write(' android:restrictionType="%s"/>' % policy.restriction_type) |
@@ -1045,44 +1028,5 @@ def _WriteAppRestrictions(policies, os, f): |
WriteAppRestriction(policy) |
f.write('</restrictions>') |
- |
-def _WriteResourcesForPolicies(policies, os, f): |
- |
- # TODO(knn): Update this to support i18n. |
- def WriteString(key, value): |
- f.write(' <string name="%s">%s</string>\n' |
- % (key, _EscapeResourceString(value))) |
- |
- def WriteItems(key, items): |
- if items: |
- f.write(' <string-array name="%sEntries">\n' % key) |
- for item in items: |
- f.write(' <item>%s</item>\n' % |
- _EscapeResourceString(item.caption)) |
- f.write(' </string-array>\n') |
- f.write(' <string-array name="%sValues">\n' % key) |
- for item in items: |
- f.write(' <item>%s</item>\n' % _EscapeResourceString(item.value)) |
- f.write(' </string-array>\n') |
- |
- def WriteResourceForPolicy(policy): |
- policy_name = policy.name |
- WriteString(policy_name + 'Title', policy.caption) |
- |
- # Get the first line of the policy description. |
- description = policy.desc.split('\n', 1)[0] |
- WriteString(policy_name + 'Desc', description) |
- |
- if policy.has_restriction_resources: |
- WriteItems(policy_name, policy.items) |
- |
- # _WriteResourcesForPolicies body |
- f.write('<resources>\n\n') |
- for policy in policies: |
- if policy.is_supported and policy.restriction_type != 'invalid': |
- WriteResourceForPolicy(policy) |
- f.write('</resources>') |
- |
- |
if __name__ == '__main__': |
sys.exit(main()) |