#!/usr/bin/python
from edge.com import fs
from edge import path_helpers as ph
import ujson


_PIPELINE_SET_FILEPATH = '/etc/edge/setupstore/admin/actions/pipeline.json'


with open(_PIPELINE_SET_FILEPATH, 'r') as json_file:
    pipeline_jnode_set = ujson.load(json_file)


migrate_list = map(lambda x: x['id'], pipeline_jnode_set)

for pipeline_id in migrate_list:
    ui_jnode_filepath = ph.get_ui_pipeline_jnode_filepath(pipeline_id, ph.UI_TYPE_HTTP_STREAMING, '0')

    http_schemapath = ph.get_ui_pipeline_schema_filepath(pipeline_id, ph.UI_TYPE_HTTP_STREAMING, '0')
    fs.silent_rm_r(http_schemapath)

    rtsp_schemapath = ph.get_ui_pipeline_schema_filepath(pipeline_id, ph.UI_TYPE_RTSP_STREAMING, '0')
    fs.silent_rm_r(rtsp_schemapath)

    ui_jnode = fs.load_json2(ui_jnode_filepath)
    if ui_jnode['rw']['live']['renderer']['vehicle'].get('video-plate-center') is None:
        ui_jnode['rw']['live']['renderer']['vehicle']['video-plate-center'] = 'never'
        fs.write_json_file(ui_jnode, ui_jnode_filepath, pretty=True)
