コード例 #1
0
ファイル: judge.py プロジェクト: frarteaga/judge
def sanity_check():
    # Don't allow starting up without wbox/cptbox, saves cryptic errors later on
    if os.name == 'nt':
        try:
            import wbox
        except ImportError:
            print >> sys.stderr, "wbox must be compiled to grade!"
            return False

        # DMOJ needs to be run as admin on Windows
        import ctypes
        if ctypes.windll.shell32.IsUserAnAdmin() == 0:
            print >> sys.stderr, "can't start, the DMOJ judge must be ran as admin"
            return False
    else:
        try:
            import cptbox
        except ImportError:
            print >> sys.stderr, "cptbox must be compiled to grade!"
            return False

        # However running as root on Linux is a Bad Idea
        if os.getuid() == 0:
            startup_warnings.append('running the judge as root can be potentially unsafe, '
                                    'consider using an unprivileged user instead')

    # _checker implements standard checker functions in C
    # we fall back to a Python implementation if it's not compiled, but it's slower
    try:
        from checkers import _checker
    except ImportError:
        startup_warnings.append('native checker module not found, compile _checker for optimal performance')
    return True
コード例 #2
0
ファイル: judge.py プロジェクト: aurpine/DMOJ-judge
def sanity_check():
    # Don't allow starting up without wbox/cptbox, saves cryptic errors later on
    if os.name == 'nt':
        try:
            import wbox
        except ImportError:
            print >> sys.stderr, "wbox must be compiled to grade!"
            return False

        # DMOJ needs to be run as admin on Windows
        import ctypes
        if ctypes.windll.shell32.IsUserAnAdmin() == 0:
            print >> sys.stderr, "can't start, the DMOJ judge must be ran as admin"
            return False
    else:
        try:
            import cptbox
        except ImportError:
            print >> sys.stderr, "cptbox must be compiled to grade!"
            return False

        # However running as root on Linux is a Bad Idea
        if os.getuid() == 0:
            startup_warnings.append('running the judge as root can be potentially unsafe, '
                                    'consider using an unprivileged user instead')

    # _checker implements standard checker functions in C
    # we fall back to a Python implementation if it's not compiled, but it's slower
    try:
        from checkers import _checker
    except ImportError:
        startup_warnings.append('native checker module not found, compile _checker for optimal performance')
    return True
コード例 #3
0
ファイル: judge.py プロジェクト: uwapcs/DMOJ-judge
def sanity_check():
    # Don't allow starting up without wbox/cptbox, saves cryptic errors later on
    if os.name == 'nt':
        from judgeenv import env

        # Nasty crashes will happen if tempdir isn't specified.
        if not env.tempdir:
            print(
                'must specify `tempdir` in judge config to a directory readable by all users'
            )
            return False

        try:
            from .wbox import _wbox
        except ImportError:
            print('wbox must be compiled to grade!', file=sys.stderr)
            return False

        # DMOJ needs to be run as admin on Windows
        import ctypes
        if ctypes.windll.shell32.IsUserAnAdmin() == 0:
            print("can't start, the DMOJ judge must be ran as admin",
                  file=sys.stderr)
            return False
    else:
        try:
            from .cptbox import _cptbox
        except ImportError:
            print('cptbox must be compiled to grade!', file=sys.stderr)
            return False

        # However running as root on Linux is a Bad Idea
        if os.getuid() == 0:
            startup_warnings.append(
                'running the judge as root can be potentially unsafe, '
                'consider using an unprivileged user instead')

    # _checker implements standard checker functions in C
    # we fall back to a Python implementation if it's not compiled, but it's slower
    try:
        from .checkers import _checker
    except ImportError:
        startup_warnings.append(
            'native checker module not found, compile _checker for optimal performance'
        )
    return True
コード例 #4
0
 def __init__(self):
     global startup_warnings
     self.current_submission = None
     self.current_grader = None
     self.current_submission_thread = None
     self._terminate_grading = False
     if Observer is not None:
         handler = SendProblemsHandler(self)
         self._monitor = monitor = Observer()
         for dir in get_problem_roots():
             monitor.schedule(handler, dir, recursive=True)
         try:
             monitor.start()
         except OSError:
             startup_warnings.append('failed to start filesystem monitor')
             self._monitor = None
     else:
         self._monitor = None
コード例 #5
0
ファイル: judge.py プロジェクト: frarteaga/judge
 def __init__(self):
     global startup_warnings
     self.current_submission = None
     self.current_grader = None
     self.current_submission_thread = None
     self._terminate_grading = False
     if Observer is not None and not judgeenv.no_watchdog:
         handler = SendProblemsHandler(self)
         self._monitor = monitor = Observer()
         for dir in get_problem_roots():
             monitor.schedule(handler, dir, recursive=True)
         try:
             monitor.start()
         except OSError:
             startup_warnings.append('failed to start filesystem monitor')
             self._monitor = None
     else:
         self._monitor = None
コード例 #6
0
ファイル: judge.py プロジェクト: tanujdeqode/judge-server
def sanity_check():
    if os.name == 'nt':
        print('cannot run judge on Windows', file=sys.stderr)
        return False
    else:
        # Don't allow starting up without cptbox, saves cryptic errors later on
        try:
            from .cptbox import _cptbox  # noqa: F401, we want to see if this imports
        except ImportError:
            print('cptbox must be compiled to grade!', file=sys.stderr)
            return False

        # However running as root on Linux is a Bad Idea
        if os.getuid() == 0:
            startup_warnings.append('running the judge as root can be potentially unsafe, '
                                    'consider using an unprivileged user instead')

        # Our sandbox filter is long but simple, so we can see large improvements
        # in overhead by enabling the BPF JIT for seccomp.
        bpf_jit_path = '/proc/sys/net/core/bpf_jit_enable'
        if os.path.exists(bpf_jit_path):
            with open(bpf_jit_path, 'r') as f:
                if f.read().strip() != '1':
                    startup_warnings.append('running without BPF JIT enabled, consider running '
                                            '`echo 1 > /proc/sys/net/core/bpf_jit_enable` '
                                            'to reduce sandbox overhead')

    # _checker implements standard checker functions in C
    # we fall back to a Python implementation if it's not compiled, but it's slower
    try:
        from .checkers import _checker  # noqa: F401, we want to see if this imports
    except ImportError:
        startup_warnings.append('native checker module not found, compile _checker for optimal performance')
    return True
