-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_local.py
37 lines (27 loc) · 1007 Bytes
/
db_local.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import logging
class LocalDB:
def __init__(self):
self.db = {}
def add_rule(self, name, rule):
if self.is_rule_avaliable(name):
error_message = "Couldn't create new rule, rule named by {0} already exists.".format(name)
logging.error(error_message)
raise NameError(error_message)
self.db[name] = []
self.db[name].append(rule)
return True
def delete_rule(self, name):
if not self.is_rule_avaliable(name):
return False
self.db.__delitem__(name)
return True
def is_rule_avaliable(self, name):
return name in self.db.keys()
def get_flow(self, name):
if not self.is_rule_avaliable(name):
error_message = "Rule '{0}' not found.".format(name)
logging.error(error_message)
raise KeyError(error_message)
return self.db[name]
def get_rules(self):
return self.db.keys()