Esempio n. 1
0
def add_order_data(item: OrderItem, fname: str, parent: str) -> dict:
    assert isinstance(item, OrderItem)
    assert isinstance(fname, str)
    assert isinstance(parent, str)

    data = _get_order_raw_data()
    _fname = ordername_of(item, fname)
    _parent = ordername_of(get_parent_item_of(item), parent)

    if OrderItem.CHAPTER is item:
        assertion.is_list(data[str(OrderItem.BOOK)]).append({_fname: []})
        return data

    for ch_record in assertion.is_list(data[str(OrderItem.BOOK)]):
        assert isinstance(ch_record, dict)
        for ch_key, ch_data in ch_record.items():
            assert isinstance(ch_data, list)
            if OrderItem.EPISODE is item and ch_key == _parent:
                ch_data.append({_fname: []})
                return data

            for ep_record in ch_data:
                assert isinstance(ep_record, dict)
                for ep_key, ep_data in ep_record.items():
                    assert isinstance(ep_data, list)
                    if OrderItem.SCENE is item and ep_key == _parent:
                        ep_data.append(_fname)
                        return data
    return data
Esempio n. 2
0
def outputs_data_from_contents_data(
        contents_data: ContentsData) -> OutputsData:
    assert isinstance(contents_data, ContentsData)

    formatted = assertion.is_list(format_contents_data(contents_data))

    return OutputsData(formatted + get_breakline_list())
Esempio n. 3
0
def get_chapters_in_order() -> list:
    data = assertion.is_list(get_order_data()[str(OrderItem.BOOK)])
    tmp = []

    for ch_record in data:
        assert isinstance(ch_record, dict)
        for key in ch_record.keys():
            if str(OrderItem.CHAPTER) in key:
                tmp.append(rid_prefix(OrderItem.CHAPTER, key))
    return tmp
Esempio n. 4
0
def _reject_chapter_from_order(orders: dict, fname: str) -> bool:
    assert isinstance(orders, dict)
    assert isinstance(fname, str)

    _ch_name = ordername_of(OrderItem.CHAPTER, fname)
    tmp = []

    for ch_record in assertion.is_list(orders[str(OrderItem.BOOK)]):
        assert isinstance(ch_record, dict)
        if _ch_name not in ch_record.keys():
            tmp.append(ch_record)
    orders[str(OrderItem.BOOK)] = tmp
    return True
Esempio n. 5
0
def get_episodes_in_order() -> list:
    data = assertion.is_list(get_order_data()[str(OrderItem.BOOK)])
    tmp = []

    for ch_record in data:
        assert isinstance(ch_record, dict)
        for ep_data in ch_record.values():
            assert isinstance(ep_data, list)
            for ep_record in ep_data:
                assert isinstance(ep_record, dict)
                for key in ep_record.keys():
                    if str(OrderItem.EPISODE) in key:
                        tmp.append(rid_prefix(OrderItem.EPISODE, key))
    return tmp
Esempio n. 6
0
def serialized_filenames_from_order(order_data: dict, ch_start: int,
                                    ch_end: int, ep_start: int, ep_end: int,
                                    sc_start: int, sc_end: int) -> list:
    assert isinstance(order_data, dict)
    assert isinstance(ch_start, int)
    assert isinstance(ch_end, int)
    assert isinstance(ep_start, int)
    assert isinstance(ep_end, int)
    assert isinstance(sc_start, int)
    assert isinstance(sc_end, int)

    logger.debug(msg.PROC_START.format(proc=PROC))

    if not _is_valid_order_data(order_data):
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(proc=f"order data: {PROC}"))
        return []

    tmp = []
    ch_idx, ep_idx, sc_idx = 0, 0, 0

    for ch_record in assertion.is_list(order_data[str(OrderItem.BOOK)]):
        # in Chapter
        if ch_idx >= ch_start and (ch_idx <= ch_end or ch_end < 0):
            assert isinstance(ch_record, dict)
            for key in ch_record.keys():
                tmp.append(key)
            # in Episode
            for ch_data in ch_record.values():
                assert isinstance(ch_data, list)
                for ep_record in ch_data:
                    if ep_idx >= ep_start and (ep_idx <= ep_end or ep_end < 0):
                        assert isinstance(ep_record, dict)
                        for key in ep_record.keys():
                            tmp.append(key)
                        # in Scene
                        for ep_data in ep_record.values():
                            assert isinstance(ep_data, list)
                            for sc_record in ep_data:
                                if sc_idx >= sc_start and (sc_idx <= sc_end
                                                           or sc_end < 0):
                                    assert isinstance(sc_record, str)
                                    tmp.append(sc_record)
                                sc_idx += 1
                    ep_idx += 1
        ch_idx += 1

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return tmp
Esempio n. 7
0
def get_scenes_in_order() -> list:
    data = assertion.is_list(get_order_data()[str(OrderItem.BOOK)])
    tmp = []

    for ch_record in data:
        assert isinstance(ch_record, dict)
        for ep_data in ch_record.values():
            assert isinstance(ep_data, list)
            for ep_record in ep_data:
                assert isinstance(ep_record, dict)
                for sc_data in ep_record.values():
                    assert isinstance(sc_data, list)
                    for sc_record in sc_data:
                        assert isinstance(sc_record, str)
                        if str(OrderItem.SCENE) in sc_record:
                            tmp.append(rid_prefix(OrderItem.SCENE, sc_record))
    return tmp
