Skip to content

Commit 779958d

Browse files
committed
deploy: 4d2ca19
1 parent 49e337c commit 779958d

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed

hands_on/__init__.py

Whitespace-only changes.

hands_on/init_repo.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
3+
__requires_git__ = False
4+
__requires_github__ = False
5+
6+
7+
def download():
8+
os.makedirs("things")

new-hands-on.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import json
2+
import os
3+
import pathlib
4+
import sys
5+
import textwrap
6+
from dataclasses import dataclass
7+
from typing import Dict, List, Literal, Optional
8+
9+
10+
@dataclass
11+
class HandsOnConfig:
12+
hands_on_name: str
13+
requires_git: bool
14+
requires_github: bool
15+
16+
17+
def confirm(prompt: str, default: bool) -> bool:
18+
str_result = input(f"{prompt} (defaults to {'y' if default else 'N'}) [y/N]: ")
19+
bool_value = default if str_result.strip() == "" else str_result.lower() == "y"
20+
return bool_value
21+
22+
23+
def prompt(prompt: str, default: str) -> str:
24+
str_result = input(f"{prompt} (defaults to '{default}'): ")
25+
if str_result.strip() == "":
26+
return default
27+
return str_result.strip()
28+
29+
30+
def get_exercise_config() -> HandsOnConfig:
31+
hands_on_name = input("Hands-on name: ")
32+
requires_git = confirm("Requires Git?", True)
33+
requires_github = confirm("Requires Github?", True)
34+
35+
return HandsOnConfig(
36+
hands_on_name=hands_on_name,
37+
requires_git=requires_git,
38+
requires_github=requires_github,
39+
)
40+
41+
42+
def create_download_py_file(config: HandsOnConfig) -> None:
43+
with open(f"{config.hands_on_name}.py", "w") as download_script_file:
44+
download_script = f"""
45+
import subprocess
46+
from sys import exit
47+
from typing import List, Optional
48+
49+
__requires_git__ = {config.requires_git}
50+
__requires_github__ = {config.requires_github}
51+
52+
53+
def run_command(command: List[str], verbose: bool) -> Optional[str]:
54+
try:
55+
result = subprocess.run(
56+
command,
57+
capture_output=True,
58+
text=True,
59+
check=True,
60+
)
61+
if verbose:
62+
print(result.stdout)
63+
return result.stdout
64+
except subprocess.CalledProcessError as e:
65+
if verbose:
66+
print(e.stderr)
67+
exit(1)
68+
69+
70+
def setup(verbose: bool = False):
71+
pass
72+
"""
73+
download_script_file.write(textwrap.dedent(download_script).lstrip())
74+
75+
76+
def main():
77+
config = get_exercise_config()
78+
os.chdir("hands_on")
79+
create_download_py_file(config)
80+
81+
82+
if __name__ == "__main__":
83+
main()

new.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
#!/bin/bash
22

3-
python new-exercise.py
3+
echo "Do you want to create a hands-on or an exercise? (hands-on/exercise, h/e)"
4+
read choice
5+
6+
case "$choice" in
7+
"hands-on" | "h" | "H")
8+
python new-hands-on.py
9+
;;
10+
"exercise" | "e" | "E")
11+
python new-exercise.py
12+
;;
13+
*)
14+
echo "Invalid choice. Please enter 'hands-on' (h) or 'exercise' (e)."
15+
;;
16+
esac

0 commit comments

Comments
 (0)