#!/usr/bin/env python

from json import load
from os import mkdir, path

from pycs.database.Database import Database
from pycs.frontend.WebServer import WebServer
from pycs.jobs.JobRunner import JobRunner
from pycs.util.PipelineCache import PipelineCache

if __name__ == '__main__':
    # load settings
    print('- load settings')
    with open('settings.json', 'r') as file:
        settings = load(file)

    # create projects folder
    if not path.exists('projects/'):
        mkdir('projects/')

    # initialize database
    print('- load database')
    database = Database('data.sqlite3')

    # start job runner
    print('- start job runner')
    jobs = JobRunner()

    # create pipeline cache
    print('- create pipeline cache')
    pipelines = PipelineCache(jobs)

    # start web server
    print('- start web server')
    web_server = WebServer(settings, database, jobs, pipelines)
