1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 # Copyright (C) 2010 OpenERP s.a. (<http://openerp.com>).
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
35 module_name_re = re.compile('.*addons.(.*?).__terp__.py$')
37 _info_arch = '''<?xml version="1.0"?>
38 <form string="Scan for new modules">
39 <label string="This function will check if you installed new modules in the 'addons' path of your server installation." colspan="4" />
44 class wizard_install_module(wizard.interface):
45 def watch_dir(self, cr, uid, data, context):
46 mod_obj = pooler.get_pool(cr.dbname).get('ir.module.module')
47 all_mods = mod_obj.read(cr, uid, mod_obj.search(cr, uid, []), ['name', 'state'])
48 known_modules = [x['name'] for x in all_mods]
49 ls_ad = glob.glob(os.path.join(tools.config['addons_path'], '*', '__terp__.py'))
50 modules = [module_name_re.match(name).group(1) for name in ls_ad]
51 for fname in os.listdir(tools.config['addons_path']):
52 if zipfile.is_zipfile(fname):
53 modules.append( fname.split('.')[0])
54 for module in modules:
55 if module in known_modules:
57 terp = mod_obj.get_module_info(module)
58 if not terp.get('installable', True):
61 # XXX check if this code is correct...
62 fm = imp.find_module(module)
64 imp.load_module(module, *fm)
69 values = mod_obj.get_values_from_terp(terp)
70 mod_id = mod_obj.create(cr, uid, dict(name=module, state='uninstalled', **values))
71 dependencies = terp.get('depends', [])
72 for d in dependencies:
73 cr.execute('insert into ir_module_module_dependency (module_id,name) values (%s, %s)', (mod_id, d))
74 for module in known_modules:
75 terp = mod_obj.get_module_info(module)
76 if terp.get('installable', True):
78 if mod['name'] == module and mod['state'] == 'uninstallable':
79 mod_obj.write(cr, uid, [mod['id']], {'state': 'uninstalled'})
85 'result': {'type':'form', 'arch': _info_arch, 'fields': _info_fields, 'state':[('end','Cancel','gtk-cancel'),('addmod','Check new modules','gtk-ok')]}
88 'actions': [watch_dir],
89 'result': {'type':'state', 'state':'end'}
92 wizard_install_module('module.module.scan')
95 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: