- 19D07B2CC67C9BFD80A99EA29C8B9064D30253381E6AFE2A4CB6BB30D329D6A92258D4D9671588896D71B0619973604C07312FE005F1E926A955EFBE40784A52
+ 302F32CC4525B593ED2B8E61AE3610003F5811F59778E1085B3E6CB28DD87646D77758A48B7BB7643D41D7602524B2CB35F2D7C9D96FC1D3E4F5136CD5A1A6F8
blatta/lib/state.py
(6 . 6)(6 . 10)
97 import datetime
98 from itertools import chain
99
100 KNOBS=({'max_bounces': 3,
101 'embargo_interval': 1,
102 'rubbish_interval': 10})
103
104 class State(object):
105 __instance = None
106 @staticmethod
(48 . 11)(52 . 43)
108 cursor.execute("create table if not exists dedup_queue(\
109 hash text not null,\
110 created_at datetime default current_timestamp)")
111 cursor.execute("create table if not exists knobs(\
112 name text not null,\
113 value text not null)")
114 State.__instance = self
115
116 def cursor(self):
117 return self.conn.cursor()
118
119 def get_knobs(self):
120 cursor = self.cursor()
121 results = cursor.execute("select name, value from knobs order by name asc").fetchall()
122 knobs = {}
123 for result in results:
124 knobs[result[0]] = result[1]
125 for key in KNOBS.keys():
126 if not knobs.get(key):
127 knobs[key] = KNOBS[key]
128 return knobs
129
130 def get_knob(self, knob_name):
131 cursor = self.cursor()
132 result = cursor.execute("select value from knobs where name=?", (knob_name,)).fetchone()
133 if result:
134 return result[0]
135 elif KNOBS.get(knob_name):
136 return KNOBS.get(knob_name)
137 else:
138 return None
139
140 def set_knob(self, knob_name, knob_value):
141 cursor = self.cursor()
142 result = cursor.execute("select value from knobs where name=?", (knob_name,)).fetchone()
143 if result:
144 cursor.execute("update knobs set value=? where name=?", (knob_value, knob_name,))
145 else:
146 cursor.execute("insert into knobs(name, value) values(?, ?)", (knob_name, knob_value,))
147
148 def get_at(self, handle=None):
149 cursor = self.cursor()
150 at = []