[MERGE]
[odoo/odoo.git] / bin / report / render / render.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
19 #
20 ##############################################################################
21
22 # Why doing some multi-thread instead of using OSE capabilities ?
23 # For progress bar.
24
25 #
26 # Add a transparant multi-thread layer to all report rendering layers
27 #
28
29 import threading
30
31 #
32 # TODO: method to stock on the disk
33 # Les class de reporting doivent surclasser cette classe
34 # Les seules methodes qui peuvent etre redefinies sont:
35 #     __init__
36 #     _render
37 #
38 class render(object):
39     def __init__(self, bin_datas={}, path='.'):
40         self.done = False
41         self.bin_datas = bin_datas
42         self.path = path
43     
44     def _render(self):
45         return None
46
47     def render(self):
48         self.done = False
49         result = self._render()
50         self._result = result
51         self.done = True
52         return True
53     
54     def is_done(self):
55         res = self.done
56         return res
57
58     def get(self):
59         if self.is_done():
60             return self._result
61         else:
62             return None
63
64 if __name__=='__main__':
65     import time
66     print 'Multi-thread code !'
67     r = render()
68     r.render()
69     while not r.is_done():
70         print 'not yet!'
71         time.sleep(1)
72     print 'done!'
73
74
75 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
76