summaryrefslogtreecommitdiff
path: root/addons/base_module_publish/wizard/module_zip.py
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@tinyerp.com>2007-05-03 20:09:31 +0000
committerFabien Pinckaers <fp@tinyerp.com>2007-05-03 20:09:31 +0000
commitaaa3fa648c84701adbe80b0695be24c879337bed (patch)
tree1edd7a00e547a4219a68895f6b210ae4ba385b28 /addons/base_module_publish/wizard/module_zip.py
parent52e00eeeac140b9ae2a8146bf601b7e4dcf8103c (diff)
Missing file
bzr revid: fp@tinyerp.com-46b1565fcd9a17de0a339846b2f7288a1e13f80f
Diffstat (limited to 'addons/base_module_publish/wizard/module_zip.py')
-rw-r--r--addons/base_module_publish/wizard/module_zip.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/addons/base_module_publish/wizard/module_zip.py b/addons/base_module_publish/wizard/module_zip.py
new file mode 100644
index 00000000000..8d249e70df4
--- /dev/null
+++ b/addons/base_module_publish/wizard/module_zip.py
@@ -0,0 +1,44 @@
+import wizard
+import osv
+import pooler
+import os
+import tools
+
+from zipfile import PyZipFile, ZIP_DEFLATED
+import StringIO
+import base64
+
+def _zippy(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):
+ _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
+
+def createzip(cr, uid, moduleid, context, b64enc=True):
+ module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
+ module_name = module_obj.browse(cr, uid, moduleid).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))
+ _zippy(archive, ad, module_name)
+ archive.close()
+ val =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()
+ else:
+ raise wizard.except_wizard('Error !', 'Could not find the module to export !')
+ if b64enc:
+ val =base64.encodestring(val)
+ return {'module_file':val, 'module_filename': module_name+'.zip'}
+