<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def override_component_template(component, template_path):
 """Override a default component with a new component with given template. :param component: Component as dictionary. :type component: dict :param template_path: Custom template path that will be used. :type template_path: str :returns: New report component. :rtype: dict """

    copy_component = deepcopy(component)
    template_directory, template_filename = split(template_path)
    file_name, file_format = splitext(template_filename)
    if file_format[1:] != (
            QgisComposerComponentsMetadata.OutputFormat.QPT) or (
                not exists(template_path)):
        return copy_component

    # we do the import here to avoid circular import when starting
    # up the plugin
    from safe.definitions.reports.components import (
        map_report_component_boilerplate)
    custom_template_component = deepcopy(
        map_report_component_boilerplate)

    # we need to update several items in this component
    pdf_output_file = '{file_name}.pdf'.format(file_name=file_name)
    qpt_output_file = '{file_name}.qpt'.format(file_name=file_name)

    custom_template_component['key'] = file_name
    custom_template_component['template'] = template_path
    custom_template_component['output_path']['template'] = qpt_output_file
    custom_template_component['output_path']['map'] = pdf_output_file

    # we need to update the orientation of the custom template
    with open(custom_template_component['template']) as (
            template_file):
        template_content = template_file.read()
    document = QDomDocument()
    document.setContent(template_content)
    root_element = document.namedItem('Composer')
    composition_element = root_element.namedItem('Composition')
    all_orientations = [
        landscape_map_report_description,
        portrait_map_report_description
    ]
    orientation = None
    if isinstance(root_element, QDomNode):
        paper_width = composition_element.attributes().namedItem(
            'paperWidth').nodeValue()
        paper_height = composition_element.attributes().namedItem(
            'paperHeight').nodeValue()
        for _orientation in all_orientations:
            if _orientation['width'] == int(paper_width) and (
                    _orientation['height'] == int(paper_height)):
                orientation = _orientation['orientation']
                break

    # By default, the component is landscape oriented, So if we found that
    # the custom template is portrait, we need to delete the information about
    # orientation in the component because in the report metadata, if there is
    # no specification about the orientation, then they will set it
    # to portrait.
    if orientation == portrait_map_report_description['orientation']:
        custom_template_component['orientation'] = orientation
        del custom_template_component['page_width']
        del custom_template_component['page_height']

    copy_component['components'] = [custom_template_component]

    return copy_component