def all_unknown(self, message, *args, **kwargs): __callstack_var_tx__ = Transaction(name=self._transactionName) yield self.once.begin(self._transactionName) try: yield self.all.unknown(message, *args, **kwargs) yield __callstack_var_tx__.commit() except TransactionException: yield __callstack_var_tx__.rollback()
def any_unknown(self, message, *args, **kwargs): __callstack_var_tx__ = Transaction(name=self._transactionName) yield self.once.begin(name=self._transactionName) try: try: response = yield self.any.unknown(message, *args, **kwargs) except NoneOfTheObserversRespond: raise DeclineMessage yield __callstack_var_tx__.commit() raise StopIteration(response) except TransactionException: yield __callstack_var_tx__.rollback()
def parse(self, op, timeStamp): ''' Parse the inputdate from user. ''' self.detDeadlock() self.run() op = self.formalize(op) # print(op) if op.startswith('beginro'): transId = int(op[op.find('(') + 2:op.find(')')]) trans = Transaction(transId, timeStamp, readOnly=True) trans.makeVarsCopy(self.sites) self.curTrans[transId] = trans elif op.startswith('begin'): transId = int(op[op.find('(') + 2:op.find(')')]) trans = Transaction(transId, timeStamp) self.curTrans[transId] = trans elif op.startswith('recover'): siteId = int(op[op.find('(') + 1:op.find(')')]) site = self.sites[siteId] site.recover(self.sites) elif op.startswith('r'): args = op[op.find('(') + 1:op.find(')')].split(',') transId, varId = int(args[0][1:]), int(args[1][1:]) trans = self.curTrans[transId] if trans.readOnly: if trans.varsCopy[varId] is not None: print('x{}: {}'.format(varId, trans.varsCopy[varId])) else: print('T{} cannot read x{} at this time'.format( transId, varId)) else: if not trans.abort: trans.acquireReadLock(self.sites, varId) self.ops.append(['r', trans, varId]) elif op.startswith('w'): args = op[op.find('(') + 1:op.find(')')].split(',') transId, varId, value = int(args[0][1:]), int(args[1][1:]), int( args[2]) trans = self.curTrans[transId] if not trans.abort: trans.acquireWriteLock(self.sites, varId) self.ops.append(['w', trans, varId, value]) elif op.startswith('dump'): arg = op[op.find('(') + 1:op.find(')')] if arg == '': print(self.dumpAll()) elif arg.startswith('x'): varId = int(arg[1:]) print('\n'.join(self.dumpBySite(varId))) else: siteId = int(arg) print(self.sites[siteId].dump()) elif op.startswith('end'): transId = int(op[op.find('(') + 2:op.find(')')]) trans = self.curTrans[transId] if trans.abort: print('T{} aborts ({})'.format(transId, trans.reason)) else: log = trans.commit(self.sites) if log: print(log) print('T{} commits'.format(transId)) elif op.startswith('fail'): siteId = int(op[op.find('(') + 1:op.find(')')]) site = self.sites[siteId] abortSet = site.fail() for transId in abortSet: if transId in self.curTrans: self.curTrans[transId].setAbort(self.sites, self.ops, 'site down') # print('-----before------') # print(self.ops) # print('----------------') # print('input: {}, locks: {}'.format(op, self.sites[1].vars[2].locks.keys())) self.run()
return parent.find_element_by_css_selector(selector).text except NoSuchElementException: return None for hotelurl in session.query(HotelUrl).filter(HotelUrl.crawled==None): driver.get(hotelurl.hotel_url) description = driver.find_element_by_css_selector("#summary").text address = driver.find_element_by_css_selector("#hp_address_subtitle") features = driver.find_elements_by_css_selector("div.facilitiesChecklistSection") hotel_features = {} for category in features: cat = category.find_element_by_css_selector("h5").text fs = map(lambda x: x.text, category.find_elements_by_css_selector("li")) hotel_features[cat]=fs address = extract_address(address.text) opinions,hotel_grade = getOpinionsAndHotelGrade(driver,hotelurl.hotel_opinion_url) #session, hotel_url, address, hotel_grade, description, opinions, features # print description,address,hotel_features,opinions,hotel_grade transaction = Transaction(session,hotelurl,address,hotel_grade,description,opinions,hotel_features) transaction.commit()
key = args[1] value = args[2] transaction.set(key, value) elif args[0] == "GET": key = args[1] value = transaction.get(key) print value if value != None else "NULL" elif args[0] == "UNSET": key = args[1] transaction.unset(key) elif args[0] == "NUMEQUALTO": value = args[1] print str(transaction.numEqualTo(value)) elif args[0] == "BEGIN": transaction = transaction.createChild() elif args[0] == "COMMIT": transaction = transaction.commit({}) elif args[0] == "ROLLBACK": if transaction.parent != None: transaction = transaction.parent else: print "NO TRANSACTION" else: raise Exception("Bad argument passed") except: print "Command not recognized or malformed" print "Commands: SET, GET, UNSET, NUMEQUALTO, BEGIN, COMMIT, ROLLBACK, END" finally: line = sys.stdin.readline().rstrip()