diff --git a/README.md b/README.md index 86e79bf..e2f0eb9 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,17 @@ Then, source it to enable it. cp .env.dist .env nano .env +### Configure permissions + +`var/runs` must be writeable by the application. + + +## Build CSS and JS ()for prod) + + flask assets build + + + ## Development @@ -55,7 +66,3 @@ Then, visit http://localhost:5000 > We're trying to remove the need for the `export` statements, but… -## Build CSS and JS for prod - - flask assets build - diff --git a/flaskr/controllers/main_controller.py b/flaskr/controllers/main_controller.py index 170487e..b7804b3 100644 --- a/flaskr/controllers/main_controller.py +++ b/flaskr/controllers/main_controller.py @@ -575,12 +575,13 @@ def compute(): # process the queue of estimation requests # WRITE RESULTS INTO THE DATABASE ######################################### estimation.status = StatusEnum.success - estimation.output_yaml = u"%s" % yaml_dump(results) + # estimation.output_yaml = u"%s" % yaml_dump(results) + estimation.set_output_dict(results) db.session.commit() # FINALLY, RESPOND ######################################################## - response += yaml_dump(results) + "\n" + # response += yaml_dump(results) + "\n" return _respond(response) @@ -636,7 +637,8 @@ def consult_estimation(public_id, extension): if estimation.status in unavailable_statuses: abort(404) - return estimation.output_yaml + return u"%s" % yaml_dump(estimation.get_output_dict()) + # return estimation.output_yaml elif 'csv' == extension: diff --git a/flaskr/models.py b/flaskr/models.py index d55b8f4..7c863dd 100755 --- a/flaskr/models.py +++ b/flaskr/models.py @@ -1,3 +1,6 @@ +import enum +import shelve +from os.path import join, isfile from flask_admin.contrib.sqla import ModelView from flaskr.core import generate_unique_id, models @@ -5,7 +8,10 @@ from flask_sqlalchemy import SQLAlchemy from flask_login import UserMixin, AnonymousUserMixin from werkzeug.security import generate_password_hash, check_password_hash from yaml import safe_load as yaml_load -import enum + +from content import get_path + + # These are not the emission "models" in the scientific meaning of the word. # They are the SQL Database Models. @@ -73,15 +79,36 @@ class Estimation(db.Model): return self.run_name return self.public_id + def get_output_filename(self): + runs_dir = get_path("var/runs") + return join(runs_dir, self.public_id) + + def set_output_dict(self, output): + # with shelve.open(filename=self.get_output_filename(), protocol=2) as shelf: + # shelf['output'] = output + shelf = shelve.open(filename=self.get_output_filename(), protocol=2) + shelf['output'] = output + shelf.close() + _output_dict = None def get_output_dict(self): if self._output_dict is None: if self.output_yaml is None: - self._output_dict = None + output_filename = self.get_output_filename() + if isfile(output_filename): + # with shelve.open(filename=output_filename, + # protocol=2) as shelf: + # self._output_dict = shelf['output'] + shelf = shelve.open(filename=output_filename, protocol=2) + self._output_dict = shelf['output'] + # self._output_dict = copy(shelf['output']) + shelf.close() + else: + self._output_dict = None else: self._output_dict = yaml_load(self.output_yaml) - return self._output_dict + return self._output_dict def is_one_to_one(self): return self.scenario == ScenarioEnum.one_to_one -- libgit2 0.21.2