components/policy/tools/syntax_check_policy_template_json.py
def _CheckPolicyDefinitionChangeCompatibility(self, original_policy,
                                                original_released_platforms,
                                                new_policy,
                                                new_released_platforms,
                                                current_version):
    '''
    Checks if the new policy definition is compatible with the original policy
    definition.

    Args:
      original_policy: The policy definition as it was in the original policy
                       templates file.
      original_released_platforms: A dictionary contains a released platforms
                                   and their release version in the  original
                                   policy template files.
      new_policy: The policy definition as it is (if any) in the modified policy
                  templates file.
      new_released_platforms: A dictionary contains a released platforms and
                              their release version in the modified policy
                              template files.
      current_version: The current major version of the branch as stored in
      chrome/VERSION.

    '''
    # 1. Check if the supported_on versions are valid.

    # All starting versions in supported_on in the original policy must also
    # appear in the changed policy. The only thing that can be added is an
    # ending version.
    for platform in original_released_platforms:
      if platform not in new_released_platforms:
        self._Error('Released platform %s has been removed.' % (platform),
                    'policy', original_policy['name'])
      elif original_released_platforms[platform] < new_released_platforms[
          platform]:
        self._Error(
            'Supported version of released platform %s is changed to a later '
            'version %d from %d.' % (platform, new_released_platforms[platform],
                                     original_released_platforms[platform]),
            'policy', original_policy['name'])

    #2. Check if the type of the policy has changed.
    if new_policy['type'] != original_policy['type']:
      self._Error(
          'Cannot change the type of released policy \'%s\' from %s to %s.' %
          (new_policy['name'], original_policy['type'], new_policy['type']))

    #3 Check if the policy has suddenly been marked as future: true.
    if ('future' in new_policy
        and new_policy['future']) and ('future' not in original_policy
                                       or not original_policy['future']):
      self._Error('Cannot make released policy \'%s\' a future policy' %
                  (new_policy['name']))

    original_device_only = ('device_only' in original_policy and
                            original_policy['device_only'])

    #4 Check if the policy has changed its device_only value
    if (('device_only' in new_policy and
         original_device_only != new_policy['device_only']) or
        ('device_only' not in new_policy and original_device_only)):
      self._Error(
          'Cannot change the device_only status of released policy \'%s\'' %
          (new_policy['name']))

    #5 Check schema changes for compatibility.
    self._CheckSchemasAreCompatible([original_policy['name']],
                                    original_policy['schema'],
                                    new_policy['schema'])

    Checks if the new policy definition is compatible with the original policy
    definition.

    Args:
      original_policy: The policy definition as it was in the original policy
                       templates file.
      original_released_platforms: A dictionary contains a released platforms
                                   and their release version in the  original
                                   policy template files.
      new_policy: The policy definition as it is (if any) in the modified policy
                  templates file.
      new_released_platforms: A dictionary contains a released platforms and
                              their release version in the modified policy
                              template files.
      current_version: The current major version of the branch as stored in
      chrome/VERSION.

    
Checks if the new policy definition is compatible with the original policy
definition.

