#!/usr/bin/python

import re
import sys
import posixpath

from subprocess import Popen, PIPE


def main():
    """
    Run compiz check and return any error code
    """
    compiz_check = posixpath.join(posixpath.dirname(__file__), "compiz-check")
    # Answer 'n' to all questions
    command = "yes n | %s" % compiz_check
    process = Popen(command, shell=True, stdout=PIPE)
    output = process.communicate()[0]

    # Remove colored output (not handled correctly in checkbox report)
    output = re.sub(r"\[([0-8])?(;3[0-7])?(;4[0-7])?m", "", output)
    print output

    return process.returncode

if __name__ == "__main__":
    sys.exit(main())
