-
Notifications
You must be signed in to change notification settings - Fork 1
/
tee.py
35 lines (27 loc) · 866 Bytes
/
tee.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
'''
maroon models - simplified object-relational mapper for Python and MongoDB
by Jeremy Kelley <[email protected]> and Jeff McGee <[email protected]>
'''
try:
import simplejson as json
except:
import json
import itertools
#We do not extend MaroonDB because we want to call the methods in self._db
class TeeDB(object):
def __init__(self, path, db):
self._db = db
self._f = open(path,'a')
def _log(self,model):
print>>self._f,json.dumps(model.to_d())
def bulk_save_models(self, models, *args):
for model in models:
self._log(model)
self._f.flush()
return self._db.bulk_save_models(models, *args)
def save(self, model):
self._log(model)
self._f.flush()
return self._db.save(model)
def __getattr__(self,name):
return getattr(self._db,name)