def GenerateDynamicManifest(plist, client_id, user_settings=None):
  """Generate a dynamic manifest based on a the various client_id fields.

  Args:
    plist: str XML or plist_module.ApplePlist object, manifest to start with.
    client_id: dict client_id parsed by common.ParseClientId.
    user_settings: dict UserSettings as defined in Simian client.
  Returns:
    str XML manifest with any custom modifications based on the client_id.
  """
  # TODO(user): This function is getting out of control and needs refactoring.
  manifest = client_id['track']

  site_mods = models.SiteManifestModification.MemcacheWrappedGetAllFilter(
      (('site =', client_id['site']),))

  os_version_mods = \
      models.OSVersionManifestModification.MemcacheWrappedGetAllFilter(
          (('os_version =', client_id['os_version']),))

  owner_mods = models.OwnerManifestModification.MemcacheWrappedGetAllFilter(
      (('owner =', client_id['owner']),))

  uuid_mods = models.UuidManifestModification.MemcacheWrappedGetAllFilter(
      (('uuid =', client_id['uuid']),))

  tag_mods = []
  if client_id['uuid']:  # not set if viewing a base manifest.
    computer_key = models.db.Key.from_path('Computer', client_id['uuid'])
    computer_tags = models.Tag.GetAllTagNamesForKey(computer_key)
    if computer_tags:
      # NOTE(user): if we feel most computers will have tags, it might make
      #             sense to regularly fetch and cache all mods.
      for tag in computer_tags:
        t = (('tag_key_name =', tag),)
        tag_mods.extend(
            models.TagManifestModification.MemcacheWrappedGetAllFilter(t))

  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 mod.manifests not in manifest:
      return  # return if the desired manifest is not in the mod manifests.

    for install_type in mod.install_types:
      plist_module.UpdateIterable(
          plist, install_type, mod.value, default=[], op=_ModifyList)

  if site_mods or owner_mods or os_version_mods or uuid_mods or tag_mods:
    if type(plist) is str:
      plist = plist_module.MunkiManifestPlist(plist)
      plist.Parse()
    for mod in site_mods:
      __ApplyModifications(manifest, mod, plist)
    for mod in os_version_mods:
      __ApplyModifications(manifest, mod, plist)
    for mod in owner_mods:
      __ApplyModifications(manifest, mod, plist)
    for mod in uuid_mods:
      __ApplyModifications(manifest, mod, plist)
    for mod in tag_mods:
      __ApplyModifications(manifest, mod, plist)

  if user_settings:
    flash_developer = user_settings.get('FlashDeveloper', False)
    block_packages = user_settings.get('BlockPackages', [])
    # If plist is not parsed yet and modifications are required, parse it.
    if (flash_developer or block_packages) and type(plist) is str:
      if type(plist) is str:
        plist = plist_module.MunkiManifestPlist(plist)
        plist.Parse()

    # If FlashDeveloper is True, replace the regular flash plugin with the
    # debug version in managed_updates.
    if flash_developer:
      plist[common.MANAGED_UPDATES].append(FLASH_PLUGIN_DEBUG_NAME)
      try:
        plist[common.MANAGED_UPDATES].remove(FLASH_PLUGIN_NAME)
      except ValueError:
        pass  # FLASH_PLUGIN_NAME was not in managed_updates to begin with.

    # Look for each block package in each install type, remove if found.
    for block_package in block_packages:
      for install_type in common.INSTALL_TYPES:
        if block_package in plist.get(install_type, []):
          plist[install_type].remove(block_package)

  if type(plist) is str:
    return plist
  else:
    return plist.GetXml()
dataset/ETHPy150Open google/simian/src/simian/mac/munki/common.py/GenerateDynamicManifest/swapped operands of `not in`