def by_id(assignment_id): session = SessionFactory() try: return session.query(Assignment).filter( Assignment.id == assignment_id).one() finally: session.close()
def by_id(uid): session = SessionFactory() try: return session.query(User).filter(User.id == uid).one() except NoResultFound: return None finally: session.close()
def by_id(mid): session = SessionFactory() try: return session.query(Match).filter(Match.id==mid).one() except NoResultFound: return None finally: session.close()
def parse_file(input_file): print("[Processing] Creating Session Factory") session_factory = SessionFactory() hdf_factory = HDFOutputFactory() parse_map = { 'bin': session_factory.session_from_rfeye_file, 'hdf5': session_factory.session_from_hdf_file, 'hdf': session_factory.session_from_hdf_file, } print("[Processing] Parsing File " + input_file) file_name = path.split(input_file)[1] file_type = file_name.split('.')[-1] print("[Processing] Parsing as '{0}' File".format(file_type)) if file_type not in parse_map: print("[Error] '{0}' is an unsupported file type!".format(file_type)) return parser = parse_map[file_type] session = parser(input_file) print("[Processing] File Successfully Parsed") output_base_name = input_file.split('.')[0] output_name = '{0}_conv.hdf5'.format(output_base_name) hdf_factory.save_session_to_hdf5(session, output_name) print("[Complete] Output File Generated Successfully!")
def set_last_online(self, when): session = SessionFactory() try: user = session.query(User).filter_by(id=self.id).one() user.last_online = when session.add(user) session.commit() finally: session.close()
def main(): #setup session = SessionFactory.get() stmt = update(Request).values(activated=False) session.execute(stmt) session.commit() session.close() while True: session = SessionFactory.get() #Get unactivated request pending_request = session.query(Request).filter_by(blocked=False, activated=False) #Insert pending request to running queue and set activated flag to True for req in pending_request: threading.Timer(req.interval_between_checks, handle_request, (req,)).start() session.close() time.sleep(3)
def handle_request(request): #create seperate session session = SessionFactory.get() #Validate that still unblocked req = session.query(Request).filter_by(request_id=request.request_id).first() if not req.blocked: if not req.activated: #if not active yet, set to activated. req.activated = True #create result req.AddResult(session) #print("Req id: {2}, Res id:{0}, activated:{1}\n".format(res.id,req.activated, req.request_id)) threading.Timer(request.interval_between_checks*5, handle_request, (request,)).start() session.close()
def __addSession(self, address, param, sessionId, monitor): status = SessionStatus() status.setId(sessionId) status.setProtocol(self.protocol) status.setParam(param) status.setAddress(address) self.IDs.append(sessionId) imp = SessionFactory.createSession(self.protocol) self.lockForSessions.acquire() session = Session(imp, status) status.setSession(session) session.registerObserver(self)#SessionGroup as the observer of session. session.registerMonitor(monitor) session.init() self.sessions.append(session) self.actionsComposite.addAction(session) self.lockForSessions.release()
def __addSession(self, address, param, sessionId, monitor): status = SessionStatus() status.setId(sessionId) status.setProtocol(self.protocol) status.setParam(param) status.setAddress(address) self.IDs.append(sessionId) imp = SessionFactory.createSession(self.protocol) self.lockForSessions.acquire() session = Session(imp, status) status.setSession(session) session.registerObserver( self) #SessionGroup as the observer of session. session.registerMonitor(monitor) session.init() self.sessions.append(session) self.actionsComposite.addAction(session) self.lockForSessions.release()
def by_id(assignment_id): session = SessionFactory() try: return session.query(Assignment).filter(Assignment.id==assignment_id).one() finally: session.close()
def get_user(cls, username): session = SessionFactory() try: user = session.query(User).filter_by(username=username).one() return user except NoResultFound: user = User(username) session.add(user) session.commit() print "Created new user entry in the database for user '{}'.".format(username) finally: session.close() # If the entry for the user was just created then retreive the committed version session = SessionFactory() try: user = session.query(User).filter_by(username=username).one() return user except NoResultFound: return None finally: session.close()
def unblockRequest(request_id): session = SessionFactory.get() req = session.query(Request).filter_by(request_id=request_id).first() req.block() session.commit()