def drop_pade_db(): click.echo( click.style('[...] Droping Pade tables in selected data base.', fg='red')) from pade.web.flask_server import db db.drop_all() click.echo( click.style('[ok_] Tables droped in selected data base', fg='green'))
def start_loop(session, debug=False): """ Lança o loop do twisted integrado com o loop do Qt se a opção GUI for verdadeira, se não lança o loop do Twisted """ # instancia o factory do agente AMS e chama o metodo listenTCP # do Twisted para o agente AMS amsFactory = AgentManagementFactory(session.ams['port'], debug) twisted.internet.reactor.listenTCP(session.ams['port'], amsFactory) # instancia a classe que lança o processo # com o servidor web com o aplicativo Flask p1 = FlaskServerProcess() p1.daemon = True p1.start() db.drop_all() db.create_all() # registra uma nova sessão no banco de dados s = Session(name=session.name, date=datetime.datetime.now(), state = 'Ativo') db.session.add(s) db.session.commit() # registra os agentes no banco de dados i = 1 agents_db = list() for agent in session.agents: twisted.internet.reactor.callLater(i, listen_agent, agent) a = Agent(name=agent.aid.localname, session_id=s.id, date=datetime.datetime.now(), state = 'Ativo') agents_db.append(a) i += 0.2 db.session.add_all(agents_db) db.session.commit() # registra os usuarios no banco de dados users_db = list() for user in session.users: u = User(username=user['username'], email=user['email'], password=user['password'], session_id=s.id) users_db.append(u) db.session.add_all(users_db) db.session.commit() # lança o loop do Twisted twisted.internet.reactor.run()
def _initialize_database(self): db.create_all() # searches in the database if there is a session with # this name db_session = Session.query.filter_by(name=self.name).first() # in case there is not a session with this name if db_session is None: # clear out the database and creates new registers db.drop_all() db.create_all() # registers a new session in the database db_session = Session(name=self.name, date=datetime.datetime.now(), state='Active') db.session.add(db_session) db.session.commit() # instantiates AMS agent and calls listenTCP method # from Twisted to launch the agent ams_agent = AMS(host=self.ams['name'], port=self.ams['port'], session=db_session, debug=self.ams_debug) reactor.listenTCP(ams_agent.aid.port, ams_agent.agentInstance) # registers the users, in case they exist, in the database if len(self.users) != 0: users_db = list() for user in self.users: u = User(username=user['username'], email=user['email'], password=user['password'], session_id=db_session.id) users_db.append(u) db.session.add_all(users_db) db.session.commit() # in case there is a session with this name else: self._verify_user_in_session(db_session)
def _initialize_database(self): db.create_all() # searches in the database if there is a session with # this name self.session = Session.query.filter_by(name=self.session_name).first() # in case there is not a session with this name if self.session is None: # clear out the database and creates new registers db.drop_all() db.create_all() # registers a new session in the database self.session = Session(name=self.session_name, date=datetime.now(), state='Active') db.session.add(self.session) db.session.commit() reactor.listenTCP(self.aid.port, self.agentInstance) # registers the users, in case they exist, in the database if len(self.users) != 0: users_db = list() for user in self.users: u = User(username=user['username'], email=user['email'], password=user['password'], session_id=self.session.id) users_db.append(u) db.session.add_all(users_db) db.session.commit() # in case there is a session with this name else: self._verify_user_in_session(self.session)