12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- from glob import glob
- from json import load, dump
- from os import path, mkdir
- from time import time
- from uuid import uuid1
- from pycs import ApplicationStatus
- class ProjectManager:
- def __init__(self, app_status: ApplicationStatus):
- # TODO create projects folder if it does not exist
- # find projects
- for folder in glob('projects/*'):
- # load project.json
- with open(path.join(folder, 'project.json'), 'r') as file:
- project = load(file)
- project['status'] = 'close'
- app_status['projects'].append(project)
- # subscribe to changes
- app_status['projects'].subscribe(self.update)
- def update(self, data):
- # detect project to create
- for i in range(len(data)):
- if data[i]['status'] == 'create':
- # create dict representation
- uuid = str(uuid1())
- data[i] = {
- 'id': uuid,
- 'status': 'close',
- 'name': data[i]['name'],
- 'description': data[i]['description'],
- 'created': int(time()),
- 'access': 0,
- 'pipeline': {
- 'model-distribution': data[i]['model']
- }
- }
- # create project directory
- folder = path.join('projects', uuid)
- mkdir(folder)
- # create project.json
- with open(path.join(folder, 'project.json'), 'w') as file:
- dump(data[i], file, indent=4)
- # detect project to load
- to_load = list(filter(lambda x: x['status'] == 'load', data))
- for project in to_load:
- # TODO actually load pipeline
- project['status'] = 'open'
- project['access'] = time()
|