[IMP] openerp python module.
[odoo/odoo.git] / openerp / 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     """ Represents a report job being rendered.
40     
41     @param bin_datas a dictionary of name:<binary content> of images etc.
42     @param path the path in which binary files can be discovered, useful
43             for components (images) of the report. It can be:
44                - a string, relative or absolute path to images
45                - a list, containing strings of paths.
46             If a string is absolute path, it will be opened as such, else
47             it will be passed to tools.file_open() which also considers zip
48             addons.
49     """
50     def __init__(self, bin_datas=None, path='.'):
51         self.done = False
52         if bin_datas is None:
53             self.bin_datas = {}
54         else:
55             self.bin_datas = bin_datas
56         self.path = path
57     
58     def _render(self):
59         return None
60
61     def render(self):
62         self.done = False
63         result = self._render()
64         self._result = result
65         self.done = True
66         return True
67     
68     def is_done(self):
69         res = self.done
70         return res
71
72     def get(self):
73         if self.is_done():
74             return self._result
75         else:
76             return None
77
78 if __name__=='__main__':
79     import time
80     print 'Multi-thread code !'
81     r = render()
82     r.render()
83     while not r.is_done():
84         print 'not yet!'
85         time.sleep(1)
86     print 'done!'
87
88
89 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
90