The policy definition as it was in the original policy
templates file.
original_released_platforms: A dictionary contains a released platforms
and their release version in the  original
policy template files.
new_policy: The policy definition as it is (if any) in the modified policy
templates file.
new_released_platforms: A dictionary contains a released platforms and
their release version in the modified policy
template files.
current_version: The current major version of the branch as stored in
chrome/VERSION.
Checks if the new policy definition is compatible with the original policy definition . The policy definition as it was in the original policy templates file . original_released_platforms : A dictionary contains a released platforms and their release version in the original policy template files . new_policy : The policy definition as it is ( if any ) in the modified policy templates file . new_released_platforms : A dictionary contains a released platforms and their release version in the modified policy template files . current_version : The current major version of the branch as stored in chrome / VERSION .
def _CheckPolicyDefinitionChangeCompatibility(self, original_policy,
                                                original_released_platforms,
                                                new_policy,
                                                new_released_platforms,
                                                current_version):
    for platform in original_released_platforms:
      if platform not in new_released_platforms:
        self._Error('Released platform %s has been removed.' % (platform),
                    'policy', original_policy['name'])
      elif original_released_platforms[platform] < new_released_platforms[
          platform]:
        self._Error(
            'Supported version of released platform %s is changed to a later '
            'version %d from %d.' % (platform, new_released_platforms[platform],
                                     original_released_platforms[platform]),
            'policy', original_policy['name'])
    if new_policy['type'] != original_policy['type']:
      self._Error(
          'Cannot change the type of released policy \'%s\' from %s to %s.' %
          (new_policy['name'], original_policy['type'], new_policy['type']))
    if ('future' in new_policy
        and new_policy['future']) and ('future' not in original_policy
                                       or not original_policy['future']):
      self._Error('Cannot make released policy \'%s\' a future policy' %
                  (new_policy['name']))
    original_device_only = ('device_only' in original_policy and
                            original_policy['device_only'])
    if (('device_only' in new_policy and
         original_device_only != new_policy['device_only']) or
        ('device_only' not in new_policy and original_device_only)):
      self._Error(
          'Cannot change the device_only status of released policy \'%s\'' %
          (new_policy['name']))
    self._CheckSchemasAreCompatible([original_policy['name']],
                                    original_policy['schema'],
                                    new_policy['schema'])
def _CheckPolicyDefinitionChangeCompatibility ( self , original_policy , original_released_platforms , new_policy , new_released_platforms , current_version ) : for platform in original_released_platforms : if platform not in new_released_platforms : self . _Error ( 'Released platform %s has been removed.' % ( platform ) , 'policy' , original_policy [ 'name' ] ) elif original_released_platforms [ platform ] < new_released_platforms [ platform ] : self . _Error ( 'Supported version of released platform %s is changed to a later ' 'version %d from %d.' % ( platform , new_released_platforms [ platform ] , original_released_platforms [ platform ] ) , 'policy' , original_policy [ 'name' ] ) if new_policy [ 'type' ] != original_policy [ 'type' ] : self . _Error ( 'Cannot change the type of released policy \'%s\' from %s to %s.' % ( new_policy [ 'name' ] , original_policy [ 'type' ] , new_policy [ 'type' ] ) ) if ( 'future' in new_policy and new_policy [ 'future' ] ) and ( 'future' not in original_policy or not original_policy [ 'future' ] ) : self . _Error ( 'Cannot make released policy \'%s\' a future policy' % ( new_policy [ 'name' ] ) ) original_device_only = ( 'device_only' in original_policy and original_policy [ 'device_only' ] ) if ( ( 'device_only' in new_policy and original_device_only != new_policy [ 'device_only' ] ) or ( 'device_only' not in new_policy and original_device_only ) ) : self . _Error ( 'Cannot change the device_only status of released policy \'%s\'' % ( new_policy [ 'name' ] ) ) self . _CheckSchemasAreCompatible ( [ original_policy [ 'name' ] ] , original_policy [ 'schema' ] , new_policy [ 'schema' ] )
Checks if the new policy definition is compatible with the original policy
definition.
Checks if the new policy definition is compatible with the original policy definition .
'''
    Checks if the new policy definition is compatible with the original policy
    definition.

    Args:
      original_policy: The policy definition as it was in the original policy
                       templates file.
      original_released_platforms: A dictionary contains a released platforms
                                   and their release version in the  original
                                   policy template files.
      new_policy: The policy definition as it is (if any) in the modified policy
                  templates file.
      new_released_platforms: A dictionary contains a released platforms and
                              their release version in the modified policy
                              template files.
      current_version: The current major version of the branch as stored in
      chrome/VERSION.

    ''' # 1. Check if the supported_on versions are valid. # All starting versions in supported_on in the original policy must also # appear in the changed policy. The only thing that can be added is an # ending version. #2. Check if the type of the policy has changed. #3 Check if the policy has suddenly been marked as future: true. #4 Check if the policy has changed its device_only value #5 Check schema changes for compatibility.
self
original_policy
original_released_platforms
new_policy
new_released_platforms
current_version