-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jan Lauber <jan.lauber@protonmail.ch>
- Loading branch information
Showing
3 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export LABS_UPLOAD_URL=https://kubelab.swisscom.k8s.natron.cloud/api/collections/labs/records | ||
export EXERCISES_UPLOAD_URL=https://kubelab.swisscom.k8s.natron.cloud/api/collections/exercises/records | ||
export URL_PREFIX=https://raw.githubusercontent.com/natrontech/kubelab-workshops/main/kubernetes-basics/ | ||
export WORSHOP_DIR_PATH=/Users/janlauber/code/github.com/natrontech/kubelab-workshops/kubernetes-basics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import json | ||
import os | ||
import requests | ||
|
||
|
||
class Lab: | ||
def __init__(self, title, description, docs): | ||
self.title = title | ||
self.description = description | ||
self.docs = docs | ||
|
||
|
||
class Exercise: | ||
def __init__(self, title, description, docs, hint, solution, check, bootstrap, lab): | ||
self.title = title | ||
self.description = description | ||
self.docs = docs | ||
self.hint = hint | ||
self.solution = solution | ||
self.check = check | ||
self.bootstrap = bootstrap | ||
self.lab = lab | ||
|
||
|
||
def post_request(url, data): | ||
try: | ||
headers = {'Content-type': 'application/json'} | ||
response = requests.post(url, data=json.dumps(data), headers=headers) | ||
print(response.text) | ||
except requests.exceptions.RequestException as e: | ||
print(e) | ||
|
||
|
||
def main(): | ||
# from .env import labs_upload_url, exercises_upload_url | ||
labs_upload_url = os.environ['LABS_UPLOAD_URL'] | ||
exercises_upload_url = os.environ['EXERCISES_UPLOAD_URL'] | ||
prefix = os.environ['URL_PREFIX'] | ||
path = os.environ['WORSHOP_DIR_PATH'] | ||
|
||
labs = get_labs_from_dir(path) | ||
exercises = get_exercises_from_dir(path) | ||
|
||
# sort labs and exercises | ||
labs.sort(key=lambda x: x.title) | ||
exercises.sort(key=lambda x: x.title) | ||
|
||
for lab in labs: | ||
data = { | ||
'title': lab.title, | ||
'description': lab.description, | ||
'docs': prefix + lab.docs | ||
} | ||
post_request(labs_upload_url, data) | ||
|
||
|
||
def get_labs_from_dir(path): | ||
labs = [] | ||
for name in os.listdir(path): | ||
if os.path.isdir(os.path.join(path, name)): | ||
prename = name | ||
number = name.split("_")[0] | ||
name = name.split("_")[1:] | ||
name = " ".join(name) | ||
name = number+" "+name.title() | ||
labs.append( | ||
Lab( | ||
title=name, | ||
description=name, | ||
docs=prename+"/docs.md" | ||
) | ||
) | ||
return labs | ||
|
||
|
||
def get_exercises_from_dir(path, level=1, parent=None): | ||
exercises = [] | ||
for name in os.listdir(path): | ||
full_path = os.path.join(path, name) | ||
if os.path.isdir(full_path): | ||
if level == 2: | ||
prename = name | ||
number = name.split("_")[0] | ||
name = name.split("_")[1:] | ||
name = " ".join(name) | ||
name = number+" "+name.title() | ||
exercises.append( | ||
Exercise( | ||
title=name, | ||
description=name, | ||
docs=prename+"/docs.md", | ||
hint=prename+"/hint.md", | ||
solution=prename+"/solution.md", | ||
check=prename+"/check.sh", | ||
bootstrap=prename+"/bootstrap.sh", | ||
lab=parent | ||
) | ||
) | ||
exercises.extend(get_exercises_from_dir(full_path, level + 1, parent=name)) | ||
return exercises | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<div class="absolute top-16 bottom-0 right-0 left-0 overflow-hidden p-2"> | ||
<div class="absolute top-20 bottom-0 right-0 left-0 overflow-y-scroll p-2"> | ||
<slot /> | ||
</div> |