def send_session(path=None): session = get_session() if path is not None: session = load(path) set_session(session) emit_session(session, broadcast=False)
def post(self): try: global session requestBody = request.json additionalParams = {} if requestBody["action"] == "updateSettings": #Update this session's settings session.updateSettings(**requestBody["settings"]) elif requestBody["action"] == "undoSettings": #Go back to previous settings session.undoSettings() elif requestBody["action"] == "save": #Save the session session.save( os.path.join(session.settings["rootDir"], requestBody["path"])) elif requestBody["action"] == "load": #Load a saved session session = load( os.path.join(session.settings["rootDir"], requestBody["path"])) elif requestBody["action"] == "updatePlots": #Update this session's settings additionalParams = {"justUpdated": session.updates_available()} session.commit_updates() response = jsonify({ "statusCode": 200, "status": "Options delivered", "session": session._getJsonifiableInfo(), **additionalParams }) return response except Exception as error: print(traceback.format_exc()) return jsonify({ "statusCode": 500, "status": "Could not make perform operation on the current session", "error": str(error) })
def load_session_from_file(file_bytes, name): session = get_session() file_name, dirname, keep = _write_file(session, file_bytes, name) session = load(file_name) if isinstance(session, Session): set_session(session) emit_session(session, broadcast=True) _remove_temp_file(file_name, dirname) if not isinstance(session, Session): raise ValueError( "A session could not be loaded from the file provided.")
def test_save_and_load(self, obj=None): file_name = "./__sislsaving_test" if obj is None: obj = self._init_plot_without_warnings() obj.save(file_name) try: plot = load(file_name) except Exception as e: os.remove(file_name) raise e os.remove(file_name)