def _handle_FindAccountByKey(self, event): accounts = self._load() a = self._find_by_key(accounts, event.key) if a == None: kernel.queue(events.NotFound()) else: a.setEncryptionKey(event.encryption_key) kernel.queue(events.AccountFound(a))
def _has_duplicate_keys(self, accounts): keys = {} for acct in accounts: if acct.key() in keys: kernel.queue(events.DuplicateKeyError(acct.key())) return True keys[acct.key()] = 1 return False
def _handle_NewAccount(self, event): accounts = self._load() accounts.append(event.account) if self._has_duplicate_keys(accounts): return persistance.write(self._path, accounts) kernel.queue(events.Success("Account created"))
def _command_add(self, args): if len(args.args) < 3: print "usage: add account_key username password [note]" return account = Account(args.args[0], args.key) account.setUsername(args.args[1]) account.setPassword(args.args[2]) if len(args.args) > 3: account.setNote(args.args[3]) kernel.queue(events.NewAccount(account))
def _handle_DeleteAccount(self, event): accounts = self._load() a = self._find_by_key(accounts, event.key) if a == None: kernel.queue(events.NotFound()) return accounts.remove(a) persistance.write(self._path, accounts) kernel.queue(events.Success("Account removed"))
def _handle_UpdateAccountField(self, event): accounts = self._load() a = self._find_by_key(accounts, event.key) if a == None: kernel.queue(events.NotFound()) return if event.field == "password": a.setEncryptionKey(event.encryption_key) a.setPassword(event.value) else: setter = "set%s" % (event.field.title()) if hasattr(a, setter): method = getattr(a, setter) method(event.value) if self._has_duplicate_keys(accounts): return persistance.write(self._path, accounts) kernel.queue(events.Success("Account updated"))
def _command_set(self, args): if len(args.args) != 3: print "usage: set account_key field new_value" return kernel.queue(events.UpdateAccountField(args.args[0], args.args[1], args.args[2], args.key))
def _command_show(self, args): if len(args.args) == 0: print "usage: show account_key" return kernel.queue(events.FindAccountByKey(args.args[0], args.key))
def _command_rm(self, args): if len(args.args) == 0: print "usage: rm account_key" return kernel.queue(events.DeleteAccount(args.args[0]))
def _command_list(self, args): kernel.queue(events.GetAccountList())
def _handle_GetAccountList(self, event): accounts = self._load() kernel.queue(events.AccountList(accounts))