1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
31 from osv import osv, fields
33 class base_module_scan(osv.osv_memory):
36 _name = "base.module.scan"
37 _description = "scan module"
39 def watch_dir(self, cr, uid, ids, context):
40 mod_obj = self.pool.get('ir.module.module')
41 all_mods = mod_obj.read(cr, uid, mod_obj.search(cr, uid, []), ['name', 'state'])
42 known_modules = [x['name'] for x in all_mods]
43 ls_ad = glob.glob(os.path.join(tools.config['addons_path'], '*', '__terp__.py'))
44 modules = [module_name_re.match(name).group(1) for name in ls_ad]
45 for fname in os.listdir(tools.config['addons_path']):
46 if zipfile.is_zipfile(fname):
47 modules.append( fname.split('.')[0])
48 for module in modules:
49 if module in known_modules:
51 terp = mod_obj.get_module_info(module)
52 if not terp.get('installable', True):
55 # XXX check if this code is correct...
56 fm = imp.find_module(module)
58 imp.load_module(module, *fm)
63 values = mod_obj.get_values_from_terp(terp)
64 mod_id = mod_obj.create(cr, uid, dict(name=module, state='uninstalled', **values))
65 dependencies = terp.get('depends', [])
66 for d in dependencies:
67 cr.execute('insert into ir_module_module_dependency (module_id,name) values (%s, %s)', (mod_id, d))
68 for module in known_modules:
69 terp = mod_obj.get_module_info(module)
70 if terp.get('installable', True):
72 if mod['name'] == module and mod['state'] == 'uninstallable':
73 mod_obj.write(cr, uid, [mod['id']], {'state': 'uninstalled'})