Skip to content

Commit

Permalink
Merge remote-tracking branch 'noi/kompgen' into noi
Browse files Browse the repository at this point in the history
  • Loading branch information
kcvajgf committed Sep 26, 2023
2 parents 1436499 + 5f0e7ff commit 0a63b16
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cms/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# session
"Session", "ScopedSession", "SessionGen", "custom_psycopg2_connection",
# types
"CastingArray", "Codename", "Filename", "FilenameSchema",
"CastingArray", "Codename", "Username", "Filename", "FilenameSchema",
"FilenameSchemaArray", "Digest",
# base
"metadata", "Base",
Expand Down Expand Up @@ -91,7 +91,7 @@
from .session import Session, ScopedSession, SessionGen, \
custom_psycopg2_connection

from .types import CastingArray, Codename, Filename, FilenameSchema, \
from .types import CastingArray, Codename, Username, Filename, FilenameSchema, \
FilenameSchemaArray, Digest
from .base import Base
from .fsobject import FSObject, LargeObject
Expand Down
3 changes: 2 additions & 1 deletion cms/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Boolean, Integer, Float, String, Unicode, Enum, DateTime, Interval, \
BigInteger

from . import engine, metadata, CastingArray, Codename, Filename, \
from . import engine, metadata, CastingArray, Codename, Username, Filename, \
FilenameSchema, FilenameSchemaArray, Digest


Expand All @@ -46,6 +46,7 @@
Unicode: str,
String: str, # TODO Use bytes.
Codename: str,
Username: str,
Filename: str,
FilenameSchema: str,
Digest: str,
Expand Down
31 changes: 31 additions & 0 deletions cms/db/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ def bind_expression(self, bindvalue):
return sqlalchemy.cast(bindvalue, self)


class Username(TypeDecorator):
"""Check that the column uses a limited alphabet.
Namely: latin letters (upper and lowercase), arabic digits, the
underscore, the period, and the dash. It must also be non-empty.
"""

domain_name = "USERNAME"
impl = Unicode

@classmethod
def get_create_command(cls):
return DDL("CREATE DOMAIN %(domain)s VARCHAR "
"CHECK (VALUE ~ '^[A-Za-z0-9_.-]+$')",
context={"domain": cls.domain_name})

@classmethod
def get_drop_command(cls):
return DDL("DROP DOMAIN %(domain)s",
context={"domain": cls.domain_name})

event.listen(metadata, "before_create", Username.get_create_command())
event.listen(metadata, "after_drop", Username.get_drop_command())


@compiles(Username)
def compile_codename(element, compiler, **kw):
return Username.domain_name


