Exemple #1
0
    def testUpdateIterable(self):
        """Test UpdateIterable()."""
        d = {
            'foo': [0, 1],
        }

        array_add = lambda a, v: a.append(v)
        dict_add = lambda d, v: d.update(v)

        plist.UpdateIterable(d, 'foo', 2, default=[], op=array_add)
        self.assertEqual(d['foo'], [0, 1, 2])

        plist.UpdateIterable(d, 'simple', 'hello')
        self.assertEqual(d['simple'], 'hello')

        plist.UpdateIterable(d, 'simple', 'hello', op=lambda d, v: v.upper())
        self.assertEqual(d['simple'], 'HELLO')

        plist.UpdateIterable(d, 'newd', default={})
        self.assertEqual(d['newd'], {})

        plist.UpdateIterable(d, 'newd', {'newv': 1}, op=dict_add)
        self.assertEqual(
            d,
            {
                'foo': [0, 1, 2],
                'simple': 'HELLO',
                'newd': {
                    'newv': 1
                },
            },
        )
Exemple #2
0
  def __ApplyModifications(manifest, mod, plist):
    """Applies a manifest modification if the manifest matches mod manifest.

    NOTE(user): if mod.manifests is empty or None, mod is made to any manifest.
    """
    plist_xml = None
    if type(plist) is str:
      plist_xml = plist

    if not mod.enabled:
      return  # return it the mod is disabled
    elif mod.manifests and manifest not in mod.manifests:
      return  # return if the desired manifest is not in the mod manifests.

    #logging.debug(
    #    'Applying manifest mod: %s %s', mod.install_types, mod.value)
    for install_type in mod.install_types:
      plist_module.UpdateIterable(
          plist, install_type, mod.value, default=[], op=_ModifyList)