<commit_before>"""
Main module for the PythonWrapper XBMC/Kodi script
"""
import os
try:
    import xbmc
except ImportError:
    LOG = print
else:
    LOG = xbmc.log

def main():
    """ main """
    LOG("### Python wrapper ### Hello !")
    try:
        os.mkdir("/tmp/xbmcwrapper")
        os.mkfifo("/tmp/xbmcwrapper/input_cmd")
    except FileExistsError:
        pass

    with open("/tmp/xbmcwrapper/input_cmd", 'r') as pipe:
        with open("/tmp/xbmcwrapper/output", 'wa') as output:
            LOG("### Python wrapper ### File opened !")
            while True:
                line = pipe.readline()
                if line == "exit\n":
                    break
                elif len(line) > 0:
                    LOG("### Python wrapper ### {0}".format(line))
                    try:
                        returned = eval(line)
                    except Exception as eval_exception:
                        returned = "Exception raised during evaluation : {0}".format(eval_exception)
                    output.write("Input : < {0} >\n\tReturned : < {1} >\n\n".format(line.strip(),
                        returned))
                    output.flush()
    return 0

if __name__ == "__main__":
    main()<commit_msg>No more polling, and allow multi-line execution Need to find how to output to the output file instead of stdout when exec()<commit_after>"""
Main module for the PythonWrapper XBMC/Kodi script
"""
import os
try:
    import xbmc
except ImportError:
    LOG = print
else:
    LOG = xbmc.log

def main():
    """ main """
    LOG("### Python wrapper ### Hello !")
    try:
        os.mkdir("/tmp/xbmcwrapper")
    except FileExistsError:
        pass
    try:
        os.mkfifo("/tmp/xbmcwrapper/input_cmd")
    except FileExistsError:
        pass

    abort = False
    with open("/tmp/xbmcwrapper/output", 'a') as output:
        LOG("### Python wrapper ### File opened !")
        while not abort:
            pipe = open("/tmp/xbmcwrapper/input_cmd", "r")
            cmd = ''.join(pipe.readlines())
            pipe.close()
            if cmd == "exit\n":
                LOG("### Python wrapper ### Exiting")
                abort = True
            else:
                if cmd.startswith("eval\n"):
                    cmd = cmd.replace("eval\n", "", 1)
                    exec(cmd)
                else:
                    LOG("### Python wrapper ### {0}".format(cmd.strip()))
                    try:
                        returned = eval(cmd, {"sys.stderr" : output})
                    except Exception as eval_exception:
                        returned = "Exception raised during evaluation : {0}".format(eval_exception)
                    output.write("Input : < {0} >\n\tReturned : < {1} >\n\n".format(cmd.strip(),
                        returned))
                    output.flush()

    os.unlink("/tmp/xbmcwrapper/input_cmd")
    return 0

if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.13410483321987746, 'fraction_numerical': 0.0040844111640571815, 'mean_word_length': 1.6358744394618834, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3977187', 'n_tokens_mistral': 842, 'n_tokens_neox': 823, 'n_words': 217}