Exemplo n.º 1
0
    def __init__(self, args):
        if len(args) != 6:
            raise conf.UserError(
                "Option {0} takes five arguments, but {1} is(are) given".
                format(args[0],
                       len(args) - 1))

        global _executor_dict, lang_dict

        if args[1] in lang_dict:
            raise conf.UserError("duplicated language: {0!r}".format(args[1]))

        self._name = args[1]
        self._src_ext = args[2]
        self._exe_ext = args[3]

        if args[4] == "None":
            self._compiler = None
        else:
            if args[4] not in _executor_dict:
                raise conf.UserError(
                    "unknown compiler executor {0!r} for language {1!r}".
                    format(args[4], args[1]))
            self._compiler = _executor_dict[args[4]]

        if args[5] not in _executor_dict:
            raise conf.UserError(
                "unknown program executor {0!r} for language {1!r}".format(
                    args[5], args[1]))
        self._executor = _executor_dict[args[5]]

        lang_dict[args[1]] = self
Exemplo n.º 2
0
def _set_temp_dir(arg):
    global _cmd_vars, _dir_temp, _dir_temp_abs, _prog_path, _prog_path_abs
    _dir_temp = arg[1]
    if "CHROOT_DIR" in _cmd_vars:
        if os.path.isabs(_dir_temp):
            raise conf.UserError(
                "If ChrootDir is set, Option {0} takes a relative path as argument"
                .format(arg[0]))
        _dir_temp_abs = _join_path(_cmd_vars["CHROOT_DIR"], _dir_temp)
        _dir_temp = os.path.join('/', _dir_temp)
    else:
        if not os.path.isabs(_dir_temp):
            raise conf.UserError(
                "Option {0} takes an absolute path as argument".format(arg[0]))
        _dir_temp_abs = _dir_temp

    if not os.path.isdir(_dir_temp_abs):
        raise conf.UserError(
            "path {0!r} is not a directory".format(_dir_temp_abs))

    try:
        os.chmod(
            _dir_temp_abs, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
            | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH
            | stat.S_IWOTH | stat.S_IXOTH)
    except Exception as e:
        raise conf.UserError(
            "failed to change permission for temporary directory: {0}".format(
                e))

    _prog_path = _join_path(_dir_temp, _DEFAULT_PROG_NAME)
    _prog_path_abs = _join_path(_dir_temp_abs, _DEFAULT_PROG_NAME)

    _cmd_vars["WORKDIR"] = _dir_temp
    _cmd_vars["WORKDIR_ABS"] = _dir_temp_abs
Exemplo n.º 3
0
def _set_chroot_dir(arg):
    if len(arg) == 2:
        global _cmd_vars, _dir_temp
        if _dir_temp:
            raise conf.UserError(
                "Option {0} must be set before TempDir".format(arg[0]))
        if not os.path.isabs(arg[1]):
            raise conf.UserError(
                "Option {0} takes an absolute path as argument".format(arg[0]))
        _cmd_vars["CHROOT_DIR"] = arg[1]
Exemplo n.º 4
0
def _ch_server_addr(arg):
    if len(arg) == 1:
        raise conf.UserError(
            "Option {0} must be specified in the configuration file".format(
                arg[0]))
    if len(arg) != 3:
        raise conf.UserError("Option {0} takes two arguments".format(arg[0]))
    global _server_addr, _server_port
    _server_addr = arg[1]
    _server_port = int(arg[2])
    if _server_port <= 0 or _server_port > 65535:
        raise conf.UserError("port must be between 0 and 65536")
Exemplo n.º 5
0
def _ch_set_info(arg):
    if len(arg) == 1:
        return
    if len(arg) < 3:
        raise conf.UserError("Option {0} takes at least two arguments" . format(arg[0]))
    global _info_dict
    _info_dict[arg[1]] = "\n".join(arg[2:])
