Skip to content

Commit 77271d3

Browse files
committed
[staging-intervention] Setup exercise
1 parent f2928f8 commit 77271d3

File tree

8 files changed

+108
-0
lines changed

8 files changed

+108
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"exercise_name": "staging-intervention",
3+
"tags": [
4+
"git-restore"
5+
],
6+
"requires_git": true,
7+
"requires_github": false,
8+
"base_files": {},
9+
"exercise_repo": {
10+
"repo_type": "local",
11+
"repo_name": "intervention",
12+
"repo_title": null,
13+
"create_fork": null,
14+
"init": true
15+
}
16+
}

staging_intervention/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# staging-intervention
2+
3+
You are checking the attendance of your employees (indicated by staging a file)
4+
but you realize some employees have checked in but did not appear in person.
5+
6+
## Task
7+
8+
Unstage the attendance files of the following employees: Josh, Adam, Mary.
9+
10+
Keep everyone else's attendance file staged.
11+

staging_intervention/__init__.py

Whitespace-only changes.

staging_intervention/download.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
import pathlib
3+
import subprocess
4+
import textwrap
5+
from sys import exit
6+
from typing import List, Optional
7+
8+
9+
def run_command(command: List[str], verbose: bool) -> Optional[str]:
10+
try:
11+
result = subprocess.run(
12+
command,
13+
capture_output=True,
14+
text=True,
15+
check=True,
16+
)
17+
if verbose:
18+
print(result.stdout)
19+
return result.stdout
20+
except subprocess.CalledProcessError as e:
21+
if verbose:
22+
print(e.stderr)
23+
exit(1)
24+
25+
26+
def create_or_update_file(
27+
filepath: str | pathlib.Path, contents: Optional[str] = None
28+
) -> None:
29+
if os.path.dirname(filepath) != "":
30+
os.makedirs(os.path.dirname(filepath), exist_ok=True)
31+
if contents is None:
32+
open(filepath, "a").close()
33+
else:
34+
with open(filepath, "w") as file:
35+
file.write(textwrap.dedent(contents).lstrip())
36+
37+
38+
def setup(verbose: bool = False):
39+
crew = [
40+
"josh.txt",
41+
"adam.txt",
42+
"mary.txt",
43+
"jane.txt",
44+
"charlie.txt",
45+
"kristen.txt",
46+
"alice.txt",
47+
"john.txt",
48+
]
49+
for member in crew:
50+
create_or_update_file(member)
51+
52+
run_command(["git", "add", "."], verbose)

staging_intervention/tests/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from git_autograder import GitAutograderTestLoader
2+
3+
from ..verify import verify
4+
5+
REPOSITORY_NAME = "staging-intervention"
6+
7+
loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)
8+
9+
10+
def test():
11+
with loader.load("specs/base.yml", "start"):
12+
pass

staging_intervention/verify.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from git_autograder import (
2+
GitAutograderOutput,
3+
GitAutograderExercise,
4+
GitAutograderStatus,
5+
)
6+
7+
8+
def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
9+
# INSERT YOUR GRADING CODE HERE
10+
11+
return exercise.to_output([], GitAutograderStatus.SUCCESSFUL)

0 commit comments

Comments
 (0)