Modifs
[odoo/odoo.git] / addons / base_module_publish / wizard / base_module_publish_all.py
1 ##############################################################################
2 #
3 # Copyright (c) 2005-2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 #
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsability of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # garantees and support are strongly adviced to contract a Free Software
10 # Service Company
11 #
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 #
26 ##############################################################################
27
28 import wizard
29 import pooler
30 import module_zip
31 from base_module_publish import post_multipart
32 from urllib import urlopen
33
34 intro_form = '''<?xml version="1.0"?>
35 <form string="Module publication">
36         <separator string="Publication information" colspan="4"/>
37         <field name="text" colspan="4" nolabel="1"/>
38 </form>'''
39
40 intro_fields = {
41         'text': {'string': 'Introduction', 'type': 'text', 'readonly': True,
42                 'default': lambda *a: """
43 This system will automatically publish and upload the selected modules to the
44 Tiny ERP official website. You can use it to quickly update a set of
45 module (new version).
46
47 Make sure you read the publication manual and modules guidlines
48 before continuing:
49   http://www.openerp.com/
50
51 Thanks you for contributing!
52 """},
53 }
54
55 login_form = '''<?xml version="1.0"?>
56 <form string="Module publication">
57         <separator string="User information" colspan="4"/>
58         <label string="Please provide here your login on the Tiny ERP website."
59         align="0.0" colspan="4"/>
60         <label string="If you don't have an access, you can create one http://www.openerp.com/"
61         align="0.0" colspan="4"/>
62         <field name="login"/>
63         <newline/>
64         <field name="password"/>
65         <newline/>
66         <field name="email"/>
67 </form>'''
68
69 login_fields = {
70         'login': {'string':'Login', 'type':'char', 'size':32, 'required':True},
71         'email': {'string':'Email', 'type':'char', 'size':100, 'required':True},
72         'password': {'string':'Password', 'type':'char', 'size':32, 'required':True,
73                 'invisible':True},
74 }
75
76 end_form = '''<?xml version="1.0"?>
77 <form string="Module publication">
78         <separator string="Upload information" colspan="4"/>
79         <field name="update" colspan="4"/>
80         <field name="already" colspan="4"/>
81         <field name="error" colspan="4"/>
82 </form>'''
83
84 end_fields= {
85         'update': {'type': 'text', 'string': 'Modules updated', 'readonly': True},
86         'already': {'type': 'text', 'string': 'Modules already updated',
87                 'readonly': True},
88         'error': {'type': 'text', 'string': 'Modules in error', 'readonly': True},
89 }
90
91 def _upload(self, cr, uid, datas, context):
92         pool = pooler.get_pool(cr.dbname)
93         modules = pool.get('ir.module.module').browse(cr, uid, datas['ids'])
94         log = [[], [], []] # [update, already, error]
95         for mod in modules: # whoooouuuuffff update
96                 if mod.state != 'installed':
97                         result[2].append(mod.name)
98                         continue
99                 res = module_zip.createzip(cr, uid, mod.id, context, b64enc=False,
100                                 src=(mod.license in ('GPL-2')))
101                 download = 'http://www.openerp.com/download/modules/'+res['module_filename']
102                 result = post_multipart('www.openerp.com', '/mtree_upload.php',
103                                 [('login', datas['form']['login']),
104                                         ('password', datas['form']['password']),
105                                         ('module_name', mod.name)
106                                 ], [('module', res['module_filename'],
107                                         res['module_file'])
108                                 ])
109                 if result[0] == "1":
110                         raise wizard.except_wizard('Error', 'Login failed!')
111                 elif result[0] == "0":
112                         log[0].append(mod.name)
113                 elif result[0] == "2":
114                         log[1].append(mod.name)
115                 else:
116                         log[2].append(mod.name)
117                 updata = {
118                         'link_name': mod.shortdesc or '',
119                         'link_desc': (mod.description or '').replace('\n','<br/>\n'),
120                         'website': mod.website or '',
121                         'email': datas['form']['email'] or '',
122                         'cust_1': download,
123                         'cust_3': mod.url or '/',
124                         'cust_6': mod.installed_version or '0',
125                         'cust_7': mod.name,
126                         'option': 'com_mtree',
127                         'task': 'savelisting',
128                         'Itemid': '99999999',
129                         'cat_id': '0',
130                         'adminForm': '',
131                         'auto_login': datas['form']['login'],
132                         'auto_password': datas['form']['password']
133                 }
134                 a = urlopen('http://www.openerp.com/mtree_interface.php?module=%s' % (mod.name,))
135                 aa = a.read()
136                 if aa[0]<>'0':
137                         updata['link_id']=aa.split('\n')[0]
138                         updata['cat_id']=aa.split('\n')[1]
139                         updata['option'] = 'mtree'
140                 result = post_multipart('www.openerp.com', '/index.php', updata.items(), [])
141         return {'update': '\n'.join(log[0]), 'already': '\n'.join(log[1]),
142                 'error': '\n'.join(log[2])}
143
144 class base_module_publish_all(wizard.interface):
145         states = {
146                 'init': {
147                         'actions': [],
148                         'result': {
149                                 'type': 'form',
150                                 'arch': intro_form,
151                                 'fields': intro_fields,
152                                 'state': [
153                                         ('end', 'Cancel'),
154                                         ('login', 'Ok'),
155                                 ]
156                         }
157                 },
158                 'login': {
159                         'actions': [],
160                         'result': {
161                                 'type': 'form',
162                                 'arch': login_form,
163                                 'fields': login_fields,
164                                 'state': [
165                                         ('end', 'Cancel'),
166                                         ('publish', 'Publish')
167                                 ]
168                         }
169                 },
170                 'publish': {
171                         'actions': [_upload],
172                         'result': {
173                                 'type': 'form',
174                                 'arch': end_form,
175                                 'fields': end_fields,
176                                 'state': [
177                                         ('end', 'Close')
178                                 ]
179                         }
180                 },
181         }
182 base_module_publish_all('base_module_publish.module_publish_all')