コード例 #7
0
ファイル: judge.py プロジェクト: dyna-dot/DMOJ-judge
def sanity_check():
    # Don't allow starting up without wbox/cptbox, saves cryptic errors later on
    if os.name == 'nt':
        from judgeenv import env

        # Nasty crashes will happen if tempdir isn't specified.
        if not env.tempdir:
            print(
                'must specify `tempdir` in judge config to a directory readable by all users'
            )
            return False

        try:
            from .wbox import _wbox
        except ImportError:
            print('wbox must be compiled to grade!', file=sys.stderr)
            return False

        # DMOJ needs to be run as admin on Windows
        import ctypes
        if ctypes.windll.shell32.IsUserAnAdmin() == 0:
            print("can't start, the DMOJ judge must be ran as admin",
                  file=sys.stderr)
            return False
    else:
        try:
            from .cptbox import _cptbox
        except ImportError:
            print('cptbox must be compiled to grade!', file=sys.stderr)
            return False

        # However running as root on Linux is a Bad Idea
        if os.getuid() == 0:
            startup_warnings.append(
                'running the judge as root can be potentially unsafe, '
                'consider using an unprivileged user instead')

        # Our sandbox filter is long but simple, so we can see large improvements
        # in overhead by enabling the BPF JIT for seccomp.
        bpf_jit_path = '/proc/sys/net/core/bpf_jit_enable'
        if os.path.exists(bpf_jit_path):
            with open(bpf_jit_path, 'r') as f:
                if f.read().strip() != '1':
                    startup_warnings.append(
                        'running without BPF JIT enabled, consider running '
                        '`echo 1 > /proc/sys/net/core/bpf_jit_enable` '
                        'to reduce sandbox overhead')

    # _checker implements standard checker functions in C
    # we fall back to a Python implementation if it's not compiled, but it's slower
    try:
        from .checkers import _checker
    except ImportError:
        startup_warnings.append(
            'native checker module not found, compile _checker for optimal performance'
        )
    return True
コード例 #8
0
ファイル: judge.py プロジェクト: DMOJ/judge
def sanity_check():
    # Don't allow starting up without wbox/cptbox, saves cryptic errors later on
    if os.name == 'nt':
        from judgeenv import env

        # Nasty crashes will happen if tempdir isn't specified.
        if not env.tempdir:
            print('must specify `tempdir` in judge config to a directory readable by all users')
            return False

        try:
            from .wbox import _wbox
        except ImportError:
            print('wbox must be compiled to grade!', file=sys.stderr)
            return False

        # DMOJ needs to be run as admin on Windows
        import ctypes
        if ctypes.windll.shell32.IsUserAnAdmin() == 0:
            print("can't start, the DMOJ judge must be ran as admin", file=sys.stderr)
            return False
    else:
        try:
            from .cptbox import _cptbox
        except ImportError:
            print('cptbox must be compiled to grade!', file=sys.stderr)
            return False

        # However running as root on Linux is a Bad Idea
        if os.getuid() == 0:
            startup_warnings.append('running the judge as root can be potentially unsafe, '
                                    'consider using an unprivileged user instead')

        # Our sandbox filter is long but simple, so we can see large improvements
        # in overhead by enabling the BPF JIT for seccomp.
        bpf_jit_path = '/proc/sys/net/core/bpf_jit_enable'
        if os.path.exists(bpf_jit_path):
            with open(bpf_jit_path, 'r') as f:
                if f.read().strip() != '1':
                    startup_warnings.append('running without BPF JIT enabled, consider running '
                                            '`echo 1 > /proc/sys/net/core/bpf_jit_enable` '
                                            'to reduce sandbox overhead')

    # _checker implements standard checker functions in C
    # we fall back to a Python implementation if it's not compiled, but it's slower
    try:
        from .checkers import _checker
    except ImportError:
        startup_warnings.append('native checker module not found, compile _checker for optimal performance')
    return True
コード例 #9
0
from dmoj.utils.debugger import setup_all_debuggers

setup_all_debuggers()

if os.name == 'posix':
    try:
        import readline
    except ImportError:
        pass

try:
    from watchdog.observers import Observer
    from watchdog.events import FileSystemEventHandler
except ImportError:
    startup_warnings.append(
        'watchdog module not found, install it to automatically update problems'
    )
    Observer = None

    class FileSystemEventHandler(object):
        pass


class BatchBegin(object):
    pass


class BatchEnd(object):
    pass

コード例 #10
0
ファイル: judge.py プロジェクト: frarteaga/judge
from dmoj.utils.ansi import ansi_style, strip_ansi
from dmoj.utils.debugger import setup_all_debuggers

setup_all_debuggers()

if os.name == 'posix':
    try:
        import readline
    except ImportError:
        pass

try:
    from watchdog.observers import Observer
    from watchdog.events import FileSystemEventHandler
except ImportError:
    startup_warnings.append('watchdog module not found, install it to automatically update problems')
    Observer = None


    class FileSystemEventHandler(object):
        pass


class BatchBegin(object):
    pass


class BatchEnd(object):
    pass