def main(*args, **kwargs):
    print "Time limit checker"

    tle_file = os.path.join(corrector.submission_directory(), ".time_limit_exceeded")

    if os.path.exists(tle_file):
        print "Execution took to long."
        os.unlink(tle_file)
        return (corrector.CORR_ERROR, corrector.TIME_LIMIT_EXCEEDED)
    else:
        print "Execution was within the time limit."
#!/usr/bin/python
import corrector
import os
import re

rex = re.compile(r".*ERROR SUMMARY: (\d+) errors.*")
valgrind_file = os.path.join(corrector.submission_directory(), ".valgrind_log")

def read_valgrind():
    return open(valgrind_file).read()

def error_count(data):
    arr = data.split('\n')
    match = rex.match(arr[-2])
    if match:
        number_of_errors = int(match.group(1))
    else:
        number_of_errors = 1

    return number_of_errors > 0

def sigsegv(data):
    return data.find("SIGSEGV") >= 0 

checkers = [error_count, sigsegv]

def show_error(data):
    for i in checkers:
        if i(data):
            return True
    return False
#!/usr/bin/python
import corrector
import re
import os
import optparse
import difflib

# verbatim: Compares obtained and expected output verbatim. Overrides the --ignore_pattern option.',
# ci: Case insensitive comparison (default: false)',
# ip: A regular expression that determines which characters in the output should be
#    ignored. If no pattern is specified, verbatim comparison, ignoring leading
#    and trailing whitespaces, is made.', default = None)

diff_file = os.path.join(corrector.submission_directory(), ".regex_corrector")


def show_diff():
    return not os.path.exists(diff_file)


def main(diff=False, verbatim=True, ci=False, ip=None, strip_lines=True, **kwargs):
    ip = r"[^0-9]"

    options = type(
        "", (), {"verbatim": verbatim, "ignore_pattern": ip, "case_insensitive": ci, "strip_lines": strip_lines}
    )

    try:
        res = corrector.Result()
        res.html_header = "<h4>Output comparer</h4>"
def error(p, ex, out):
    print out[0]
    print """<p>There was an error in corrector %s: %r </br>
System admin has been notified</p>"""%(p, ex)
    emailer.send_bug_report(ex, p, corrector.submission_directory())
#!/usr/bin/python
import corrector
import re
import os
import optparse
import difflib
import imp
import cgi

diff_file = os.path.join(corrector.submission_directory(), ".p_specific_corrector_diff")

MAXLINES = 1000


def show_diff():
    return not os.path.exists(diff_file)


def main(diff=False, checker="checker.py", show_inp=True, **kwargs):

    try:
        res = corrector.Result()
        # res.html_header = "<h4>Output checker</h4>"

        expected = corrector.expected()
        obtained = corrector.obtained()

        problem_dir = os.path.abspath(os.path.join(corrector.context(), "..", "..", ".."))
        checker_file = os.path.join(problem_dir, checker)
        chk = imp.load_source("chk", checker_file)
#!/usr/bin/python
import corrector
import os
import re
import subprocess
import csv
import sys

output_file = os.path.join(corrector.submission_directory(), '.nsiqcppstyle')

def urlify(s):
    return r'<a href="http://nsiqcppstyle.appspot.com/rules/%s" target="_blank">%s</a>'%(s,s.split('_',4)[-1].replace('_',' '))


def formatted_output():
    with open(output_file, 'rb') as csvfile:
        reader = csv.reader(csvfile)
        next(reader)
        
        html = []
        for row in reader:
            html.append( '%s:%s:%s (%s) %s'%(os.path.basename(row[0]), row[1], row[2], urlify(row[4]), row[3]) )
        if html:
            return corrector.output_html('\n'.join(html))
        return None    

def invade_korea(rule_file):
    args =  ' '.join([ os.path.join(corrector.home(),'bin/nsiqcppstyle/nsiqcppstyle'), '-o', output_file, '-f', rule_file, '--output=csv'] + corrector.submission_files('.cpp','.h'))
    p = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    p.wait()
    
def check_cppcheck():
    args = [ '/usr/bin/cppcheck', '--enable=style,unusedFunction,missingInclude', '--error-exitcode=1', corrector.submission_directory() ]
    p = subprocess.Popen(' '.join(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    p.wait()
    errs = p.stderr.read()
    if errs:
        for line in errs.splitlines():
            m = re.search(filename, line)
            if m:
                print '[%s]%s'%(os.path.basename(m.group(1)),m.group(2))
            else:
                print line
    return (p.returncode == 0)