示例#1
0
 def run(self, execute, in_file, out_file):
     in_file = os.path.abspath(in_file)
     out_file = os.path.abspath(out_file)
     with build_context('cpp') as context:
         context.add_dependency(execute, '/main')
         result = context.run_command('./main',
                                      limits=self.run_limits,
                                      redirect_stdin=in_file,
                                      redirect_stdout=out_file)
         return self.parse_run_result(*result)
示例#2
0
 def run(self, execute, in_file, out_file):
     in_file = os.path.abspath(in_file)
     out_file = os.path.abspath(out_file)
     with build_context('python3') as context:
         context.add_dependency(execute, '/main.py')
         command = config['RunCommand']['PY3'].format(execute='main.py')
         result = context.run_command(command,
                                      limits=self.run_limits,
                                      redirect_stdin=in_file,
                                      redirect_stdout=out_file)
         return self.parse_run_result(*result)
示例#3
0
 def judge_run(self, execute, in_file, out_file, real_out_file):
     with build_context('python') as context:
         context.add_writable_folder('/workspace')
         context.add_dependency(in_file, '/workspace/in')
         context.add_dependency(out_file, '/workspace/out')
         context.add_dependency(real_out_file, '/workspace/real_out')
         context.add_dependency(execute, '/workspace/main.py')
         command = 'python -S {execute} in out real_out'.format(
             execute='main.py')
         outs, errs, code, stat = context.run_command(
             command, limits=self.judge_limits, chdir='/workspace')
         result = self.parse_run_result(outs, errs, code, stat)
         if result['status'] is None:
             return outs
         return None
示例#4
0
 def run(self, execute, in_file, out_file):
     in_file = os.path.abspath(in_file)
     out_file = os.path.abspath(out_file)
     with build_context('java') as context:
         context.add_dependency(
             os.path.join(os.path.dirname(__file__),
                          '../conf/java/java_run.policy'), '/java.policy')
         context.add_dependency(execute, '/target.jar')
         command = config['RunCommand']['JAVA'].format(execute='target.jar',
                                                       name=self.class_name)
         result = context.run_command(command,
                                      limits=self.run_limits,
                                      redirect_stdin=in_file,
                                      redirect_stdout=out_file)
         return self.parse_run_result(*result)
示例#5
0
 def compile(self, source, target):
     if self.class_name is None:
         return {
             'status': JudgeStatus.CompileError,
             'info': "Public Class Not Found"
         }
     with build_context('javac') as context:
         # self.class_name = self.parse_public_class(self.code)
         # if self.class_name is None:
         # return {'status': JudgeStatus.CompileError, 'info': "Public Class Not Found"}
         source_file = '{}.java'.format(self.class_name)
         context.add_dependency(source, '/workspace/' + source_file)
         compile_command = config['CompileCommand']['JAVA'].format(
             source=source_file)
         result = context.run_command(compile_command,
                                      limits=self.compile_limits,
                                      chdir='/workspace')
         status = self.parse_compile_result(*result)
         if status:
             return status
         # The default SecurityManager of Java does not forbid using Thread,
         # we define a subclass of java.lang.SecurityManager, ThreadSecurityManager(OJSecurityManager) to do that.
         # http://stackoverflow.com/questions/15868534/why-java-security-manager-doesnt-forbid-neither-creating-new-thread-nor-start/31039987#31039987
         context.add_dependency(
             os.path.join(os.path.dirname(__file__),
                          '../conf/java/OJSecurityManager.class'),
             "/workspace/OJSecurityManager.class")
         class_files = []
         for file in os.listdir(context.real_path('/workspace')):
             if file.endswith('.class'):
                 # Add quote to filename, since java class file name maybe Main$InputReader.class, that cause shell
                 # unexpected result
                 class_files.append(shlex.quote(file))
         outs, errs, code, stat = context.run_command(
             'jar -cf target.jar {}'.format(' '.join(class_files)),
             limits=self.compile_limits,
             chdir='/workspace')
         if code or stat["EXITCODE"] or stat['EXCEED'] != "none" or stat[
                 'SIGNALED'] or stat['TERMSIG']:
             return {
                 'status': JudgeStatus.CompileError,
                 'info': "Jar class file fail"
             }
         target = os.path.abspath(target)
         if os.path.exists(target):
             os.remove(target)
         os.link(context.real_path('/workspace/target.jar'), target)
         return None
示例#6
0
 def compile(self, source, target):
     with build_context('g++') as context:
         context.add_dependency(source, '/workspace/main.cpp')
         compile_command = config['CompileCommand']['CPP'].format(
             source='main.cpp', execute='Main')
         result = context.run_command(compile_command,
                                      limits=self.compile_limits,
                                      chdir='/workspace')
         status = self.parse_compile_result(*result)
         if status:
             return status
         target = os.path.abspath(target)
         if os.path.exists(target):
             os.remove(target)
         os.link(context.real_path('/workspace/Main'), target)
         return None
示例#7
0
 def judge_run(self, execute, in_file, out_file, real_out_file):
     with build_context('java') as context:
         context.add_writable_folder('/workspace')
         context.add_dependency(in_file, '/workspace/in')
         context.add_dependency(out_file, '/workspace/out')
         context.add_dependency(real_out_file, '/workspace/real_out')
         context.add_dependency(execute, '/workspace/target.jar')
         context.add_dependency(
             os.path.join(os.path.dirname(__file__),
                          '../conf/java/java_judge.policy'),
             '/workspace/java.policy')
         command = "java -Djava.security.manager -Djava.security.policy=./java.policy -cp {jar} {name}" \
                   " in out real_out".format(jar='target.jar', name=self.class_name)
         outs, errs, code, stat = context.run_command(
             command, limits=self.judge_limits, chdir='/workspace')
         result = self.parse_run_result(outs, errs, code, stat)
         if result['status'] is None:
             return outs
         return None