How can the active bone group be set from a script? According to the docs


  bpy.ops.pose.group_select()
   Select bones in active Bone Group


How can the active bone group be set?

Context:

import bpy
is_debug = True

def debug(msg):
    if is_debug:
        print( "Frame:%d %s" % (bpy.context.scene.frame_current, msg ))         

def find_bone_names_by_group(passedPose, passedGroupName):
    result = []
    for b in passedPose.bones:
        if hasattr( b.bone_group, "name"):
            if b.bone_group.name == passedGroupName:
                result.append(b.bone.name)
    return result

def dump(obj,name="obj"):
   for attr in dir(obj):
       if hasattr( obj, attr ):
           print( "%s.%s = %s" % (name,attr, getattr(obj, attr)))

def assign_pose(rig, bone_group_name, pose_name):

    pl = rig.pose_library
    pm=pl.pose_markers[ pose_name ]
    #dump(pm)
    debug("pose_marker=" +str(pm))
    p = rig.pose

    bones_to_modify = find_bone_names_by_group(p, bone_group_name)
    if len(bones_to_modify ) &lt; 1:
        print("No bones found in group [" + bone_group_name + "].")
        return

    action =  bpy.data.actions[pl.name]
    debug("assign_pose " + pose_name)
    for agrp in action.groups:
        if agrp.name in bones_to_modify:
            i = p.bones.find(agrp.name)
            if i != -1:
                pb = p.bones[i]
                debug("Found bone:" + pb.name )
                # check if group has any keyframes.
                for fc in agrp.channels:
                    tmpValue = fc.evaluate(bpy.context.scene.frame_current)
                    # Determine where to assign this value based upon the data_path.
                    if fc.data_path.find("location") != -1:
                        pb.location[fc.array_index] = tmpValue
                    if fc.data_path.find("rotation_quaternion") != -1:
                        pb.rotation_quaternion[fc.array_index] = tmpValue
                bpy.ops.anim.keyframe_insert(type='BUILTIN_KSI_LocRot',confirm_success=is_debug)  
                #bpy.ops.anim.keyframe_insert(type='DEFAULT', confirm_success=True)  
            else:
                print("Pose bone [" + agrp.name + "] not found.")                      


txt = bpy.data.texts["pose.txt"].as_string()
for line in txt.splitlines():
    if line.find(" ") != -1 and line.find("#") == -1:
        sframe,rig_and_poses= line.split(" ")
        rest=rig_and_poses.split(":")
        print("-"*40)
        rig_name=rest[0]
        poses=rest[1]
        pose_list=poses.split(",")
        bpy.context.scene.frame_set( int( sframe ))
        for assignment in pose_list:
            bone_group_name,pose_name=assignment.split("=")
            rig = bpy.data.objects.get(rig_name)
            if rig == None:
                print("rig name=" + rig_name + " not found.")
                break
            debug("assign rig:%s bone_group:%s, pose:%s" % (rig, bone_group_name, pose_name))
            assign_pose(rig, bone_group_name, pose_name)
Example:

import bpy

obj = bpy.data.objects['Armature']
bone_groups = obj.pose.bone_groups

bone_groups.active = bone_groups[string_key]
#or
bone_groups.active_index = new_index