'Build an XBlock, add it to block_map, and call build_xblock on
the children defined in block_dict.
Arguments:
block_hierarchy (BlockStructureDict): Definition of
hierarchy, from this block down.
block_map (dict[str: XBlock]): Mapping from \'#ref\' values to
their XBlocks.
parent (XBlock): Parent block for this xBlock.'

def build_xblock(self, block_hierarchy, block_map, parent):

    block_type = block_hierarchy['#type']
    block_ref = block_hierarchy['#ref']
    factory = (CourseFactory if (block_type == 'course') else ItemFactory)
    kwargs = {key: value for (key, value) in block_hierarchy.iteritems() if (key[0] != '#')}
    if (block_type != 'course'):
        kwargs['category'] = block_type
        kwargs['publish_item'] = (True,)
    if parent:
        kwargs['parent'] = parent
    xblock = factory.create(display_name=self.create_block_id(block_type, block_ref), **kwargs)
    block_map[block_ref] = xblock
    for child_hierarchy in block_hierarchy.get('#children', []):
        self.build_xblock(child_hierarchy, block_map, xblock)