class Codename(TypeDecorator):
"""Check that the column uses a limited alphabet.
Expand Down
4 changes: 2 additions & 2 deletions cms/db/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
Interval

from cmscommon.crypto import generate_random_password, build_password
from . import CastingArray, Codename, Base, Admin, Contest
from . import CastingArray, Codename, Username, Base, Admin, Contest


class User(Base):
Expand All @@ -60,7 +60,7 @@ class User(Base):

# Username and password to log in the CWS.
username = Column(
Codename,
Username,
nullable=False,
unique=True)
password = Column(
Expand Down
2 changes: 1 addition & 1 deletion cms/grading/steps/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def compilation_step(sandbox, commands):
sandbox.preserve_env = True
sandbox.max_processes = config.compilation_sandbox_max_processes
sandbox.timeout = config.compilation_sandbox_max_time_s
sandbox.wallclock_timeout = 2 * sandbox.timeout + 1
sandbox.wallclock_timeout = 10 * sandbox.timeout + 1
sandbox.address_space = config.compilation_sandbox_max_memory_kib * 1024

# Run the compilation commands, copying stdout and stderr to stats.
Expand Down
2 changes: 1 addition & 1 deletion cms/grading/steps/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def evaluation_step_before_run(sandbox, command,
# Set sandbox parameters suitable for evaluation.
if time_limit is not None:
sandbox.timeout = time_limit
sandbox.wallclock_timeout = 2 * time_limit + 1
sandbox.wallclock_timeout = 10 * time_limit + 1
else:
sandbox.timeout = None
sandbox.wallclock_timeout = None
Expand Down
2 changes: 1 addition & 1 deletion cms/grading/steps/trusted.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def trusted_step(sandbox, commands):
sandbox.preserve_env = True
sandbox.max_processes = config.trusted_sandbox_max_processes
sandbox.timeout = config.trusted_sandbox_max_time_s
sandbox.wallclock_timeout = 2 * sandbox.timeout + 1
sandbox.wallclock_timeout = 10 * sandbox.timeout + 1
sandbox.address_space = config.trusted_sandbox_max_memory_kib * 1024

# Run the trusted commands.
Expand Down
4 changes: 2 additions & 2 deletions cmscontrib/DumpExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from sqlalchemy.dialects.postgresql import ARRAY, CIDR, JSONB

from cms import rmtree, utf8_decoder
from cms.db import version as model_version, Codename, Filename, \
from cms.db import version as model_version, Codename, Username, Filename, \
FilenameSchema, FilenameSchemaArray, Digest, SessionGen, Contest, User, \
Task, Submission, UserTest, SubmissionResult, UserTestResult, PrintJob, \
Announcement, Participation, enumerate_files
Expand Down Expand Up @@ -113,7 +113,7 @@ def encode_value(type_, value):
return None
elif isinstance(type_, (
Boolean, Integer, Float, String, Unicode, Enum, JSONB, Codename,
Filename, FilenameSchema, Digest)):
Username, Filename, FilenameSchema, Digest)):
return value
elif isinstance(type_, DateTime):
return make_timestamp(value)
Expand Down
4 changes: 2 additions & 2 deletions cmscontrib/DumpImporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

import cms.db as class_hook
from cms import utf8_decoder
from cms.db import version as model_version, Codename, Filename, \
from cms.db import version as model_version, Codename, Username, Filename, \
FilenameSchema, FilenameSchemaArray, Digest, SessionGen, Contest, \
Submission, SubmissionResult, User, Participation, UserTest, \
UserTestResult, PrintJob, Announcement, init_db, drop_db, enumerate_files
Expand Down Expand Up @@ -98,7 +98,7 @@ def decode_value(type_, value):
return None
elif isinstance(type_, (
Boolean, Integer, Float, String, Unicode, Enum, JSONB, Codename,
Filename, FilenameSchema, Digest)):
Username, Filename, FilenameSchema, Digest)):
return value
elif isinstance(type_, DateTime):
try:
Expand Down
1 change: 1 addition & 0 deletions cmscontrib/loaders/kompgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __init__(self, input=None, output=None):
'c++': 'C++17 / g++',
'cpp': 'C++17 / g++',
'java': 'Java / JDK',
'python3.11': 'Python 3.11 / CPython',
'python3': 'Python 3 / CPython',
'pypy3': 'Python 3 / PyPy',
}
Expand Down
Binary file modified cmsranking/static/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ psycopg2>=2.8,<2.9 # http://initd.org/psycopg/articles/tag/release/
sqlalchemy>=1.3,<1.4 # http://docs.sqlalchemy.org/en/latest/changelog/index.html
netifaces>=0.10,<0.11 # https://bitbucket.org/al45tair/netifaces/src/
pycryptodomex>=3.6,<3.7 # https://github.com/Legrandin/pycryptodome/blob/master/Changelog.rst
psutil>=5.5,<5.6 # https://github.com/giampaolo/psutil/blob/master/HISTORY.rst
psutil>=5.6.1,<5.7 # https://github.com/giampaolo/psutil/blob/master/HISTORY.rst
requests>=2.22,<2.23 # https://pypi.python.org/pypi/requests
# Slightly higher version for Python 3.8 support
gevent>=1.5,<1.6 # http://www.gevent.org/changelog.html
Expand Down

0 comments on commit 0a63b16

Please sign in to comment.