import copy


def construct_page_specifications(pages_dict, masters_dict):
    """Construct dict by adding details from masters to page instructions

    The pages dict only contains the name of the master to use and the
    page number, which is not enough to generate the page. This function
    fills in the needed details from the masters dict.

    This allows the file containing the page-generating instructions
    to be kept reasonably clear, allowing for easier editing, and
    removes repetition.
    """
    detailed_dict = copy.deepcopy(pages_dict)
    for desk in detailed_dict:
        for page_list in detailed_dict[desk].values():
            for page in page_list:
                master = masters_dict[page['master']]
                page['slug'] = master['slug']
                page['spread'] = master['spread']
    return detailed_dict