def maybe_split_groups(self, max_groups):
split_commands = []<EOL>maybe_split = False<EOL>valid_step_keys = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>for command in self.commands:<EOL><INDENT>step_key, step_args = next(six.iteritems(command))<EOL>if step_key not in valid_step_keys or not isinstance(step_args, dict):<EOL><INDENT>split_commands.append(command)<EOL>continue<EOL><DEDENT>new_commands = [command]<EOL>while True:<EOL><INDENT>new_command = {step_key: {}}<EOL>for group_type, groups in six.iteritems(command[step_key]):<EOL><INDENT>if len(groups) > max_groups:<EOL><INDENT>command[step_key][group_type], new_command[step_key][group_type] =groups[<NUM_LIT:0>:max_groups], groups[max_groups:]<EOL><DEDENT><DEDENT>if new_command[step_key]:<EOL><INDENT>new_commands.append(new_command)<EOL>command = new_command<EOL>maybe_split = True<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>split_commands += new_commands<EOL><DEDENT>self.commands = split_commands<EOL>return maybe_split<EOL>
Check if group lists in add/remove directives should be split and split them if needed
:param max_groups: Max group list size
:return: True if at least one command was split, False if none were split