class runSync(QThread): """Thread for syncing the package database. :param QThread: Parent class. """ def __init__(self, mw): """Initialize new sync thread. :param mw: MainWindow that created this class. """ QThread.__init__(self) self.mw = mw def run(self): """Run sync thread. """ self.t = Transaction() self.t.sync() return def begin(self): """Begin new Thread. """ self.start()
class runQuery(QThread): """Emits update(Transaction()) when complete. :Param QThread: Parent class. """ def __init__(self, mw): QThread.__init__(self) self.mw = mw def run(self): """Runs query in a seperate thread. """ self.t = Transaction() self.t.query_string = str(self.mw.ui.queryEdit.text()) self.t.query(self.t.query_string) self.emit(SIGNAL('update(PyQt_PyObject)'), self.t) return def begin(self): """Begin new query thread. """ self.start()
def test_account_total_is_updated(self): tr_1 = Transaction("credit", 10, "Money transfer") tr_2 = Transaction("debit", 5, "Purchase") self.service.save_transaction(tr_1) self.service.save_transaction(tr_2) self.assertEqual(self.service.get_account_summary(), 5)
def fixTransactionId(self): if len(self.__transactions) > 0: max = 0 for transaction in self.__transactions: if max <= transaction.getId(): max = transaction.getId() + 1 Transaction.setTransactionId(max)
def by_parent(self, parent, **kwargs): """Returns a tuple of dicts (see Transaction.get_all()). Use order key argument for sort order""" order = kwargs.pop('order', None) if not order: order = '-datetime' obj = Transaction(CALENDARDB).query_by_property_simple(parent = parent, order = order, **kwargs) return obj.get_all()
def btnAddActionPerformed(self): customerId = self.__txtCustomerId.get() itemId = self.__txtItemId.get() number = self.__txtNumber.get() employeeId = self.__txtEmployeeId.get() if len(customerId) > 0 and len(itemId) > 0 and len(number) > 0 and len( employeeId) > 0: try: customer = Customer(customerId, "", "", "") item = Item(itemId, "", "", "") employee = Employee(employeeId, "", "", "", "") if self.__customers.__contains__(customer) \ and self.__items.__contains__(item) and\ self.__employees.__contains__(employee): cIndex = self.__customers.index(customer) iIndex = self.__items.index(item) eIndex = self.__employees.index(employee) transaction = Transaction("", self.__customers[cIndex], self.__items[iIndex], number, self.__employees[eIndex]) transaction.fixId() self.__parent.addTransactionCallBack(transaction) messagebox.showinfo("Success", "A new transaction has been added") self.showDefaultText() else: messagebox.showerror("Error", "This information does not exist!") except Exception: messagebox.showerror("Error", "Invalid information format!") else: messagebox.showerror("Error", "Input fields cannot be left blank!")
def __by_name_and_parent(self, name, parent): logging.error(parent) logging.error(name) task = Transaction(TASKDB).query_by_property_simple(parent = parent, name = name) if not task.obj(): return (None, None) thing = Thing(task.obj()) return (task, thing)
def commitInstalls(self): """Installs programs marked as such. """ for app in self.installList.values(): self.commitWin.setLabel(QLabel(str('Installing ' + app['Name']))) trans = Transaction() try: trans.upgrade(app) except: pass
def commitUpgrades(self): """Upgrades programs marked as such. """ for app in self.upgradeList.values(): try: self.commitWin.setLabel(QLabel(str('Upgrading ' + app['Name']))) trans = Transaction() trans.upgrade(app) except: pass
def commitRemoves(self): """Removes programs marked as such. """ for app in self.removeList.values(): try: self.commitWin.setLabel(QLabel(str('Removing ' + app['Name']))) trans = Transaction() trans.remove(app) except: pass
def new(self, name, owner): grp = Transaction(GROUPDB).set_new(name=name, owner=owner) grp.commit() thing = Thing(grp.obj()) for t in GROUP_THINGS_DEFAULT: setattr(thing, t, GROUP_THINGS_DEFAULT[t]) thing.members[owner] = GROUP_PERMISSIONS_OWNER thing.commit() self.grp = grp self.thing = thing
def by_name(self, name): t = Transaction(GROUPDB).query(name=name) if len(t) == 0: return None t = t[0] self.key = t.pop("__key__") self._properties = t self._things.update(Thing(self.key).get()) Cache().set(GROUPDB, name, (self._properties, self._things, self.key)) return self
def new(self, name, pw, email): password = make_pw_hash(name, pw) usr = Transaction(USERDB).set_new(password = password, name = name, email = email) self.usr = usr usr.commit() thing = Thing(usr.obj()) for t in USER_THINGS_DEFAULT: setattr(thing, t, USER_THINGS_DEFAULT[t]) self.thing = thing self.thing.commit() return self
def clearChanges(self): """Clears all changes that have not been commited. """ self.ui.queryList.clear() self.installList.clear() self.removeList.clear() self.upgradeList.clear() t = Transaction() self.installed = t.getInstalled() self.upgrades = {} self.handleChanges()
def markUpgrades(self): """Finds all packages that can be updated, and marks them for \ updating. """ t = Transaction() self.upgrades = t.toBeUpgraded() newT = Transaction() upgrades = newT.toBeUpgraded() for app in upgrades: if app['Name'] not in self.installList: self.upgradeList[app['Name']] = app
def test_transaction_is_saved_by_id(self): tr_1 = Transaction("credit", 10, "Money transfer") tr_2 = Transaction("debit", 5, "Purchase") saved_tr_1 = self.service.save_transaction(tr_1) saved_tr_2 = self.service.save_transaction(tr_2) retrieved_tr_1 = self.service.get_transaction_by_id(1) retrieved_tr_2 = self.service.get_transaction_by_id(2) self.assertEqual(saved_tr_1, retrieved_tr_1) self.assertEqual(saved_tr_2, retrieved_tr_2) self.assertNotEqual(retrieved_tr_1, retrieved_tr_2)
def createTransaction(pre_out_ids, publicAddrToValueArray): tx_ins = __get_tx_ins(pre_out_ids) tx_outs = __get_tx_outs(publicAddrToValueArray) tx = Transaction(Constants.VERSION, tx_ins, tx_outs, Constants.LOCK_TIME, None, 0) if len(tx_ins) != 0: tx = signTx(tx, pre_out_ids) tx.check() if verify(tx): insert(tx) # 广播新交易 return tx
def applyChanges(self): """Displays changes and commits them. """ if os.geteuid() != 0: self.notroot = notRoot(self) QMessageBox.open(self.notroot) return self.handleChanges() t = Transaction() changes = t.changeList(self.installList, self.upgradeList, self.removeList) self.cWin = ChangeWin(self) QObject.connect(self.cWin, SIGNAL('accepted()'), self.commitChanges) QObject.connect(self.cWin, SIGNAL('rejected()'), self.noChanges) self.cWin.setChanges(changes) self.cWin.show()
def createFirstTransaction(publicAddrToValueArray): tx_in = TransactionIn.coinbase_tx_in() tx_ins = [] tx_ins.append(tx_in) tx_outs = __get_tx_outs(publicAddrToValueArray) tx = Transaction(Constants.VERSION, tx_ins, tx_outs, Constants.LOCK_TIME, None, 0) if len(tx_ins) != 0: tx = signTx(tx) tx.check() if verify(tx): insert(tx) # 广播新交易 return tx
def new(self, parent, **kwargs): name = kwargs.pop('name') description = kwargs.pop('description') task = Transaction(TASKDB).set_new(parent,key_name = name, name = name, description = description) task.commit() thing = Thing(task.obj()) for t in TASK_THINGS_DEFAULT: setattr(thing, t, TASK_THINGS_DEFAULT[t]) for kw in kwargs: setattr(thing, kw, kwargs[kw]) thing.commit() self._task = task self._thing = thing self.all(parent, _update = True) return self
def parse(f): tx_type, = parse_struct("L", f) if 0x01 == tx_type: tx = Transaction.parse(f) elif 0x02 == tx_type: tx = TransactionCF.parse(f) return tx
def main(): parser = argparse.ArgumentParser( description="Add a transaction to tx cache.") parser.add_argument( "tx_id_or_path", nargs="+", help= 'The id of the transaction to fetch from web services or the path to it.' ) args = parser.parse_args() TX_RE = re.compile(r"^[0-9a-fA-F]{64}$") tx_db = get_tx_db() for p in args.tx_id_or_path: if TX_RE.match(p): tx = tx_db.get(h2b_rev(p)) if not tx: parser.error("can't find Transact ion with id %s" % p) else: f = open(p, "rb") try: if f.name.endswith("hex"): f = io.BytesIO(codecs.getreader("hex_codec")(f).read()) tx = Transaction.parse(f) except Exception: parser.error("can't parse %s" % f.name) tx_db[tx.hash()] = tx print("cached %s" % tx.id())
def create_debit(self, amount, description): account_amount = self.get_account_summary() if account_amount - amount < 0: raise NegativeTotalError(amount, account_amount) tr = Transaction("debit", amount, description) return self.db.save_transaction(tr)
def __init__(self, parent): object.__setattr__(self, 'things_dict' , {}) object.__setattr__(self, 'things_obj', None) object.__setattr__(self, 'changed', []) object.__setattr__(self, 'parent', None) self.things_obj = Transaction(THINGDB, True).query_by_ancestor(parent) self.parent = parent if self.things_obj: things = self.things_obj.get_all() for t in things: self.things_dict[t['name']] = t['value'] else: self.things_obj = Transaction(THINGDB, True) self.things_dict = DEFAULT_THING for key in self.things_dict: self.changed.append(key)
def run(self): """Runs query in a seperate thread. """ self.t = Transaction() self.t.query_string = str(self.mw.ui.queryEdit.text()) self.t.query(self.t.query_string) self.emit(SIGNAL('update(PyQt_PyObject)'), self.t) return
def deserialize_hello_bank_input_file(file_path: str) -> List[Transaction]: transaction_list: List[Transaction] = [] with open(file_path, 'r') as f: reader = csv.reader(f, delimiter=";") next(reader) # skip header for row in reader: date: datetime = make_date_from_string(row[0]) transaction_list.append( Transaction(date, row[1], row[2], row[3], float(row[4].replace(",", ".").replace(" ", "")))) return transaction_list
def __init__(self, app): """Initialize the window. :param app: Parent Qt application. """ QMainWindow.__init__(self) self.app = app self.ui=Ui_MainWindow() self.ui.setupUi(self) self.makeConnections() self.installList = {} self.upgradeList = {} self.removeList = {} self.changeFont = QFont() self.changeFont.setBold(True) self.Font = QFont() self.Font.setBold(False) t = Transaction() self.installed = t.getInstalled() self.upgrades = {}
def __getSearchResultSingle(c): tmp = c.fetchone() if tmp == None: return None parentBlockId = tmp[4] parentTxId = tmp[1] txs_in = TransactionInDao.search(parentBlockId, parentTxId) txs_out = TransactionOutDao.search(parentBlockId, parentTxId) unspents = unspents_from_db(txs_in) if tmp[7] == 1: tx = Transaction(tmp[2], txs_in, txs_out, tmp[3], unspents, tmp[6], tmp[0]) else: tx = TransactionCF(CFHeader(tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14]), tmp[2], txs_in, txs_out, tmp[3], unspents, tmp[6], tmp[0]) return tx
def __getSearchResult(c): txs = [] for tmp in c.fetchall(): parentBlockId = tmp[4] parentTxId = tmp[1] txs_in = TransactionInDao.search(parentBlockId, parentTxId) txs_out = TransactionOutDao.search(parentBlockId, parentTxId) unspents = unspents_from_db(txs_in) if tmp[7] == 1: tx = Transaction(tmp[2], txs_in, txs_out, tmp[3], unspents, tmp[6], tmp[0]) else: tx = TransactionCF(CFHeader(tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14]), tmp[2], txs_in, txs_out, tmp[3], unspents, tmp[6], tmp[0]) txs.append(tx) return txs
def readTransactionTable(self): self.__transactions = [] sql = "SELECT * FROM transactions" self.__cursor.execute(sql) records = self.__cursor.fetchall() for row in records: id = str(row[0]) customerId = str(row[1]) itemId = str(row[3]) number = str(row[5]) employeeId = str(row[7]) cIndex = self.__customers.index(Customer(customerId, "", "", "")) iIndex = self.__items.index(Item(itemId, "", "", "")) eIndex = self.__employees.\ index(Employee(employeeId, "", "", "", "")) transaction = Transaction(id, self.__customers[cIndex], self.__items[iIndex], number, self.__employees[eIndex]) self.__transactions.append(transaction) return self.__transactions
def __by_name(self, name): grp = Transaction(GROUPDB).query_by_property_simple(name = name) if not grp.obj(): return (None, None) thing = Thing(grp.obj()) return (grp, thing)
def test_transaction_is_saved(self): tr = Transaction("debit", 10, "Money transfer") self.service.save_transaction(tr) self.assertEqual(len(self.service.get_all_transactions()), 1)
def all(self, parent): t = Transaction(TASKDB).query_by_ancestor(parent) if t: return t.get_all() return []
class Thing(object): things_dict = {} things_obj = None changed = [] parent = None def __init__(self, parent): object.__setattr__(self, 'things_dict' , {}) object.__setattr__(self, 'things_obj', None) object.__setattr__(self, 'changed', []) object.__setattr__(self, 'parent', None) self.things_obj = Transaction(THINGDB, True).query_by_ancestor(parent) self.parent = parent if self.things_obj: things = self.things_obj.get_all() for t in things: self.things_dict[t['name']] = t['value'] else: self.things_obj = Transaction(THINGDB, True) self.things_dict = DEFAULT_THING for key in self.things_dict: self.changed.append(key) def get_value(self, key): if key not in self.things_dict: if key in DEFAULT_THING: self.things_dict[key] = DEFAULT_THING[key] self.changed.append(key) else: self.things_dict[key] = None return None return self.things_dict[key] def set_value(self, key, value): self.things_dict[key] = value self.changed.append(key) def add_value(self, thing_key, dkey, value): """adds to a existing dict or creates one, but doesnt create new thing value pair""" if thing_key in self.things_dict: dic = self.things_dict[thing_key] if type(dic) != type({}): dic = {} dic[dkey] = value self.things_dict[thing_key] = dic self.changed.append(thing_key) return True return False def remove_value(self, thing_key, dkey): """removes dict entry from a thing value """ if thing_key in self.things_dict: dic = self.things_dict[thing_key] if type(dic) != type({}): return dic.pop(dkey, None) def commit(self, force=False): """commits all changes to the DB, or forces everything if force == True""" if len(self.changed) > 0 or force: self.things_obj.set_all(self.things_dict, self.parent) logging.error('commited!!!!!!!!') def __getattr__(self, name): return self.get_value(name) def __setattr__(self, name, value): if name in self.__dict__: self.__dict__[name] = value else: self.set_value(name, value) logging.error('SETVALUES!!!!' + name) def __getstate__(self): return self.__dict__ def __setstate__(self, d): self.__dict__.update(d)
def create_credit(self, amount, description): tr = Transaction("credit", amount, description) return self.db.save_transaction(tr)
def delete_active(self,parent, taskname): """ Deletes the active entry """ obj = Transaction(CALENDARDB).query_by_property_simple(parent = parent, task = taskname, status = 'Active') if obj.obj(): obj.obj().delete()
def set_status(self, parent, key, status): """ Sets the DB entry for parent/key pair to status""" obj = Transaction(CALENDARDB).query_by_property_simple(parent = parent, key_name = key) obj.status = status obj.commit() return obj
def run(self): """Run sync thread. """ self.t = Transaction() self.t.sync() return
__author__ = 'CSPF' from . config import app,db_path,db from model.Users import User from model.Account import Account from model.Transaction import Transaction from os import stat,path if not path.exists(db_path): #first time -default password db.create_all() user = User("mammoth","mammoth") user.id = 100000 user.create() user1 = User("test","test") user1.create() account = Account(user.id,"13371111",100000) account.create() account1 = Account(user1.id,"13371112",400000) account1.create() first_transaction = Transaction(user.id,10000,13371111,13371112,remarks="Salary",transaction_details="User to User 1 (1000)") first_transaction.insert() from . import controller
def __by_name(self, name): usr = Transaction(USERDB).query_by_property_simple(name = name) if usr.obj() == None: return (None, None) thing = Thing(usr.obj()) return (usr, thing)