summaryrefslogtreecommitdiff
path: root/bin/addons/base/module/wizard
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@tinyerp.com>2007-05-03 18:34:39 +0000
committerFabien Pinckaers <fp@tinyerp.com>2007-05-03 18:34:39 +0000
commitb46cf7ec1929e7c355c2b7e89b15e9c134d2c5d5 (patch)
treeeedf3538f66702b04bec10fe08d50c13d6099523 /bin/addons/base/module/wizard
parent3931f854941670e5509a73053b66cd08f54ecc73 (diff)
Modifs on module systems
bzr revid: fp@tinyerp.com-f61ade60da194c40ebff78bb20883548f3e449f3
Diffstat (limited to 'bin/addons/base/module/wizard')
-rw-r--r--bin/addons/base/module/wizard/move_module_wizard.py173
1 files changed, 82 insertions, 91 deletions
diff --git a/bin/addons/base/module/wizard/move_module_wizard.py b/bin/addons/base/module/wizard/move_module_wizard.py
index 8d96c7862fc..446dafe5445 100644
--- a/bin/addons/base/module/wizard/move_module_wizard.py
+++ b/bin/addons/base/module/wizard/move_module_wizard.py
@@ -1,107 +1,98 @@
+##############################################################################
+#
+# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+
import wizard
import osv
-from datetime import date
-import time
import pooler
-import xmlrpclib
-import re
import os
-import sys
-import string
-from zipfile import ZipFile, ZIP_DEFLATED
+import tools
-move_module_form = '''<?xml version="1.0"?>
-<form string="Transfer Module">
- <field name="module_name" colspan="4"/>
- <newline/>
- <newline/>
-</form>'''
+from zipfile import PyZipFile, ZIP_DEFLATED
+import StringIO
+import base64
finish_form ='''<?xml version="1.0"?>
<form string="Finish">
- <label string="Module Zipped successfully !!!" colspan="4"/>
+ <separator string="Module successfully exported !" colspan="4"/>
+ <field name="module_file"/>
+ <newline/>
+ <field name="module_filename"/>
</form>
'''
-class move_module_wizard(wizard.interface):
- def _get_module(self, cr, uid, context):
- module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
- ids=module_obj.search(cr, uid, [])
- modules=module_obj.browse(cr, uid, ids)
- return [(modules_rec.name,modules_rec.name) for modules_rec in modules]
-
- def zippy(self,path, archive):
- paths = os.listdir(path)
- for p in paths:
- if p=='.svn':
- continue
- p = os.path.join(path, p) # Make the path relative
- if os.path.isdir(p): # Recursive case
- self.zippy(p, archive)
- else:
- ext=p.split('/')
- if ext[len(ext)-1]=='__terp__.py':
- archive.write(p)
- continue
- ext=p.split('.')[1]
- if ext=='py':
- continue
- archive.write(p) # Write the file to the zipfile
- return
-
- def zipit(self,path, archname):
- # Create a ZipFile Object primed to write
- archive = ZipFile(archname, "w", ZIP_DEFLATED) # "a" to append, "r" to read
- # Recurse or not, depending on what path is
- if os.path.isdir(path):
- self.zippy(path, archive)
- else:
- archive.write(path)
- archive.close()
- return "Compression of \""+path+"\" was successful!"
+finish_fields = {
+ 'module_file': {'string': 'Module .ZIP file', 'type':'binary', 'readonly':True},
+ 'module_filename': {'string': 'Filename', 'type':'char', 'size': 64, 'readonly':True},
+}
- def createzip(self, cr, uid, data, context):
- try:
- fromurl=os.getcwd()
- fromurl=fromurl+'/addons/'+data['form']['module_name']
- tourl = fromurl+'.zip'
- status=self.zipit(fromurl,tourl)
-
- except Exception,e:
-
- if hasattr(e,'args'):
- print "Items::",e.args;
- if len(e.args) == 2:
- if e.args[0] == -2:
- return 'wrong_server_name'
- #end if e.args[0] == -2:
- else:
- return 'wrong_server_name'
- #end if len(e.args) == 2:
- #end if hasattr(e,'args'):
-
- return 'wrong_server_name'
- return 'finish'
-
- #end def createzip(self, cr, uid, data, context):
+class move_module_wizard(wizard.interface):
+ def zippy(self, archive, fromurl, path):
+ url = os.path.join(fromurl, path)
+ if os.path.isdir(url):
+ if path.split('/')[-1]=='.svn':
+ return False
+ for fname in os.listdir(url):
+ self.zippy(archive, fromurl, path and os.path.join(path, fname) or fname)
+ else:
+ if (path.split('.')[-1] not in ['py','pyo','pyc']) or (os.path.basename(path)=='__terp__.py'):
+ print 'Adding', os.path.join(fromurl, path), 'as', path
+ archive.write(os.path.join(fromurl, path), path)
+ return True
- move_module_fields = {
- 'module_name': {'string':'Module Name', 'type':'selection', 'selection':_get_module,'required':True},
+ def createzip(self, cr, uid, data, context):
+ module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
+ module_name = module_obj.browse(cr, uid, data['id']).name
- }
+ ad = tools.config['addons_path']
+ if os.path.isdir(os.path.join(ad,module_name)):
+ archname = StringIO.StringIO('wb')
+ archive = PyZipFile(archname, "w", ZIP_DEFLATED)
+ archive.writepy(os.path.join(ad,module_name))
+ self.zippy(archive, ad, module_name)
+ archive.close()
+ val =base64.encodestring(archname.getvalue())
+ archname.close()
+ elif os.path.isfile(os.path.join(ad,module_name+'.zip')):
+ val = file(os.path.join(ad,module_name+'.zip'),'rb').read()
+ val =base64.encodestring(val)
+ else:
+ raise wizard.except_wizard('Error !', 'Could not find the module to export !')
+ return {'module_file':val, 'module_filename': module_name+'.zip'}
- states = {
- 'init': {
- 'actions': [],
- 'result': {'type':'form', 'arch':move_module_form, 'fields':move_module_fields, 'state':[('end','Cancel'),('makezip','Create Zip')]}
- },
- 'makezip': {
- 'actions': [],
- 'result':{'type':'choice', 'next_state': createzip}
- },
- 'finish':{
- 'actions': [],
- 'result':{'type':'form', 'arch':finish_form,'fields':{},'state':[('end','OK')]}
- }
- }
+ states = {
+ 'init': {
+ 'actions': [createzip],
+ 'result': {
+ 'type':'form',
+ 'arch':finish_form,
+ 'fields':finish_fields,
+ 'state':[('end','Close')]
+ }
+ }
+ }
move_module_wizard('tmp.wizard')