def getOsVersion(only_major_minor=True, as_tuple=False):
    """Returns an OS version.

    Args:
      only_major_minor: Boolean. If True, only include major/minor versions.
      as_tuple: Boolean. If True, return a tuple of ints, otherwise a string.
    """
    os.environ["SYSTEM_VERSION_COMPAT"] = '0'
    cmd = ["/usr/bin/sw_vers -productVersion"]
    proc = subprocess.Popen(
        cmd,
        shell=True,
        bufsize=-1,
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    (output, unused_error) = proc.communicate()
    output = output.strip()
    os_version_tuple = output.split(".")
    if only_major_minor:
        os_version_tuple = os_version_tuple[0:2]
    if as_tuple:
        return tuple(map(int, os_version_tuple))
    else:
        return ".".join(os_version_tuple)