Mercurial > bzapi
comparison example.py @ 0:78e4757601ec
origination
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 22 Dec 2009 21:40:25 -0800 |
parents | |
children | f2147b34d6af |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78e4757601ec |
---|---|
1 import os | |
2 from datetime import datetime, timedelta | |
3 import cPickle as pickle | |
4 | |
5 import bzapi | |
6 | |
7 class Picklable(object): | |
8 def __init__(self, filename, constructor, **kwargs): | |
9 self.__filename = filename | |
10 | |
11 if not os.path.exists(filename): | |
12 self.__obj = constructor(**kwargs) | |
13 self.save() | |
14 else: | |
15 obj_file = open(filename, 'r') | |
16 self.__obj = pickle.load(obj_file) | |
17 obj_file.close() | |
18 | |
19 def save(self): | |
20 obj_file = open(self.__filename, 'w') | |
21 pickle.dump(self.__obj, obj_file) | |
22 obj_file.close() | |
23 | |
24 def __getattr__(self, attr): | |
25 if not attr.startswith('_Picklable_'): | |
26 return getattr(self.__obj, attr) | |
27 else: | |
28 return self.__dict__[attr] | |
29 | |
30 def __setattr__(self, attr, value): | |
31 if not attr.startswith('_Picklable_'): | |
32 setattr(self.__obj, attr, value) | |
33 else: | |
34 self.__dict__[attr] = value | |
35 | |
36 api = Picklable( | |
37 'example.api.pickle', | |
38 bzapi.BugzillaApi, | |
39 base_url = 'https://api-dev.bugzilla.mozilla.org/latest' | |
40 ) | |
41 | |
42 search = Picklable( | |
43 'example.cached-search.pickle', | |
44 bzapi.CachedSearch, | |
45 api = api, | |
46 product='Mozilla Labs', | |
47 component='Jetpack' | |
48 ) | |
49 | |
50 #search.update(api) | |
51 | |
52 #print len([bug for bug in search.bugs.itervalues()]) | |
53 | |
54 #print search.bugs.values()[12]['summary'] | |
55 | |
56 #print api.get('/bug/510339/history') | |
57 | |
58 #print api.get('/bug', | |
59 # product='Mozilla Labs', component='Jetpack', | |
60 # changed_after=now-timedelta(minutes=60)) |