from datetime import datetime
import time


def generate_module_stream_version(timestamp=False):
    """Generates a version of a module stream. The version of a module stream can be an arbitrary
    unix timestamp or a timestamp taken from the commit of a git branch.

    :param timestamp: unix timestamp
    :type timestamp: int, optional
    :return: Formated module stream version
    :rtype: str
    """

    if timestamp:
        dt = datetime.utcfromtimestamp(int(timestamp))
    else:
        dt = datetime.utcfromtimestamp(int(time.time()))

    # we need to format the timestamp so its human readable and becomes a module stream version
    version = int(dt.strftime("%Y%m%d%H%M%S"))

    return version