Added selfgenerating test template

This commit is contained in:
2020-01-29 23:18:13 +01:00
parent 7c9a080f8b
commit c24f5e2fc1
7 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
#!/usr/bin/env python3
from distutils import file_util
import os
import fileinput
import json
from sys import argv
from shutil import rmtree
#Copy CSS
file_util.copy_file('../resources/css/main.css', './resources/css/main.css')
jsonPath = './resources/js/tasksJSON.js'
jsonData = {}
jsonData['tasks'] = []
numberOfTasks = int(input('Number of tasks: '))
for i in range(0, numberOfTasks):
#Define variables
realTaskNumber = i+1
dirPath = './oppgaver/oppgave' + str(realTaskNumber) + '/'
htmlPath = dirPath + 'oppgave.html'
jsPath = dirPath + 'oppgave.js'
#Make html file
with open('./task-template/oppgave.html', 'r') as file:
data = file.read()
data = data.replace("taskNumber", str(realTaskNumber))
os.makedirs(dirPath)
with open(htmlPath, 'w') as file:
file.write(data)
#Make js file
with open(jsPath, 'w') as file:
file.write('')
#Add to JSON
jsonData['tasks'].append({
'name': 'Oppgave ' + str(realTaskNumber),
'path': str(htmlPath)
})
jsVariable = "const tasks = " + json.dumps(jsonData)
#Update JSON
with open(jsonPath, 'w') as file:
file.write(jsVariable)
#Delete the template
deleteBool = input('Delete the template? (yes/No): ')
if deleteBool == "yes":
rmtree('./task-template', ignore_errors=True)
#Delete itself
deleteBool = input('Delete the program? (yes/No): ')
if deleteBool == "yes":
os.remove(argv[0])

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test</title>
<link rel="stylesheet" href="./resources/css/main.css">
<script async src="./resources/js/tasksJSON.js"></script>
<script async src="./resources/js/linkConnector.js"></script>
</head>
<body>
<h1>Test</h1>
<div class="center">
<div class="textboxGrid"></div>
</div>
</body>
</html>

View File

View File

@@ -0,0 +1,10 @@
const taskArray = tasks.tasks;
const grid = document.getElementsByClassName("textboxGrid")[0];
for (i=0; i<taskArray.length; i++) {
let mess = '<div class=linkElement>';
mess += '<h2><a href="' + taskArray[i]["path"] + '">' + taskArray[i]["name"] + '</a></h2>';
mess += '</div>';
grid.innerHTML+=mess;
}

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Oppgave taskNumber</title>
<link rel="stylesheet" href="../resources/css/main.css">
<script async src="./script.js"></script>
</head>
<body>
<h1>Oppgave taskNumber</h1>
</body>
</html>