Import animation (posebone quat and loc using head and tail coords)


I’m trying to enhance smd importer by JMD ( so that it could load animation.
Right now i have all frames loaded as posebones head and tail positions:
i added lines to be sure they are ok:
How can i transpose those positions to insertKey ?
Function setPose was removed from API though in that case it was perfect solution i think.

Here is my function:

   def createActions(self):
       print 'Creating Action'

       # getting existing armature
       armobj = Object.Get('imported_armature')
       armdata = armobj.getData()
       pose = armobj.getPose()

       newaction = Armature.NLA.NewAction('imported_action')
       for bone in self.bones:
            rest_bone = armdata.bones[]
            bone_rest_matrix = rest_bone.matrix['ARMATURESPACE'].rotationPart()

            bone_rest_matrix_inv= Matrix(bone_rest_matrix)


            pbone = pose.bones[]
            for frm in bone.frames:
                headVec = frm.phead
                tailVec = frm.ptail
                add_line(headVec, tailVec, + ":" + str(frm.number))
                matrix3 = matrix3.resize4x4() * bone_rest_matrix * bone_rest_matrix_inv
                pbone.quat = matrix3.toQuat()
                #pbone.loc = (bone_rest_matrix*matrix3).translationPart().resize3D()

Thank you for any help.:o

So noone could help with this?
here is whole script in case you want to look at: