Merge lp:~openerp-dev/openobject-server/trunk-load-virtual-mod-pna into lp:openobject-server

Proposed by Harry (OpenERP)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-server/trunk-load-virtual-mod-pna
Merge into: lp:openobject-server
Diff against target: 200 lines (+73/-5)
6 files modified
openerp/addons/base/base.sql (+1/-0)
openerp/addons/base/module/module.py (+30/-1)
openerp/http.py (+11/-0)
openerp/modules/db.py (+4/-3)
openerp/modules/loading.py (+26/-1)
openerp/modules/module.py (+1/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-load-virtual-mod-pna
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+212107@code.launchpad.net
To post a comment you must log in.
5141. By Pinakin Nayi (OpenERP)

[IMP]store module name and file name to make it compatible to apps

Unmerged revisions

5141. By Pinakin Nayi (OpenERP)

[IMP]store module name and file name to make it compatible to apps

5140. By Pinakin Nayi (OpenERP)

[IMP]check module if virtual then append in manifest list

5139. By Pinakin Nayi (OpenERP)

[IMP]small improvement

5138. By Pinakin Nayi (OpenERP)

[IMP]check files at the time of apps install and if type virtual then store in attachment(static files)

5137. By Pinakin Nayi (OpenERP)

[IMP]create new type and check if virtual then save in attachemnt

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/base.sql'
2--- openerp/addons/base/base.sql 2013-12-02 15:08:56 +0000
3+++ openerp/addons/base/base.sql 2014-03-21 08:18:29 +0000
4@@ -286,6 +286,7 @@
5 license character varying(32),
6 sequence integer DEFAULT 100,
7 auto_install boolean default False,
8+ type character varying(32),
9 primary key(id)
10 );
11 ALTER TABLE ir_module_module add constraint name_uniq unique (name);
12
13=== modified file 'openerp/addons/base/module/module.py'
14--- openerp/addons/base/module/module.py 2014-02-11 10:55:25 +0000
15+++ openerp/addons/base/module/module.py 2014-03-21 08:18:29 +0000
16@@ -34,6 +34,7 @@
17 import zipfile
18 import zipimport
19 import lxml.html
20+import base64
21
22 try:
23 from cStringIO import StringIO
24@@ -294,6 +295,10 @@
25 'application': fields.boolean('Application', readonly=True),
26 'icon': fields.char('Icon URL', size=128),
27 'icon_image': fields.function(_get_icon_image, string='Icon', type="binary"),
28+ 'type': fields.selection([
29+ ('virtual', 'Virtual'),
30+ ('physical', 'Physical'),
31+ ], string='Type', readonly=True),
32 }
33
34 _defaults = {
35@@ -301,6 +306,7 @@
36 'sequence': 100,
37 'demo': False,
38 'license': 'AGPL-3',
39+ 'type': 'physical',
40 }
41 _order = 'sequence,name'
42
43@@ -660,6 +666,7 @@
44 _logger.debug('Install from url: %r', urls)
45 try:
46 # 1. Download & unzip missing modules
47+ ir_attach = self.pool.get('ir.attachment')
48 for module_name, url in urls.items():
49 if not url:
50 continue # nothing to download, local version is already the last one
51@@ -671,7 +678,29 @@
52 raise osv.except_osv(_('Module not found'),
53 _('The `%s` module appears to be unavailable at the moment, please try again later.') % module_name)
54 else:
55- zipfile.ZipFile(StringIO(content)).extractall(tmp)
56+ with zipfile.ZipFile(StringIO(content)) as zip_file:
57+ #get __openerp__.py information
58+ module_info = zip_file.open(module_name+'/__openerp__.py')
59+ info = {
60+ 'name' : "",
61+ 'type' : "physical",
62+ }
63+ info.update(eval(module_info.read()))
64+ #loop check files and extract
65+ for f_name in zip_file.namelist():
66+ if f_name.startswith(module_name+"/static/") and info.get('type') == "virtual":
67+ if not os.path.isdir(f_name):
68+ source = zip_file.open(f_name).read()
69+ result = base64.b64encode(source)
70+ ir_attach.create(cr, uid, {
71+ 'name': module_name,
72+ 'db_datas': result,
73+ 'datas_fname': f_name,
74+ 'res_model': module_name,
75+ 'type': "binary",
76+ }, context=context)
77+ else:
78+ zip_file.extract(f_name, tmp)
79 assert os.path.isdir(os.path.join(tmp, module_name))
80
81 # 2a. Copy/Replace module source in addons path
82
83=== modified file 'openerp/http.py'
84--- openerp/http.py 2014-03-19 23:51:17 +0000
85+++ openerp/http.py 2014-03-21 08:18:29 +0000
86@@ -1109,6 +1109,17 @@
87 addons_module[module] = m
88 addons_manifest[module] = manifest
89 statics['/%s/static' % module] = path_static
90+ else :
91+ if os.path.isfile(manifest_path):
92+ manifest = ast.literal_eval(open(manifest_path).read())
93+ if manifest.get('type') == "virtual" :
94+ manifest['addons_path'] = addons_path
95+ _logger.debug("Loading %s", module)
96+ if 'openerp.addons' in sys.modules:
97+ m = __import__('openerp.addons.' + module)
98+ addons_module[module] = m
99+ addons_manifest[module] = manifest
100+ statics['/%s/static' % module] = path_static
101
102 app = werkzeug.wsgi.SharedDataMiddleware(self.dispatch, statics)
103 self.dispatch = DisableCacheMiddleware(app)
104
105=== modified file 'openerp/modules/db.py'
106--- openerp/modules/db.py 2012-11-28 18:37:01 +0000
107+++ openerp/modules/db.py 2014-03-21 08:18:29 +0000
108@@ -74,8 +74,8 @@
109
110 cr.execute('INSERT INTO ir_module_module \
111 (author, website, name, shortdesc, description, \
112- category_id, auto_install, state, web, license, application, icon, sequence, summary) \
113- VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id', (
114+ category_id, auto_install, state, web, license, application, icon, sequence, summary, type) \
115+ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id', (
116 info['author'],
117 info['website'], i, info['name'],
118 info['description'], category_id,
119@@ -83,7 +83,8 @@
120 info['web'],
121 info['license'],
122 info['application'], info['icon'],
123- info['sequence'], info['summary']))
124+ info['sequence'], info['summary'],
125+ info['type']))
126 id = cr.fetchone()[0]
127 cr.execute('INSERT INTO ir_model_data \
128 (name,model,module, res_id, noupdate) VALUES (%s,%s,%s,%s,%s)', (
129
130=== modified file 'openerp/modules/loading.py'
131--- openerp/modules/loading.py 2014-03-17 15:18:10 +0000
132+++ openerp/modules/loading.py 2014-03-21 08:18:29 +0000
133@@ -29,6 +29,7 @@
134 import os
135 import sys
136 import threading
137+import base64
138
139 import openerp
140 import openerp.modules.db
141@@ -41,7 +42,7 @@
142
143 from openerp.tools.translate import _
144 from openerp.modules.module import initialize_sys_path, \
145- load_openerp_module, init_module_models, adapt_version
146+ load_openerp_module, init_module_models, adapt_version, get_module_path
147
148 _logger = logging.getLogger(__name__)
149 _test_logger = logging.getLogger('openerp.tests')
150@@ -73,7 +74,26 @@
151 # avoid keeping stale xml_id, etc. in cache
152 openerp.modules.registry.RegistryManager.clear_caches(cr.dbname)
153
154+ def create_virtual_attachment(cr, module_name, mod_file):
155+ try:
156+ mod_path = get_module_path(module_name)
157+ path = mod_path+'/'+mod_file
158+ with open(path) as f:
159+ content = f.read()
160+
161+ f_name = module_name + '/' + mod_file
162+ result = base64.b64encode(content)
163+ cr.execute('INSERT INTO ir_attachment (name, db_datas, datas_fname, res_model, type) values (%s, %s, %s, %s, %s)', (module_name, result, f_name, module_name, 'binary'))
164+ except Exception:
165+ cr.rollback()
166
167+ def _get_files_of_static_kind(cr):
168+ kind = ['js', 'css', 'qweb']
169+ for k in kind:
170+ if package.data.get(k):
171+ for f in package.data[k]:
172+ create_virtual_attachment(cr, package.name, f)
173+
174 def _get_files_of_kind(kind):
175 if kind == 'demo':
176 kind = ['demo_xml', 'demo']
177@@ -108,6 +128,11 @@
178 try:
179 if kind in ('demo', 'test'):
180 threading.currentThread().testing = True
181+
182+ # if virtual file then save in attachment
183+ if package.data['type'] == "virtual":
184+ _get_files_of_static_kind(cr)
185+
186 for filename in _get_files_of_kind(kind):
187 _logger.info("module %s: loading %s", module_name, filename)
188 noupdate = False
189
190=== modified file 'openerp/modules/module.py'
191--- openerp/modules/module.py 2014-03-17 02:13:17 +0000
192+++ openerp/modules/module.py 2014-03-21 08:18:29 +0000
193@@ -197,6 +197,7 @@
194 'website': '',
195 'sequence': 100,
196 'summary': '',
197+ 'type': 'physical',
198 }
199 info.update(itertools.izip(
200 'depends data demo test init_xml update_xml demo_xml'.split(),