-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
36 lines (23 loc) · 707 Bytes
/
util.py
File metadata and controls
36 lines (23 loc) · 707 Bytes
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
"""Utility code."""
import time
def timeit(method):
"""Time the execution of a call."""
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
print('%r (%r, %r) took %2.2f seconds' %
(method.__name__, args, kw, te-ts))
return result
return timed
def new_rec(col_class, **kwargs):
obj = col_class()
for k, v in kwargs.items():
setattr(obj, k, v)
return obj
def get_collection_class(collection_name, db_objects):
for dbo in db_objects:
if hasattr(dbo, '__collection__') \
and dbo.__collection__ == collection_name:
return dbo
return None