Beispiel #1
0
    def compile_spj(cls, spj_version, src, spj_compile_config):
        spj_compile_config["src_name"] = spj_compile_config["src_name"].format(
            spj_version=spj_version)
        spj_compile_config["exe_name"] = spj_compile_config["exe_name"].format(
            spj_version=spj_version)

        spj_src_path = os.path.join(SPJ_SRC_DIR,
                                    spj_compile_config["src_name"])

        # if spj source code not found, then write it into file
        if not os.path.exists(spj_src_path):
            with open(spj_src_path, "w", encoding="utf-8") as f:
                f.write(src)
            os.chown(spj_src_path, COMPILER_USER_UID, 0)
            os.chmod(spj_src_path, 0o400)

        try:
            exe_path = Compiler().compile(compile_config=spj_compile_config,
                                          src_path=spj_src_path,
                                          output_dir=SPJ_EXE_DIR)
            os.chown(exe_path, SPJ_USER_UID, 0)
            os.chmod(exe_path, 0o500)
        # turn common CompileError into SPJCompileError
        except CompileError as e:
            raise SPJCompileError(e.message)
        return "success"
Beispiel #2
0
    def compile_spj(cls, spj_version, src, spj_compile_config):
        # format格式化特殊评判版本,也即是源文件和可执行文件的名字,目标位置在language
        spj_compile_config["src_name"] = spj_compile_config["src_name"].format(
            spj_version=spj_version)
        spj_compile_config["exe_name"] = spj_compile_config["exe_name"].format(
            spj_version=spj_version)
        #拼接设置特殊评判的源文件路径,这里是compile,非run
        spj_src_path = os.path.join(SPJ_SRC_DIR,
                                    spj_compile_config["src_name"])

        #如果特殊评判源代码不存在,然后将源代码写入到文件里面
        #这个设置的是特殊评判的源代码的路径的:spj_src_path
        if not os.path.exists(spj_src_path):
            with open(spj_src_path, "w", encoding="utf-8") as f:
                f.write(src)
            # 写入之后更改源代码的所有者,使用root才可以,0表示更改的用户组
            os.chown(spj_src_path, COMPILER_USER_UID, 0)
            #更改文件的权限,)0o400表示拥有者具有读写权限
            os.chmod(spj_src_path, 0o400)

        try:
            #编译传入的特殊评判源文件,并输出编译好的可执行文件到SPJ_EXE_DIR,以供运行使用
            exe_path = Compiler().compile(compile_config=spj_compile_config,
                                          src_path=spj_src_path,
                                          output_dir=SPJ_EXE_DIR)
            #更改执行文件的用户ID和组ID,所有者对文件的权限为0o500:拥有者具有读写和执行的权利
            os.chown(exe_path, SPJ_USER_UID, 0)
            os.chmod(exe_path, 0o500)
        # 出错的话就将普通的编译错误转换成特殊评判编译错误
        except CompileError as e:
            raise SPJCompileError(e.message)
        return "success"
Beispiel #3
0
    def compile_spj(self, spj_version, src, spj_compile_config):
        spj_compile_config["src_name"] = spj_compile_config["src_name"].format(
            spj_version=spj_version)
        spj_compile_config["exe_name"] = spj_compile_config["exe_name"].format(
            spj_version=spj_version)

        spj_src_path = os.path.join(SPJ_SRC_DIR,
                                    spj_compile_config["src_name"])

        # if spj source code not found, then write it into file
        if not os.path.exists(spj_src_path):
            with open(spj_src_path, "w") as f:
                f.write(src.encode("utf-8"))
        try:
            Compiler().compile(compile_config=spj_compile_config,
                               src_path=spj_src_path,
                               output_dir=SPJ_EXE_DIR)
        # turn common CompileError into SPJCompileError
        except CompileError as e:
            raise SPJCompileError(e.message)
        return "success"