convert camera to blender, math help

hi,
i have to convert a bunch of cameras from origin/up/focal point format to blender’s location/rotation/dof distance. i was able to make location work but the rest is just too much for my skills. here is the part of code is run from command line, it should make a simple setup script for every camera. source axes are: X left/right, Y up/down Z forward(+)/backward(-)
please help :frowning:


def convert_cam(cam):
    values = cam.getValues()
    step = cam.getStep(0)
    
    shutter = 1/values['shutter']
    sensor_fit = 'HORIZONTAL'
    sensor_width = values['filmWidth']*1000
    sensor_height = values['filmHeight']*1000
    iso = values['iso']
    xres = values['xRes']
    yres = values['yRes']
    pixel_aspect = values['pixelAspect']
    
    origin = step[0]
    focal_point = step[1]
    up = step[2]
    focal_length = step[3]*1000
    fstop = step[4]
    
    write_py("""
import bpy
from mathutils import *
from bpy_extras.io_utils import axis_conversion

transform = axis_conversion(from_forward='-Y',to_forward='Z',from_up='Z',to_up='Y').to_4x4()
origin = Vector(({0},{1},{2}))
loc = origin * transform

up = Vector(({3},{4},{5}))
# how to get rotation?
rot = Vector((0.0,0.0,0.0))

fp = Vector(({6},{7},{8}))
# how to get distance?
dof_distance = 0.0

bpy.ops.object.camera_add(view_align=False,enter_editmode=False,location=loc,rotation=rot)
cam = bpy.context.active_object.data
cam.lens = {9}
cam.dof_distance = dof_distance
cam.sensor_fit = '{10}'
cam.sensor_width = {11}
cam.sensor_height = {12}
render = bpy.context.scene.render
render.resolution_x = {13}
render.resolution_y = {14}

bpy.context.active_object.data.lens = focal_length
    """.format(
            origin.x(),origin.y(),origin.z(),
            up.x(),up.y(),up.z(),
            focal_point.x(),focal_point.y(),focal_point.z(),
            focal_length,sensor_fit,sensor_width,sensor_height,xres,yres,
        )
    )