Commit 19955b36 authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH
Browse files

more server fixes

parent a37e2a7e
Pipeline #19701 failed with stages
in 53 minutes and 49 seconds
...@@ -37,6 +37,7 @@ import subprocess ...@@ -37,6 +37,7 @@ import subprocess
import simplejson import simplejson
from flask import request
from flask_restful import Resource from flask_restful import Resource
import logging import logging
...@@ -77,7 +78,7 @@ class Layout(Resource): ...@@ -77,7 +78,7 @@ class Layout(Resource):
data = request.get_json() data = request.get_json()
if data != None and 'toolchain' in data: if data != None and 'toolchain' in data:
from beat.core.toolchain import Toolchain from beat.core.toolchain import Toolchain
obj = Toolchain(config.path, data['toolchain']) obj = Toolchain(self.config.path, data['toolchain'])
diagram = obj.dot_diagram(is_layout=True) diagram = obj.dot_diagram(is_layout=True)
diagram.format = 'json' diagram.format = 'json'
return diagram.pipe().decode() return diagram.pipe().decode()
...@@ -140,11 +141,14 @@ class Environments(Resource): ...@@ -140,11 +141,14 @@ class Environments(Resource):
class Templates(Resource): class Templates(Resource):
"""Endpoint for generating template files""" """Endpoint for generating template files"""
def __init__(self, config):
self.config = config
def post(self): def post(self):
data = request.get_json() data = request.get_json()
entity = data.pop('entity') entity = data.pop('entity')
name = data.pop('name') name = data.pop('name')
generate_python_template(entity, name, **data) utils.generate_python_template(entity, name, self.config, **data)
def path_to_dict(path): def path_to_dict(path):
...@@ -373,7 +377,7 @@ def gen_endpoint(entity): ...@@ -373,7 +377,7 @@ def gen_endpoint(entity):
# not copied) # not copied)
obj = o['obj'] obj = o['obj']
copy_obj_name = o['copiedObjName'] copy_obj_name = o['copiedObjName']
write_json(config, entity, obj, 'create', copy_obj_name) write_json(self.config, entity, obj, 'create', copy_obj_name)
return self.refresh() return self.refresh()
def put(self): def put(self):
...@@ -382,13 +386,13 @@ def gen_endpoint(entity): ...@@ -382,13 +386,13 @@ def gen_endpoint(entity):
if not isinstance(obj_list, list): if not isinstance(obj_list, list):
obj_list = [obj_list] obj_list = [obj_list]
for obj in obj_list: for obj in obj_list:
write_json(config, entity, obj, 'update') write_json(self.config, entity, obj, 'update')
return self.refresh() return self.refresh()
def delete(self): def delete(self):
"""Deletes an object""" """Deletes an object"""
obj = request.get_json() obj = request.get_json()
write_json(config, entity, obj, 'delete') write_json(self.config, entity, obj, 'delete')
return self.refresh() return self.refresh()
Endpoint.__name__ = entity Endpoint.__name__ = entity
......
...@@ -113,7 +113,7 @@ def main(user_input=None): ...@@ -113,7 +113,7 @@ def main(user_input=None):
api.add_resource(Home, '/') api.add_resource(Home, '/')
api.add_resource(Layout, '/layout', resource_class_kwargs={'config': config}) api.add_resource(Layout, '/layout', resource_class_kwargs={'config': config})
api.add_resource(Templates, '/templates') api.add_resource(Templates, '/templates', resource_class_kwargs={'config': config})
api.add_resource(Environments, '/environments') api.add_resource(Environments, '/environments')
for entity in VALID_ENTITIES: for entity in VALID_ENTITIES:
api.add_resource(gen_endpoint(entity), '/' + entity, api.add_resource(gen_endpoint(entity), '/' + entity,
......
...@@ -56,7 +56,7 @@ def generate_database(views=None): ...@@ -56,7 +56,7 @@ def generate_database(views=None):
""" """
views = views or ['View'] views = views or ['View']
template = env.get_template('database.jinja2') template = ENV.get_template('database.jinja2')
return template.render(views=views) return template.render(views=views)
...@@ -78,7 +78,7 @@ def generate_library(uses=None): ...@@ -78,7 +78,7 @@ def generate_library(uses=None):
""" """
uses = uses or {} uses = uses or {}
template = env.get_template('library.jinja2') template = ENV.get_template('library.jinja2')
return template.render(uses=uses) return template.render(uses=uses)
...@@ -103,19 +103,19 @@ def generate_algorithm(has_parameters=False, uses=None): ...@@ -103,19 +103,19 @@ def generate_algorithm(has_parameters=False, uses=None):
""" """
uses = uses or {} uses = uses or {}
template = env.get_template('algorithm.jinja2') template = ENV.get_template('algorithm.jinja2')
return template.render(uses=uses, has_parameters=has_parameters) return template.render(uses=uses, has_parameters=has_parameters)
TEMPLATE_FUNCTION = dict( TEMPLATE_FUNCTION = dict(
database = generate_database, databases=generate_database,
library = generate_library, libraries=generate_library,
algorithm = generate_algorithm, algorithms=generate_algorithm,
) )
"""Functions for template instantiation within beat.editor""" """Functions for template instantiation within beat.editor"""
def generate_python_template(entity, name, **kwargs): def generate_python_template(entity, name, config, **kwargs):
"""Generates a template for a BEAT entity with the given named arguments """Generates a template for a BEAT entity with the given named arguments
...@@ -126,7 +126,7 @@ def generate_python_template(entity, name, **kwargs): ...@@ -126,7 +126,7 @@ def generate_python_template(entity, name, **kwargs):
s = TEMPLATE_FUNCTION[entity](**kwargs) s = TEMPLATE_FUNCTION[entity](**kwargs)
resource_path = os.path.join(get_prefix(), entity) resource_path = os.path.join(config.path, entity)
file_path = os.path.join(resource_path, name) + '.py' file_path = os.path.join(resource_path, name) + '.py'
with open(file_path, 'w') as f: f.write(s) with open(file_path, 'w') as f: f.write(s)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment