Added functionality for default datasets.

Incorporated dataset selector into test creation.
This commit is contained in:
2021-11-28 17:28:14 +00:00
parent e0eda9df49
commit e6b37ce453
11 changed files with 350 additions and 85 deletions

View File

@ -1,5 +1,4 @@
import os
from shutil import rmtree
import pathlib
from json import dump, loads
from datetime import datetime
@ -11,16 +10,16 @@ def check_data_folder_exists():
if not os.path.exists(app.config['DATA_FILE_DIRECTORY']):
pathlib.Path(app.config['DATA_FILE_DIRECTORY']).mkdir(parents='True', exist_ok='True')
def check_current_indicator():
if not os.path.isfile(os.path.join(app.config['DATA_FILE_DIRECTORY'], '.current.txt')):
open(os.path.join(app.config['DATA_FILE_DIRECTORY'], '.current.txt'),'w').close()
def check_default_indicator():
if not os.path.isfile(os.path.join(app.config['DATA_FILE_DIRECTORY'], '.default.txt')):
open(os.path.join(app.config['DATA_FILE_DIRECTORY'], '.default.txt'),'w').close()
def make_temp_dir(file):
if not os.path.isdir('tmp'):
os.mkdir('tmp')
if os.path.isfile(f'tmp/{file.filename}'):
os.remove(f'tmp/{file.filename}')
file.save(f'tmp/{file.filename}')
def get_default_dataset():
check_default_indicator()
default_file_path = os.path.join(app.config['DATA_FILE_DIRECTORY'], '.default.txt')
with open(default_file_path, 'r') as default_file:
default = default_file.read()
return default
def check_json_format(file):
if not '.' in file.filename:
@ -42,9 +41,9 @@ def validate_json_contents(file):
return False
return True
def store_data_file(file):
def store_data_file(file, default:bool=None):
from admin.views import get_id_from_cookie
check_current_indicator()
check_default_indicator()
timestamp = datetime.utcnow()
filename = '.'.join([timestamp.strftime('%Y%m%d%H%M%S'),'json'])
filename = secure_filename(filename)
@ -53,7 +52,10 @@ def store_data_file(file):
data = loads(file.read())
data['meta']['timestamp'] = timestamp.strftime('%Y-%m-%d %H%M%S')
data['meta']['author'] = get_id_from_cookie()
data['meta']['tests'] = []
with open(file_path, 'w') as _file:
dump(data, _file, indent=4)
with open(os.path.join(app.config['DATA_FILE_DIRECTORY'], '.current.txt'), 'w') as _file:
_file.write(filename)
dump(data, _file, indent=2)
if default:
with open(os.path.join(app.config['DATA_FILE_DIRECTORY'], '.default.txt'), 'w') as _file:
_file.write(filename)
return filename