{= # Get the template profile string template_profile_name = miscellaneous.create_many_profiles.template_profile_name; string template_profile = "profiles." . template_profile_name; "Creating profiles from template '$template_profile_name'\n"; # This duplicates node destination, putting its subnodes (recursively) into node source. subroutine(duplicate_node(string source, string destination), ( # debug_message("Duplicating node $source into $destination\n"); node subnode; foreach subnode source ( string partial_node_name = substr(subnode, length(source)); # debug_message("partial_node_name: $partial_node_name\n"); (destination . partial_node_name) = node_value(subnode); if (num_subnodes(subnode) != 0) then duplicate_node(subnode, (destination . partial_node_name)); ); )); # This applies a change from profile to newprofile. subroutine(apply_change(string profile, string newprofile, string change), ( # Don't do anything if the node doesn't exist if (node_exists(change)) then ( # If this change is actually a group node, then apply the changes below it bool group = false; if (num_subnodes(change) > 0) then ( group = true; node subnode; foreach subnode change ( apply_change(profile, newprofile, subnode); ); ); # Change the value of this node string change_partial_node_name = substr(change, length(profile . ".changes")); string change_value = node_value(change); if (!group or (node_value(change) ne "")) then " Applying change: " . newprofile . change_partial_node_name . " = '" . change_value . "'\n"; (newprofile . change_partial_node_name) = change_value; ); # If change node exists )); # subroutine apply_changes() # Create the profiles string profile; foreach profile "miscellaneous.create_many_profiles.profiles" ( # Duplicate the node string profilename = node_name(profile); "Creating profile: " . profilename . "\n"; string newprofile = "profiles." . profilename; (newprofile . "") = ""; duplicate_node(template_profile, newprofile); # Apply any changes if (node_exists(profile . ".changes")) then ( string change; foreach change (profile . ".changes") ( # Set the change in the new profile apply_change(profile, newprofile, change); ) # foreach change ); # if changes save_node(newprofile); # debug_message("New profile: " . node_as_string("profiles." . miscellaneous.create_many_profiles.template_profile_name) . "\n"); ); =}