示例#1
0
def _import_field_model(subfeed: kp.Subfeed, le_field_model):
    le_field_models = _get_field_models_from_subfeed(subfeed)
    id = le_field_model['fieldModelId']
    if id in le_field_models:
        print(f'Field model with ID {id} already exists. Not adding.')
        return
    print(f'Adding field model: {id}')
    subfeed.submit_message({
        'type': 'addFieldModel',
        'fieldModel': le_field_model
    })
示例#2
0
def _import_le_sorting(subfeed: kp.Subfeed, le_sorting):
    le_sortings = _get_sortings_from_subfeed(subfeed)
    id = le_sorting["sortingId"]
    if id in le_sortings:
        print(f'Sorting with ID {id} already exists. Not adding.')
        return
    print(f'Adding sorting: {id}')
    subfeed.submit_message(
        {'action': {
            'type': 'ADD_SORTING',
            'sorting': le_sorting
        }})
示例#3
0
def _import_le_recording(subfeed: kp.Subfeed, le_recording):
    le_recordings = _get_recordings_from_subfeed(subfeed)
    id = le_recording['recordingId']
    if id in le_recordings:
        print(f'Recording with ID {id} already exists. Not adding.')
        return
    print(f'Adding recording: {id}')
    subfeed.submit_message(
        {'action': {
            'type': 'ADD_RECORDING',
            'recording': le_recording
        }})
示例#4
0
def _get_field_models_from_subfeed(subfeed: kp.Subfeed):
    subfeed.set_position(0)
    le_field_models = {}
    while True:
        msg = subfeed.get_next_message(wait_msec=0)
        if msg is None: break
        a = msg
        if a.get('type', '') == 'addFieldModel':
            fm = a.get('fieldModel', {})
            fmid = fm.get('fieldModelId', '')
            le_field_models[fmid] = fm
        elif a.get('type', '') == 'DELETE_field_models':
            for fmid in a.get('fieldModelIds', []):
                if fmid in le_field_models:
                    del le_field_models[fmid]
    return le_field_models
示例#5
0
def _get_recordings_from_subfeed(subfeed: kp.Subfeed):
    subfeed.set_position(0)
    le_recordings = {}
    while True:
        msg = subfeed.get_next_message(wait_msec=0)
        if msg is None: break
        if 'action' in msg:
            a = msg['action']
            if a.get('type', '') == 'ADD_RECORDING':
                r = a.get('recording', {})
                rid = r.get('recordingId', '')
                le_recordings[rid] = r
            elif a.get('type', '') == 'DELETE_RECORDINGS':
                for rid in a.get('recordingIds', []):
                    if rid in le_recordings:
                        del le_recordings[rid]
    return le_recordings
示例#6
0
def _get_sortings_from_subfeed(subfeed: kp.Subfeed):
    subfeed.set_position(0)
    le_sortings = {}
    while True:
        msg = subfeed.get_next_message(wait_msec=0)
        if msg is None: break
        if 'action' in msg:
            a = msg['action']
            if a.get('type', '') == 'ADD_SORTING':
                s = a.get('sorting', {})
                sid = s.get('sortingId', '')
                le_sortings[sid] = s
            elif a.get('type', '') == 'DELETE_SORTINGS':
                for sid in a.get('sortingIds', []):
                    if sid in le_sortings:
                        del le_sortings[sid]
            elif a.get('type', '') == 'DELETE_SORTINGS_FOR_RECORDINGS':
                for rid in a.get('recordingIds', []):
                    sids = list(le_sortings.keys())
                    for sid in sids:
                        if le_sortings[sid]['recordingId'] == rid:
                            del le_sortings[sid]
    return le_sortings