1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
25 from tools.translate import _
27 info = '''<?xml version="1.0"?>
28 <form string="Module Recording">
29 <label string="Thanks For using Module Recorder" colspan="4" align="0.0"/>
32 info_start_form = '''<?xml version="1.0"?>
33 <form string="Module Recording">
34 <separator string="Recording Information" colspan="4"/>
35 <field name="info_status"/>
36 <field name="info_text" colspan="4" nolabel="1"/>
37 <field name="info_yaml" colspan="4"/>
41 'info_text': {'string':'Information', 'type':'text', 'readonly':True},
42 'info_status': {'string':'Status','type':'selection', 'selection':[('no','Not Recording'),('record','Recording')], 'readonly':True},
43 'info_yaml': {'string':'YAML','type':'boolean'}
48 intro_start_form = '''<?xml version="1.0"?>
49 <form string="Module Recording">
50 <separator string="Module Information" colspan="4"/>
52 <field name="directory_name"/>
53 <field name="version"/>
54 <field name="author"/>
55 <field name="website" colspan="4"/>
56 <field name="category" colspan="4"/>
57 <field name="data_kind"/>
59 <field name="description" colspan="4"/>
62 intro_start_fields = {
63 'name': {'string':'Module Name', 'type':'char', 'size':64, 'required':True},
64 'directory_name': {'string':'Directory Name', 'type':'char', 'size':32, 'required':True},
65 'version': {'string':'Version', 'type':'char', 'size':16, 'required':True},
66 'author': {'string':'Author', 'type':'char', 'size':64, 'default': lambda *args: 'OpenERP SA', 'required':True},
67 'category': {'string':'Category', 'type':'char', 'size':64, 'default': lambda *args: 'Vertical Modules/Parametrization', 'required':True},
68 'website': {'string':'Documentation URL', 'type':'char', 'size':64, 'default': lambda *args: 'http://www.openerp.com', 'required':True},
69 'description': {'string':'Full Description', 'type':'text', 'required':True},
70 'data_kind': {'string':'Type of Data', 'type':'selection', 'selection':[('demo','Demo Data'),('update','Normal Data')], 'required':True, 'default': lambda *args:'update'},
73 intro_save_form = '''<?xml version="1.0"?>
74 <form string="Module Recording">
75 <separator string="Module successfully created !" colspan="4"/>
76 <field name="module_filename"/>
78 <field name="module_file" filename="module_filename"/>
79 <separator string="Information" colspan="4"/>
80 <label string="If you think your module could interest other people, we'd like you to publish it on http://www.openerp.com, in the 'Modules' section. You can do it through the website or using features of the 'base_module_publish' module." colspan="4" align="0.0"/>
81 <label string="Thanks in advance for your contribution." colspan="4" align="0.0"/>
85 'module_file': {'string': 'Module .zip File', 'type':'binary', 'readonly':True},
86 'module_filename': {'string': 'Filename', 'type':'char', 'size': 64, 'readonly':True},
89 yaml_save_form = '''<?xml version="1.0"?>
90 <form string="Module Recording">
91 <separator string="YAML file successfully created !" colspan="4"/>
93 <field name="yaml_file" filename="module_filename"/>
97 'yaml_file': {'string': 'Module .zip File', 'type':'binary'},
104 def _info_default(self, cr, uid, data, context):
105 pool = pooler.get_pool(cr.dbname)
106 mod = pool.get('ir.module.record')
108 info = "Details of "+str(len(mod.recording_data))+" Operation(s):\n\n"
110 for line in mod.recording_data:
111 result.setdefault(line[0],{})
112 result[line[0]].setdefault(line[1][3], {})
113 result[line[0]][line[1][3]].setdefault(line[1][3], 0)
114 result[line[0]][line[1][3]][line[1][3]]+=1
115 for key1,val1 in result.items():
117 for key2,val2 in val1.items():
119 for key3,val3 in val2.items():
120 info+="\t\t"+key3+" : "+str(val3)+"\n"
121 return {'info_text': info, 'info_status':mod.recording and 'record' or 'no'}
123 def _create_yaml(self, cr, uid, data, context):
124 pool = pooler.get_pool(cr.dbname)
125 mod = pool.get('ir.module.record')
127 res_xml = mod.generate_yaml(cr, uid)
129 raise wizard.except_wizard(_('Error'),_(str(e)))
131 'yaml_file': base64.encodestring(res_xml),
134 def _create_module(self, cr, uid, data, context):
135 pool = pooler.get_pool(cr.dbname)
136 mod = pool.get('ir.module.record')
137 res_xml = mod.generate_xml(cr, uid)
139 s=StringIO.StringIO()
140 zip = zipfile.ZipFile(s, 'w')
141 dname = data['form']['directory_name']
142 data['form']['update_name'] = ''
143 data['form']['demo_name'] = ''
144 if data['form']['data_kind'] =='demo':
145 data['form']['demo_name'] = '"%(directory_name)s_data.xml"' % data['form']
147 data['form']['update_name'] = '"%(directory_name)s_data.xml"' % data['form']
148 data['form']['depends'] = ','.join(map(lambda x: '"'+x+'"',mod.depends.keys()))
151 "version" : "%(version)s",
152 "author" : "%(author)s",
153 "website" : "%(website)s",
154 "category" : "%(category)s",
155 "description": \"\"\"%(description)s\"\"\",
156 "depends" : [%(depends)s],
158 "demo_xml" : [ %(demo_name)s],
159 "update_xml" : [%(update_name)s],
163 '__init__.py':'#\n# Generated by the OpenERP module recorder !\n#\n',
164 '__openerp__.py':_terp,
165 dname+'_data.xml': res_xml
167 for name,datastr in filewrite.items():
168 info = zipfile.ZipInfo(dname+'/'+name)
169 info.compress_type = zipfile.ZIP_DEFLATED
170 info.external_attr = 2175008768
173 zip.writestr(info, datastr)
176 'module_file': base64.encodestring(s.getvalue()),
177 'module_filename': data['form']['directory_name']+'-'+data['form']['version']+'.zip'
179 def _check(self, cr, uid, data, context):
180 pool = pooler.get_pool(cr.dbname)
181 mod = pool.get('ir.module.record')
182 if len(mod.recording_data):
183 if data['form']['info_yaml']:
190 class base_module_publish(wizard.interface):
193 'actions': [_info_default],
196 'arch':info_start_form,
197 'fields': info_start_fields,
199 ('end', 'Cancel', 'gtk-cancel'),
200 ('check', 'Continue', 'gtk-ok'),
206 'result': {'type':'choice','next_state':_check}
212 'arch':intro_start_form,
213 'fields': intro_start_fields,
215 ('end', 'Cancel', 'gtk-cancel'),
216 ('save', 'Continue', 'gtk-ok'),
221 'actions': [_create_module],
224 'arch':intro_save_form,
225 'fields': intro_save_fields,
227 ('end', 'Close', 'gtk-ok'),
232 'actions': [_create_yaml],
235 'arch':yaml_save_form,
236 'fields': yaml_save_fields,
238 ('end', 'Close', 'gtk-ok'),
245 'result': {'type':'form', 'arch':info, 'fields':{}, 'state':[('end','OK')]}
248 base_module_publish('base_module_record.module_save')
250 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: