def import_from_dict(cls, data): data['executables'] = [ Executable.import_from_dict(executable_data) for executable_data in data['executables'] ] data['executables'] = dict([(executable.filename, executable) for executable in data['executables']]) data['testcases'] = [ Testcase.import_from_dict(testcase_data) for testcase_data in data['testcases'] ] data['managers'] = [ Manager.import_from_dict(manager_data) for manager_data in data['managers'] ] data['managers'] = dict([(manager.filename, manager) for manager in data['managers']]) data['files'] = [ File.import_from_dict(file_data) for file_data in data['files'] ] data['files'] = dict([(file_.filename, file_) for file_ in data['files']]) # XXX We convert the key from str to int because it was the key # of a JSON object. data['evaluations'] = dict( (int(k), v) for k, v in data['evaluations'].iteritems()) return cls(**data)
def import_from_dict(cls, data): data["files"] = [File.import_from_dict(file_data) for file_data in data["files"]] data["files"] = dict([(file_.filename, file_) for file_ in data["files"]]) data["managers"] = [Manager.import_from_dict(manager_data) for manager_data in data["managers"]] data["managers"] = dict([(manager.filename, manager) for manager in data["managers"]]) data["executables"] = [Executable.import_from_dict(executable_data) for executable_data in data["executables"]] data["executables"] = dict([(executable.filename, executable) for executable in data["executables"]]) return cls(**data)
def import_from_dict(cls, data): data['files'] = dict( (k, File(k, v)) for k, v in data['files'].iteritems()) data['managers'] = dict( (k, Manager(k, v)) for k, v in data['managers'].iteritems()) data['executables'] = dict( (k, Executable(k, v)) for k, v in data['executables'].iteritems()) return cls(**data)
def import_from_dict(cls, data): data["executables"] = [Executable.import_from_dict(executable_data) for executable_data in data["executables"]] data["executables"] = dict([(executable.filename, executable) for executable in data["executables"]]) data["testcases"] = [Testcase.import_from_dict(testcase_data) for testcase_data in data["testcases"]] data["managers"] = [Manager.import_from_dict(manager_data) for manager_data in data["managers"]] data["managers"] = dict([(manager.filename, manager) for manager in data["managers"]]) data["files"] = [File.import_from_dict(file_data) for file_data in data["files"]] data["files"] = dict([(file_.filename, file_) for file_ in data["files"]]) # XXX We convert the key from str to int because it was the key # of a JSON object. data["evaluations"] = dict((int(k), v) for k, v in data["evaluations"].iteritems()) return cls(**data)
def put_executable(self, filename, file_obj, description=""): """Add the specified compiled executable to the submission, overwriting, if necessary, the previous entry with the same filename. The file is read from the file-like object file_obj. """ digest = self.file_cacher.put_file(self, description=description, file_obj=file_obj) if filename in self.submission.executables: del self.submission.executables[filename] self.submission.sa_session.add( Executable(digest, filename, self.submission))
def import_from_dict(cls, data): data['files'] = [File.import_from_dict(file_data) for file_data in data['files']] data['files'] = dict([(file_.filename, file_) for file_ in data['files']]) data['managers'] = [Manager.import_from_dict(manager_data) for manager_data in data['managers']] data['managers'] = dict([(manager.filename, manager) for manager in data['managers']]) data['executables'] = [Executable.import_from_dict(executable_data) for executable_data in data['executables']] data['executables'] = dict([(executable.filename, executable) for executable in data['executables']]) return cls(**data)
def import_from_dict(cls, data): data['files'] = dict( (k, File(k, v)) for k, v in data['files'].iteritems()) data['managers'] = dict( (k, Manager(k, v)) for k, v in data['managers'].iteritems()) data['executables'] = dict( (k, Executable(k, v)) for k, v in data['executables'].iteritems()) data['testcases'] = dict( (k, Testcase(*v)) for k, v in data['testcases'].iteritems()) # XXX We convert the key from str to int because it was the key # of a JSON object. data['evaluations'] = dict( (int(k), v) for k, v in data['evaluations'].iteritems()) return cls(**data)
def import_from_dict(cls, data): data['executables'] = [Executable.import_from_dict(executable_data) for executable_data in data['executables']] data['executables'] = dict([(executable.filename, executable) for executable in data['executables']]) data['testcases'] = [Testcase.import_from_dict(testcase_data) for testcase_data in data['testcases']] data['managers'] = [Manager.import_from_dict(manager_data) for manager_data in data['managers']] data['managers'] = dict([(manager.filename, manager) for manager in data['managers']]) data['files'] = [File.import_from_dict(file_data) for file_data in data['files']] data['files'] = dict([(file_.filename, file_) for file_ in data['files']]) return cls(**data)
def compile(self): """See TaskType.compile.""" # Detect the submission's language. The checks about the # formal correctedness of the submission are done in CWS, # before accepting it. language = self.job.language # TODO: here we are sure that submission.files are the same as # task.submission_format. The following check shouldn't be # here, but in the definition of the task, since this actually # checks that task's task type and submission format agree. if len(self.job.files) != 1: self.job.success = True self.job.compilation_success = False self.job.text = "Invalid files in submission" logger.warning("Submission contains %d files, expecting 1" % len(self.job.files)) return True # Create the sandbox sandbox = create_sandbox(self) self.job.sandboxes.append(sandbox.path) # Prepare the source files in the sandbox files_to_get = {} format_filename = self.job.files.keys()[0] source_filenames = [] # Stub. source_filenames.append("stub.%s" % language) files_to_get[source_filenames[1]] = \ self.job.managers["stub.%s" % language].digest # User's submission. source_filenames.append(format_filename.replace("%l", language)) files_to_get[source_filenames[0]] = \ self.job.files[format_filename].digest for filename, digest in files_to_get.iteritems(): sandbox.create_file_from_storage(filename, digest) # Prepare the compilation command executable_filename = format_filename.replace(".%l", "") command = get_compilation_command(language, source_filenames, executable_filename) # Run the compilation operation_success, compilation_success, text, plus = \ compilation_step(sandbox, command) # Retrieve the compiled executables self.job.success = operation_success self.job.compilation_success = compilation_success self.job.plus = plus self.job.text = text if operation_success and compilation_success: digest = sandbox.get_file_to_storage( executable_filename, "Executable %s for %s" % (executable_filename, self.job.info)) self.job.executables[executable_filename] = \ Executable(digest, executable_filename) # Cleanup delete_sandbox(sandbox)
def compile(self): """See TaskType.compile.""" # Detect the submission's language. The checks about the # formal correctedness of the submission are done in CWS, # before accepting it. language = self.job.language header = HEADERS_MAP[language] # TODO: here we are sure that submission.files are the same as # task.submission_format. The following check shouldn't be # here, but in the definition of the task, since this actually # checks that task's task type and submission format agree. if len(self.job.files) != 2: self.job.success = True self.job.compilation_success = False self.job.text = "Invalid files in submission" logger.warning("Submission contains %d files, expecting 2" % len(self.job.files)) return True # First and only one compilation. sandbox = create_sandbox(self) self.job.sandboxes.append(sandbox.path) files_to_get = {} # User's submissions and headers. source_filenames = [] for filename, _file in self.job.files.iteritems(): source_filename = filename.replace("%l", language) source_filenames.append(source_filename) files_to_get[source_filename] = _file.digest # Headers. header_filename = filename.replace("%l", header) source_filenames.append(header_filename) files_to_get[header_filename] = \ self.job.managers[header_filename].digest # Manager. manager_filename = "manager.%s" % language source_filenames.append(manager_filename) files_to_get[manager_filename] = \ self.job.managers[manager_filename].digest # Manager's header. manager_filename = "manager.%s" % header source_filenames.append(manager_filename) files_to_get[manager_filename] = \ self.job.managers[manager_filename].digest for filename, digest in files_to_get.iteritems(): sandbox.create_file_from_storage(filename, digest) # Get compilation command and compile. executable_filename = "manager" command = get_compilation_command(language, source_filenames, executable_filename) operation_success, compilation_success, text, plus = \ compilation_step(sandbox, command) # Retrieve the compiled executables self.job.success = operation_success self.job.compilation_success = compilation_success self.job.plus = plus self.job.text = text if operation_success and compilation_success: digest = sandbox.get_file_to_storage( executable_filename, "Executable %s for %s" % (executable_filename, self.job.info)) self.job.executables[executable_filename] = \ Executable(digest, executable_filename) # Cleanup delete_sandbox(sandbox)
def compile(self): """See TaskType.compile.""" # Detect the submission's language. The checks about the # formal correctedness of the submission are done in CWS, # before accepting it. language = self.job.language # TODO: here we are sure that submission.files are the same as # task.submission_format. The following check shouldn't be # here, but in the definition of the task, since this actually # checks that task's task type and submission format agree. if len(self.job.files) != 1: self.job.success = True self.job.compilation_success = False self.job.text = "Invalid files in submission" logger.error("Submission contains %d files, expecting 1" % len(self.job.files)) return True # Create the sandbox sandbox = create_sandbox(self) self.job.sandboxes.append(sandbox.path) # Prepare the source files in the sandbox files_to_get = {} format_filename = self.job.files.keys()[0] source_filenames = [] source_filenames.append(format_filename.replace("%l", language)) files_to_get[source_filenames[0]] = \ self.job.files[format_filename].digest # If a grader is specified, we add to the command line (and to # the files to get) the corresponding manager. The grader must # be the first file in source_filenames. if self.job.task_type_parameters[0] == "grader": source_filenames.insert(0, "grader.%s" % language) files_to_get["grader.%s" % language] = \ self.job.managers["grader.%s" % language].digest # Also copy all *.h and *lib.pas graders for filename in self.job.managers.iterkeys(): if filename.endswith('.h') or \ filename.endswith('lib.pas'): files_to_get[filename] = \ self.job.managers[filename].digest for filename, digest in files_to_get.iteritems(): sandbox.create_file_from_storage(filename, digest) # Prepare the compilation command executable_filename = format_filename.replace(".%l", "") command = get_compilation_command(language, source_filenames, executable_filename) # Run the compilation operation_success, compilation_success, text, plus = \ compilation_step(sandbox, command) # Retrieve the compiled executables self.job.success = operation_success self.job.compilation_success = compilation_success self.job.plus = plus self.job.text = text if operation_success and compilation_success: digest = sandbox.get_file_to_storage( executable_filename, "Executable %s for %s" % (executable_filename, self.job.info)) self.job.executables[executable_filename] = \ Executable(executable_filename, digest) # Cleanup delete_sandbox(sandbox)