Added selfgenerating test template
This commit is contained in:
56
test-template-generator/generate.py
Normal file
56
test-template-generator/generate.py
Normal 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])
|
21
test-template-generator/index.html
Normal file
21
test-template-generator/index.html
Normal 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>
|
0
test-template-generator/oppgaver/.keep
Normal file
0
test-template-generator/oppgaver/.keep
Normal file
0
test-template-generator/resources/css/.keep
Normal file
0
test-template-generator/resources/css/.keep
Normal file
10
test-template-generator/resources/js/linkConnector.js
Normal file
10
test-template-generator/resources/js/linkConnector.js
Normal 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;
|
||||
}
|
16
test-template-generator/task-template/oppgave.html
Normal file
16
test-template-generator/task-template/oppgave.html
Normal 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>
|
0
test-template-generator/task-template/script.js
Normal file
0
test-template-generator/task-template/script.js
Normal file
Reference in New Issue
Block a user