Using input file, generate an output file with the version info for this package.
    This should generally be used in setup.py to generate build stamp info.
    :param infile:
    :param outfile:
    :param kwargs:
    :return:

def generate_version_file(infile='version.py.in', outfile='version.py', **kwargs):
    """
    Using input file, generate an output file with the version info for this package.
    This should generally be used in setup.py to generate build stamp info.
    :param infile:
    :param outfile:
    :param kwargs:
    :return:
    """

    if not os.path.exists(outfile) and os.path.exists(infile):
        now = datetime.datetime.now()
        repo_hash = ''
        git_path = find_exe('git')
        if git_path is not None:
            git_cmd = [find_exe('git'), 'log', '--format=%h', '-1']
            repo_hash = subprocess.Popen(git_cmd, stdout=subprocess.PIPE).communicate()[0].strip()
        if repo_hash.strip() == '':
            repo_hash = '{now.hour}.{now.minute}.{now.second}'.format(now=now)

        sub_dict = {
            'repo_hash': repo_hash,
            'build_date': '{now.year}.{now.month}.{now.day}'.format(now=now),
            'build_time': '{now.hour}.{now.minute}.{now.second}'.format(now=now),
            'build_host': socket.gethostname(),
            'build_user': getpass.getuser()
        }
        sub_dict.update(**kwargs)

        with open(infile) as version_in:
            version_data = version_in.read()
            version_final = string.Template(version_data).safe_substitute(sub_dict)

        with open(outfile, 'w') as version_out:
            version_out.write(version_final)

    return outfile if os.path.exists(outfile) else None