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


_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:

    http_schemapath = ph.get_ui_pipeline_schema_filepath(pipeline_id, ph.UI_TYPE_HTTP_STREAMING, '0')
    http_jnodepath = ph.get_ui_pipeline_jnode_filepath(pipeline_id, ph.UI_TYPE_HTTP_STREAMING, '0')
    fs.ln_schema(http_schemapath, http_jnodepath)

    rtsp_jnodepath = ph.get_ui_pipeline_jnode_filepath(pipeline_id, ph.UI_TYPE_RTSP_STREAMING, '0')
    if os.path.exists(rtsp_jnodepath):
        rtsp_schemapath = ph.get_ui_pipeline_schema_filepath(pipeline_id, ph.UI_TYPE_RTSP_STREAMING, '0')
        fs.ln_schema(rtsp_schemapath, rtsp_jnodepath)
