[IMP] remove apps

bzr revid: chs@openerp.com-20120822174413-dln0k2refi86g0lj
This commit is contained in:
Christophe Simonis 2012-08-22 19:44:13 +02:00
parent d8c0fdf505
commit 8736e1102a
4 changed files with 153 additions and 3 deletions

View File

@ -3,7 +3,7 @@
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2010 OpenERP s.a. (<http://openerp.com>).
# Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@ -99,5 +99,8 @@
'auto_install': True,
'certificate': '0076807797149',
'css': ['static/src/css/modules.css'],
'js': [
'static/src/js/apps.js',
],
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -18,13 +18,25 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from collections import defaultdict
import imp
import logging
import os
import re
import shutil
import tempfile
import urllib
import zipfile
import zipimport
import base64
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO # NOQA
import requests
from openerp import modules, pooler, release, tools, addons
from openerp.tools.parse_version import parse_version
from openerp.tools.translate import _
@ -41,6 +53,21 @@ ACTION_DICT = {
'nodestroy':True,
}
def backup(path, raise_exception=True):
path = os.path.normpath(path)
if not os.path.exists(path):
if not raise_exception:
return None
raise OSError('path does not exists')
cnt = 1
while True:
bck = '%s~%d' % (path, cnt)
if not os.path.exists(bck):
shutil.move(path, bck)
return bck
cnt += 1
class module_category(osv.osv):
_name = "ir.module.category"
_description = "Application"
@ -584,6 +611,47 @@ class module(osv.osv):
zimp.load_module(mod.name)
return res
def install_from_urls(self, cr, uid, urls, context=None):
tmp = tempfile.mkdtemp()
try:
for module_name in urls:
try:
r = requests.get(urls[module_name])
r.raise_for_status()
except requests.HTTPError, e:
_logger.exception('ggr')
raise osv.except_osv('grrr', e)
else:
zipfile.ZipFile(StringIO(r.content)).extractall(tmp)
assert os.path.isdir(os.path.join(tmp, module_name))
for module_name in urls:
module_path = modules.get_module_path(module_name, downloaded=True, display_warning=False)
bck = backup(module_path, False)
shutil.move(os.path.join(tmp, module_name), module_path)
if bck:
shutil.rmtree(bck)
self.update_list(cr, uid, context=context)
# FIXME restart server if ugrade...
ids = self.search(cr, uid, [('name', 'in', urls.keys())], context=context)
def install_or_upgrade(cr, uid, ids, context=None):
bystate = defaultdict(list)
names = []
for m in self.read(cr, uid, ids, ['state', 'name'], context=context):
bystate[m['state']].append(m['id'])
names.append(m['name'])
self.button_install(cr, uid, bystate['uninstalled'], context=context)
self.button_upgrade(cr, uid, bystate['installed'], context=context)
return self._button_immediate_function(cr, uid, ids, install_or_upgrade, context=context)
finally:
shutil.rmtree(tmp)
def _update_dependencies(self, cr, uid, mod_browse, depends=None):
if depends is None:
depends = []

View File

@ -2,6 +2,12 @@
<openerp>
<data>
<record model="ir.actions.client" id="modules_act_cl">
<field name="name">Modules</field>
<field name="tag">apps</field>
</record>
<menuitem id="module_mi" parent="base.menu_management" sequence="1" action="modules_act_cl" type="client"/>
<!-- Modules Categories -->
<record id="view_module_category_form" model="ir.ui.view">
@ -187,8 +193,8 @@
<p>You should try others search criteria.</p>
</field>
</record>
<menuitem id="menu_module_tree" parent="base.menu_management" name="Modules"
sequence="1" action="open_module_tree"/>
<menuitem id="menu_module_tree" parent="base.menu_management" name="Local Modules"
sequence="2" action="open_module_tree" groups="group_no_one" />
</data>
</openerp>

View File

@ -0,0 +1,73 @@
openerp.base = function(instance) {
instance.base = {};
instance.base.Apps = instance.web.Widget.extend({
template: 'EmptyComponent',
init: function(parent, options) {
this._super(parent);
// create a new instance
this.remote_instance = new openerp.init();
},
destroy: function() {
if (this.client) {
this.client.destroy();
}
delete this.remote_instance;
},
_get_options: function() {
//var DEFAULT_SERVER = 'http://apps.openerp.com/loempia'; // PROD
//var DEFAULT_SERVER = 'http://apps.openerp.com:9069/loempia7'; // TEST
var DEFAULT_SERVER = 'http://localhost:8080/trunk_loempia7'; // DEV
var ICP = new instance.web.Model('ir.config_parameter');
return ICP.call('get_param', ['loempia.server', DEFAULT_SERVER]).pipe(function(u) {
var link = $(_.str.sprintf('<a href="%s"></a>', u))[0];
var host = _.str.sprintf('%s//%s', link.protocol, link.host);
var dbname = link.pathname.substr(1);
var login = (sessionStorage ? sessionStorage.getItem('loempia.login') : null) || 'anonymous';
var passwd = (sessionStorage ? sessionStorage.getItem('loempia.passwd') : null) || 'anonymous';
return {
url: host,
dbname: dbname,
login: login,
password: passwd,
action_id: 'loempia.action_embed'
};
});
},
start: function() {
return this._get_options().then(this.proxy('_connect'));
},
_connect: function(options) {
this.options = options;
var client = this.client = new this.remote_instance.web.EmbeddedClient(null, this.options.url,
this.options.dbname, this.options.login, this.options.password,
this.options.action_id, this.action_flags);
client.on('connection_failed', this, this.action_fallback);
this.client = client;
client.replace(this.$element).
done(function() {
client.$element.removeClass('openerp');
}).
fail(function() {
console.log('fail', this);
alert('fail');
});
},
action_fallback: function() {
// TODO show flash message
this.do_warn(this.options.url + ' unreachable');
this.do_action('base.action_modules');
}
});
instance.web.client_actions.add("apps", "instance.base.Apps");
};