Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2e60f3

Browse files
committed
improve docs
1 parent c0d0dda commit a2e60f3

9 files changed

Lines changed: 30 additions & 24 deletions

File tree

config.sql

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
BEGIN;
22

33
-- Configure which challenge instances should be displayed to users at which point in time.
4+
-- Note that times are generally UTC.
45
-- You can pass a single string argument to challenges by appending it in parentheses.
56
DELETE FROM challenges;
67
INSERT INTO challenges (cid, team, t_start, t_stop) VALUES
78
-- expired
8-
('Attendance(01.01.2018)', 0, datetime('2018-01-01 00:00:00'), datetime('2018-01-01 14:00:00')),
9+
('Basic(Example Challenge (expired))', 0, datetime('2000-01-01 00:00:00'), datetime('2011-01-01 11:11:00+01:00')),
910
-- solved
10-
('Attendance(05.01.2018)', 0, datetime('2018-01-05 00:00:00'), datetime('2018-01-05 14:00:00')),
11+
('Basic(Example Challenge (solved))', 0, datetime('now'), datetime('now','+1 month')),
1112
-- active
12-
('Attendance(' || date('now') || ')', 0, datetime('now'), datetime('now','+1 day')),
13+
('Basic(Example Challenge (active))', 0, datetime('now'), datetime('now','+1 month')),
1314
-- still invisible
14-
('Attendance(01.01.2042)', 0, datetime('2042-01-01 00:00:00'), datetime('2042-01-01 14:00:00')),
15+
('Basic(Example Challenge (appears in the future))', 0, datetime('2042-01-01 00:00:00'), datetime('2042-01-01 14:00:00')),
1516
-- Other examples
1617
('TcpServer', 1, datetime('now'), datetime('now','+1 month')),
1718
('WebServer', 1, datetime('now'), datetime('now','+1 month')),
@@ -40,19 +41,19 @@ INSERT INTO teams (tid, uid) VALUES
4041

4142
--
4243
--
43-
-- The SQL statements only serve to illustrate the r8 UI.
44+
-- The SQL statements below only serve to illustrate the r8 UI.
4445
-- In a production deployment, we would COMMIT; here and be done.
4546
--
4647
--
4748

4849
DELETE FROM flags;
4950
INSERT INTO flags (fid, cid, max_submissions) VALUES
5051
-- easy to memorize flags for testing.
51-
('expired', 'Attendance(01.01.2018)', 999999),
52-
('da', 'Attendance(' || date('now') || ')', 999999),
53-
('limited', 'Attendance(' || date('now') || ')', 0),
54-
('future', 'Attendance(01.01.2042)', 999999),
55-
('solved', 'Attendance(05.01.2018)', 1)
52+
('expired', 'Basic(Example Challenge (expired))', 999999),
53+
('active', 'Basic(Example Challenge (active))', 999999),
54+
('limited', 'Basic(Example Challenge (active))', 0),
55+
('future', 'Basic(Example Challenge (appears in the future))', 999999),
56+
('solved', 'Basic(Example Challenge (solved))', 1)
5657
;
5758

5859
DELETE FROM events;

misc/folder-example/title.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Folder Challenge
1+
Folder Example

r8/builtin_challenges/basic.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import r8
22

33

4-
class Attendance(r8.Challenge):
4+
class Basic(r8.Challenge):
55
"""
6-
Challenge type to record class attendance.
6+
A *very* basic challenge that only has a title.
7+
This can be useful to for example record class attendance.
78
"""
89
@property
910
def title(self):
10-
return f"Attendance {self.args}"
11+
return self.args

r8/builtin_challenges/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class DockerHelloWorld(r8.challenge_mixins.DockerChallenge):
10-
title = "Hello World from Docker!"
10+
title = "Docker Container Example"
1111

1212
dockerfile = Path(__file__).parent / "docker-helloworld"
1313

r8/builtin_challenges/form_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class FormExample(r8.Challenge):
7-
title = "The Fabulous Form"
7+
title = "Form Example"
88

99
async def description(self, user: str, solved: bool):
1010
return r8.util.media(None, """

r8/builtin_challenges/tcp_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class TcpServer(r8.Challenge):
88
server: asyncio.AbstractServer = None
99
address: tuple[str, int] = ("", 8001)
1010

11-
title = "2 * 3 * 7"
11+
title = "TCP Service Example"
1212

1313
challenge = b"What's the answer to life, the universe and everything?\n"
1414
response = r"42"

r8/builtin_challenges/web_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class WebServer(r8.challenge_mixins.WebServerChallenge):
7-
title = "Web Web"
7+
title = "Embedded Web Application Example"
88
address = ("", 8203)
99

1010
async def description(self, user: str, solved: bool):

r8/challenge_mixins/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def _exec(self, *cmd) -> tuple[asyncio.subprocess.Process, bytes, bytes]:
8080
err=True
8181
)
8282
if proc.returncode != 0:
83-
raise DockerError(f"Execution error.", cmd, proc, stdout, stderr)
83+
raise DockerError(f"Execution error.\ncmd={shlex.join(cmd)!r}\n{proc.returncode=}\n{stdout=}\n{stderr=}")
8484
return proc, stdout, stderr
8585

8686
async def start(self):

r8/cli/settings.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ def view():
2121

2222
@cli.command()
2323
@click.argument("key")
24-
@click.argument("value")
24+
@click.argument("value", nargs=-1)
2525
@util.with_database()
2626
def set(key, value):
2727
"""Update a setting"""
28-
try:
29-
value = json.loads(value)
30-
except json.JSONDecodeError:
31-
pass # if the value is not valid JSON, we just treat it as a string.
28+
if len(value) == 1:
29+
try:
30+
value = json.loads(value)
31+
except json.JSONDecodeError:
32+
try:
33+
value = int(value)
34+
except ValueError:
35+
pass # if the value is neither valid JSON nor an integer, we just treat it as a string.
3236
value = json.dumps(value)
3337
with r8.db:
3438
r8.db.execute("INSERT OR REPLACE INTO settings (key, value) VALUES (?,?)", (key, value))

0 commit comments

Comments
 (0)