Ejemplo n.º 1
0
    import argparse
    
    parser = argparse.ArgumentParser("Run tests on homework assignment")
    parser.add_argument("-v", "--verbose", action='store_true', help="Be Verbose")
    parser.add_argument("-f", "--file", type=argparse.FileType('r'), help="input file")
    parser.add_argument("-o", "--output-dir", default=".", help="output directory for reference output")
    parser.add_argument("-n", "--session-name", default="grading", help="Session name")
    args = parser.parse_args()

    myaml = yaml.load(args.file.read())
    reviewstruct = find_key('review', myaml)

    if args.verbose:
        sys.stderr.write("Found review struct: {0}\n".format(reviewstruct))

    ec = EmacsClient(servername=args.session_name)

    for (pid, project_path) in imap(shlex.split, sys.stdin):
        project_path = urllib.unquote(project_path)
        for review in reviewstruct:
            subprocess.call(['tmux', 'send-keys', '-t', 'grading:0.1', "cd \"{path}\"".format(path=os.path.realpath(project_path)), 'C-m'])
            subprocess.call(['tmux', 'send-keys', '-t', 'grading:0.1', "ls *", 'C-m'])
            if 'src' in review:
                actual_files = [ first_match(src_file) for src_file in review['src'] if first_match(src_file) ]
                for review_file in actual_files[:-1]:
                    if args.verbose:
                        sys.stderr.write("Opening {0} for review\n".format(review_file))
                    if review_file:
                        ec.open_file(review_file, nowait=True)
                    else:
                        sys.stderr.write("{0}: file not found\n".format(review['src']))
Ejemplo n.º 2
0
    parser = argparse.ArgumentParser()
    parser.add_argument("--file","-f", help="script file")
    parser.add_argument("-v","--verbose", action='store_true', help="Be verbose")

    args = parser.parse_args()

    #signal.signal(signal.SIGINT, signal_handler)

    if path.isfile(args.file):
        pargs = subprocess_args(args.file)
        (module_name,dot,ext) = args.file.partition('.')
        action = imp.load_source(module_name, args.file)
    else:
        stderr.write("{}: could not find action file\n".format(args.file))
        exit(1)
    ec = EmacsClient(servername=action.session_name())

    for line in imap(lambda x: x.strip("\" \n"), stdin):
        if path.isfile(line) or path.isdir(line):
            stderr.write("{}\n".format(line))
            if args.verbose:
                stderr.write("Running action {} with input {}\n".format(pargs, line))
            aprocess = subprocess.Popen(pargs, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            (pout,perr) = aprocess.communicate(line)
            actions = [action for action in (action.strip() for action in pout.split('\n')) if action]
            parse_actions(actions, verbose=args.verbose, ec=ec)
            stderr.write("paction error: {}\n".format(perr))
            ec.kill_all()
        else:
            stderr.write("{}: Invalid path\n".format(line))
    ec.kill_all()
Ejemplo n.º 3
0
import shlex
import os
import subprocess
from emacsclient import EmacsClient

if __name__ == '__main__':
    import argparse
    import fileinput

    parser = argparse.ArgumentParser("Review diffs generated by running compare_progs")
    parser.add_argument("-t","--tests", action='store_true', help="Assume input is list of test files (*.test)")
    parser.add_argument("files", metavar='FILE', nargs="*", help="File name to read numbers from")

    args = parser.parse_args()

    ec = EmacsClient()

    for srcfile in map(str.rstrip, fileinput.input(args.files)):
        if not args.tests:
            tfile = '.'.join([srcfile,'test'])
        else:
            tfile = srcfile
        try:
            test = None
            with open(tfile, 'rb') as f:
                test = ast.literal_eval(f.read())
            
            sys.stderr.write("Reviewing {}\n".format(f.name))
            ec.open_file(test['diff'],nowait=True)
            ec.open_file(os.path.join(test['cwd'],test['path']))
            ec.kill_all()