def __init__(self, storage, config): self.storage = storage self.config = config self.values = {} self.handlers = {} try: self.values = self.storage['config'] except: pass for i in ['intrusive']: if not i in self.values: self.values[i] = False self.op = Operators(storage, config.get("modules", "op")) self.add_handler('op', self.op.config_handler) self.add_handler(['show', 'op'], self.op.show_handler)
def processRequest(rq): ops = Operators() ops.MONTHLY = rq.frequence == "month" ops.DAILY = rq.frequence == "day" if rq.accounts is not None: accounts = [Account.accounts[acc] for acc in rq.accounts] opMaths = Maths.MathsAccounts(ops, accounts, accumulate=rq.accumulate) opGraph = CSV.CSV_Cumul_Accounts(ops, accounts) else: subcategories = [SubCategory.subcategories[subcat] for subcat in rq.subcategories] opMaths = Maths.MathsSubCats(ops, subcategories, invert=rq.inverted, accumulate=rq.accumulate) opGraph = CSV.CSV_Cumul_SubCategories(ops, subcategories, invert=rq.inverted) Bank.processTransactions(ops, start=Bank.Date(*rq.start), stop=Bank.Date(*rq.stop)) return {"maths": opMaths.dump(), "graph": opGraph.raw()}
class Configuration(object): def __init__(self, storage, config): self.storage = storage self.config = config self.values = {} self.handlers = {} try: self.values = self.storage['config'] except: pass for i in ['intrusive']: if not i in self.values: self.values[i] = False self.op = Operators(storage, config.get("modules", "op")) self.add_handler('op', self.op.config_handler) self.add_handler(['show', 'op'], self.op.show_handler) def add_handler(self, command, handler=None): info = [] if type(command) == list: info = command[1:] command = command[0] if not command in self.handlers: self.handlers[command] = [] self.handlers[command] += [{'handler': handler, 'info': info}] def __call__(self, msg, nick, send_message): if msg in ['aus!', 'AUS!']: self.values['intrusive'] = False self.storage['config'] = self.values send_message(':(') return True elif msg in ['an!', 'fass!']: self.values['intrusive'] = True self.storage['config'] = self.values send_message(':)') return True else: if not self.op.is_op(nick): return False return self.passive_config(msg, nick, send_message) return False def passive_config(self, msg, nick, send_message): parts = [ x.strip() for x in msg.strip().split(' ') if x.strip() != '' ] if len(parts) == 0: return False command = parts[0] undo = False data = parts[1:] args = {'send_message': send_message, 'cmdline': msg.strip(), 'nick': nick } if command == 'no': undo = True command = parts[1] data = parts[2:] if not command in self.handlers: return False if undo and command == 'show': # "no show" is invalid return False if command != 'show': data = [ undo ] + data for handler in self.handlers[command]: if startswith(data, handler['info']): data = data[len(handler['info']):] if handler['handler'] is None: continue try: handler['handler'](*data, **args) return True except: pass def __getattr__(self, name): return self.values[name] def get(self, section, name): return self.config.get(section, name) def getint(self, section, name): return self.config.getint(section, name)