def upgrade(): with session_scope(MYCODO_DB_PATH) as conditional_sess: for each_conditional in conditional_sess.query(Conditional).all(): try: indented_code = textwrap.indent( each_conditional.conditional_statement, ' ' * 8) cond_statement_run = pre_statement_run + indented_code cond_statement_run = cond_statement_replace(cond_statement_run) assure_path_exists(PATH_PYTHON_CODE_USER) file_run = '{}/conditional_{}.py'.format( PATH_PYTHON_CODE_USER, each_conditional.unique_id) with open(file_run, 'w') as fw: fw.write('{}\n'.format(cond_statement_run)) fw.close() except Exception as msg: print("Exception: {}".format(msg)) # Inputs with session_scope(MYCODO_DB_PATH) as input_sess: for each_input in input_sess.query(Input).all(): if each_input.device == 'PythonCode' and each_input.cmd_command: try: execute_at_creation(each_input.unique_id, each_input.cmd_command, None) except Exception as msg: print("Exception: {}".format(msg))
with session_scope(MYCODO_DB_PATH) as conditional_sess: for each_conditional in conditional_sess.query(Conditional).all(): save_conditional_code( [], each_conditional.conditional_statement, each_conditional.unique_is, conditions, actions) with session_scope(MYCODO_DB_PATH) as input_sess: for each_input in input_sess.query(Input).all(): if each_input.device == 'PythonCode' and each_input.cmd_command: try: execute_at_creation(each_input.unique_id, each_input.cmd_command, None) except Exception as msg: print("Exception: {}".format(msg)) except Exception: msg = "ERROR: post-alembic revision {}: {}".format( each_revision, traceback.format_exc()) error.append(msg) print(msg) elif each_revision == '65271370a3a9': print("Executing post-alembic code for revision {}".format( each_revision)) try: from mycodo.databases.models import Actions from mycodo.databases.models import Conditional
def upgrade(): # Conditionals with session_scope(MYCODO_DB_PATH) as conditional_sess: for each_conditional in conditional_sess.query(Conditional).all(): if each_conditional.conditional_statement: # Replace strings try: strings_replace = [ ('measure(', 'self.measure('), ('measure_dict(', 'self.measure_dict('), ('run_action(', 'self.run_action('), ('run_all_actions(', 'self.run_all_actions('), ('=message', '=self.message'), ('= message', '= self.message'), ('message +=', 'self.message +='), ('message+=', 'self.message+=') ] for each_set in strings_replace: if each_set[0] in each_conditional.conditional_statement: each_conditional.conditional_statement = each_conditional.conditional_statement.replace( each_set[0], each_set[1]) except Exception as msg: print("Exception: {}".format(msg)) conditional_sess.commit() for each_conditional in conditional_sess.query(Conditional).all(): try: indented_code = textwrap.indent( each_conditional.conditional_statement, ' ' * 8) cond_statement_run = pre_statement_run + indented_code cond_statement_run = cond_statement_replace(cond_statement_run) assure_path_exists(PATH_PYTHON_CODE_USER) file_run = '{}/conditional_{}.py'.format( PATH_PYTHON_CODE_USER, each_conditional.unique_id) with open(file_run, 'w') as fw: fw.write('{}\n'.format(cond_statement_run)) fw.close() except Exception as msg: print("Exception: {}".format(msg)) # Inputs with session_scope(MYCODO_DB_PATH) as input_sess: for each_input in input_sess.query(Input).all(): if each_input.device == 'PythonCode' and each_input.cmd_command: # Replace strings try: strings_replace = [ ('store_measurement(', 'self.store_measurement(') ] for each_set in strings_replace: if each_set[0] in each_input.cmd_command: each_input.cmd_command = each_input.cmd_command.replace( each_set[0], each_set[1]) except Exception as msg: print("Exception: {}".format(msg)) input_sess.commit() for each_input in input_sess.query(Input).all(): if each_input.device == 'PythonCode' and each_input.cmd_command: try: execute_at_creation(each_input.unique_id, each_input.cmd_command, None) except Exception as msg: print("Exception: {}".format(msg))