Esempio n. 8
0
def _reject_episode_from_order(orders: dict, fname: str) -> bool:
    assert isinstance(orders, dict)
    assert isinstance(fname, str)

    _ep_name = ordername_of(OrderItem.EPISODE, fname)

    for ch_record in assertion.is_list(orders[str(OrderItem.BOOK)]):
        assert isinstance(ch_record, dict)
        for ch_data in ch_record.values():
            assert isinstance(ch_data, list)
            tmp = []
            for ep_record in ch_data:
                assert isinstance(ep_record, dict)
                if _ep_name not in ep_record.keys():
                    tmp.append(ep_record)
            for key in ch_record.keys():
                ch_record[key] = tmp
    return True
Esempio n. 9
0
def story_data_from(args: Namespace) -> StoryData:
    assert isinstance(args, Namespace)

    logger.debug(msg.PROC_START.format(proc=PROC))

    order_data = read_yaml_data(read_file(filepath_of(ElmType.ORDER, '')))

    if not order_data:
        logger.error(
            msg.ERR_FAIL_MISSING_DATA.format(data=f"order data in {PROC}"))
        return None

    elmpart = assertion.is_instance(
        _get_elm_part(args.part if args.part else ""), ElmPart)

    serialized = assertion.is_list(
        serialized_filenames_from_order(
            order_data,
            elmpart.chapter[0],
            elmpart.chapter[1],
            elmpart.episode[0],
            elmpart.episode[1],
            elmpart.scene[0],
            elmpart.scene[1],
        ))

    if not serialized:
        logger.error(
            msg.ERR_FAIL_MISSING_DATA.format(
                data=f"serialized data in {PROC}"))
        return None

    story_data_base = _conv_story_data_from(serialized)
    if not story_data_base:
        logger.error(
            msg.ERR_FAIL_MISSING_DATA.format(
                data=f"story data base in {PROC}"))
        return None

    updated = update_story_data_if_same_or_next_tag(StoryData(story_data_base))

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return updated
Esempio n. 10
0
def _reject_scene_from_order(orders: dict, fname: str) -> bool:
    assert isinstance(orders, dict)
    assert isinstance(fname, str)

    _sc_name = ordername_of(OrderItem.SCENE, fname)

    for ch_record in assertion.is_list(orders[str(OrderItem.BOOK)]):
        assert isinstance(ch_record, dict)
        for ch_data in ch_record.values():
            assert isinstance(ch_data, list)
            for ep_record in ch_data:
                assert isinstance(ep_record, dict)
                for ep_data in ep_record.values():
                    assert isinstance(ep_data, list)
                    tmp = []
                    for sc_record in ep_data:
                        assert isinstance(sc_record, str)
                        if sc_record != _sc_name:
                            tmp.append(sc_record)
                    for key in ep_record.keys():
                        ep_record[key] = tmp
    return True
Esempio n. 11
0
def elm_data_of(record: StoryRecord) -> list:
    return assertion.is_list(_safe_get_elm_item_of(record, DATAS))
Esempio n. 12
0
def test_assertion_is_list__failure(x):

    with pytest.raises(AssertionError):
        is_list(x)
Esempio n. 13
0
def test_assertion_is_list(x):

    assert is_list(x) or is_list(x) == [], f"Expected a list type value: {x}"