#!/usr/bin/env python
#
# Copyright 2017 VMware, Inc.  All rights reserved. -- VMware Confidential
#

import logging

logger = logging.getLogger(__name__)


def text_subst_in_file(file_path, text_subst_args):
    """
    Replace strings in a file

    :param file_path: Path to the file
    :type file_path: str

    :param text_subst_args: Object with key - the string to search and value - string to replace with
    :type text_subst_args: object
    """

    logger.info('Replacing values in file %s' % file_path)
    with open(file_path) as f:
        file_content = f.read()

    for k, v in text_subst_args.items():
        file_content = file_content.replace(k, v)

    with open(file_path, 'w') as f:
        f.write(file_content)

    logger.info('Done')