# Copyright (c) 2015 VMware, Inc.  All rights reserved.
# -- VMware Confidential

import os

__VERSION_FILE__ = "/etc/vmware-rhttpproxy/version.txt"


def getSourceVersion(filePath=__VERSION_FILE__):
    """Loads current component version from filePath.

    @param filePath: Path to the component version file.
    """

    if os.path.exists(filePath):
        with open(filePath) as fp:
            version = fp.read()
    else:
        version = None
    return version


def setSourceVersion(version, filePath=__VERSION_FILE__):
    """ Persists the latest applied patch version.

    @param version: The latest patch version
    @param filePath: Path to the component version file.
    """

    with open(filePath, 'w') as fp:
        fp.write(version)
