#!/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'], x['type']), pipeline_jnode_set)
for pipeline_id, pipeline_type in migrate_list:

    ui_vs_jnode_filepath = ph.get_ui_pipeline_jnode_filepath(pipeline_id, ph.UI_TYPE_VIDEOSOURCE, '0')

    ui_vs_jnode = fs.load_json2(ui_vs_jnode_filepath)
    if 'haltaction' in ui_vs_jnode['ro']:
        ui_vs_jnode['ro'].pop('haltaction')
        fs.write_json_file(ui_vs_jnode, ui_vs_jnode_filepath, pretty=True)

    if pipeline_type in [ph.PTYPE_SPEED]:
        ui_location_jnode_filepath = ph.get_ui_pipeline_jnode_filepath(pipeline_id, ph.UI_TYPE_LOCATION, '0')

        ui_jnode = fs.load_json2(ui_location_jnode_filepath)
        if 'haltaction' in ui_vs_jnode['ro']:
            ui_jnode['ro'].pop('haltaction')
            fs.write_json_file(ui_jnode, ui_location_jnode_filepath, pretty=True)