Exemplo n.º 6
0
    def __init__(self, args):
        if len(args) < 4:
            raise conf.UserError(
                "Option {0} takes at least three arguments".format(args[0]))

        global _executor_dict
        if args[1] in _executor_dict:
            raise conf.UserError("duplicated executor name: {0!r}".foramt(
                args[1]))

        if args[2] not in limiter.limiter_dict:
            raise conf.UserError(
                "unknown limiter {0!r} for executor {1!r}".format(
                    args[2], args[1]))

        _executor_dict[args[1]] = self
        self._name = args[1]
        self._limiter = limiter.limiter_dict[args[2]]
        self._args = args[3:]
Exemplo n.º 7
0
    def __init__(self, args):
        if len(args) < 4:
            raise conf.UserError(
                "Option {0} takes at least three arguments".format(args[0]))

        self._name = args[1]

        if args[2] == 'socket':
            if not conf.is_unix:
                raise conf.UserError(
                    "{0}: socket method is only avaliable on Unix systems".
                    format(args[0]))
            self._type = _LIMITER_SOCKET
            try:
                self._socket_name = "orzoj-limiter-socket.{0}".format(
                    str(uuid.uuid4()))

                s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
                s.bind("\0{0}".format(self._socket_name))
                s.listen(1)
                self._socket = s
            except Exception as e:
                raise conf.UserError(
                    "[limiter {0!r}] failed to establish socket: {1}".format(
                        self._name, e))
        elif args[2] == 'file':
            self._type = _LIMITER_FILE
        else:
            raise conf.UserError(
                "unknown limiter communication method: {0!r}".format(args[2]))
        self._args = args[3:]

        global limiter_dict
        if args[0] in limiter_dict:
            raise conf.UserError("duplicated limiter name: {0!r}".format(
                args[1]))
        limiter_dict[args[1]] = self
Exemplo n.º 8
0
def _set_refresh_interval(arg):
    global _refresh_interval
    _refresh_interval = float(arg[1])
    if _refresh_interval < 1:
        raise conf.UserError("Option {0} can not be less than 1 second".format(
            arg[0]))
Exemplo n.º 9
0
def _set_port(arg):
    global _port
    _port = int(arg[1])
    if _port <= 0 or _port > 65535:
        raise conf.UserError("port must be between 0 and 65536")
Exemplo n.º 10
0
def _seg_max_bytes(arg):
    global _max_bytes
    _max_bytes = int(arg[1])
    if _max_bytes < 0:
        raise conf.UserError("{0} can't be less than 0".format(arg[0]))
Exemplo n.º 11
0
def _set_timeout(arg):
    global _timeout
    _timeout = float(arg[1])
    if _timeout <= 1:
        raise conf.UserError(
            "Option {0} can not be less than 1 second.".format(arg[0]))
Exemplo n.º 12
0
def _ch_set_ipv6(arg):
    if len(arg) > 2 or (len(arg) == 2 and arg[1]):
        raise conf.UserError("Option UseIPv6 takes no argument")
    if len(arg) == 2:
        global _use_ipv6
        _use_ipv6 = 1
Exemplo n.º 13
0
def _set_verifier_cache(arg):
    global _verifier_cache
    if not os.path.isdir(arg[1]):
        raise conf.UserError("verifier cache directory does not exist")
    _verifier_cache = arg[1]
Exemplo n.º 14
0
def _seg_backup_count(arg):
    global _backup_count
    _backup_count = int(arg[1])
    if _backup_count < 0:
        raise conf.UserError("{0} can't be less than 0".format(arg[0]))
Exemplo n.º 15
0
def _set_id_max_len(arg):
    global _id_max_len
    _id_max_len = int(arg[1])
    if _id_max_len < 1:
        raise conf.UserError("Option {0} can not be less than 1".format(
            arg[0]))
Exemplo n.º 16
0
def _ch_add_lang(args):
    if len(args) == 1:
        raise conf.UserError(
            "Option {0} must be specified in the configuration file.".format(
                args[0]))
    _Lang(args)
Exemplo n.º 17
0
def _seg_level(arg):
    global _LEVELS, _level
    if arg[1] not in _LEVELS:
        raise conf.UserError("unknown log level: {0}".format(arg[1]))
    _level = _LEVELS[arg[1]]