Exemple #1
0
def add_configuration(json):
    cameras = json["cameras"]
    json.pop("cameras")
    configuration = Configuration(**json)
    db_session.add(configuration)
    db_session.flush()
    for camera in cameras:
        db_session.add(
            CameraConfiguration(camera_id=camera, configuration_id=configuration.id)
        )
    db_session.commit()
Exemple #2
0
def edit_camera(json):
    camera = db_session.query(Camera).filter(Camera.id == json["id"]).one()
    sub_streams = json["sub_streams"]
    ss = (
        db_session.query(CameraSubStream)
        .filter(CameraSubStream.camera == camera.id)
        .all()
    )
    for s in ss:
        db_session.delete(s)
    for sub_stream in sub_streams:
        db_session.add(CameraSubStream(camera=camera.id, sub_stream=sub_stream))
    json.pop("sub_streams")
    db_session.query(Camera).filter(Camera.id == json["id"]).update(json)
    db_session.commit()
Exemple #3
0
def edit_configuration(json):
    cameras = json["cameras"]
    json.pop("cameras")
    configuration = (
        db_session.query(Configuration).filter(Configuration.id == json["id"]).one()
    )
    cc = (
        db_session.query(CameraConfiguration)
        .filter(CameraConfiguration.configuration_id == configuration.id)
        .all()
    )
    for c in cc:
        db_session.delete(c)
    for camera in cameras:
        db_session.add(
            CameraConfiguration(camera_id=camera, configuration_id=configuration.id)
        )
    db_session.query(Configuration).filter(Configuration.id == json["id"]).update(json)
    db_session.commit()
Exemple #4
0
def add_camera(json):
    sub_streams = json["sub_streams"]
    json.pop("sub_streams")
    auth_url = ''
    port = ''
    if json["login"] != '':
        auth_url = f'{json["login"]}:{json["password"]}@'
    else:
        json.pop("login")
    if json["port"] != '':
        port = f':{json["port"]}'
    else:
        json.pop("port")
    if json["ptz_port"] == '':
        json.pop("ptz_port")
    url = f'rtsp://{auth_url}{json["ip_address"]}{port}'
    camera = Camera(**json)

    camera.url = url
    db_session.add(camera)
    db_session.flush()
    for sub_stream in sub_streams:
        db_session.add(CameraSubStream(camera=camera.id, sub_stream=sub_stream))
    db_session.commit()
Exemple #5
0
def create_settings(json):
    settings = Setting(path=json["path"], udp_preferred=json["udp_preferred"])
    db_session.add(settings)
    db_session.commit()