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 ##############################################################################
30 class base_module_scan(osv.osv_memory):
33 _name = "base.module.scan"
34 _description = "scan module"
36 def watch_dir(self, cr, uid, ids, context):
37 mod_obj = self.pool.get('ir.module.module')
38 all_mods = mod_obj.read(cr, uid, mod_obj.search(cr, uid, []), ['name', 'state'])
39 known_modules = [x['name'] for x in all_mods]
40 ls_ad = glob.glob(os.path.join(tools.config['addons_path'], '*', '__terp__.py'))
41 modules = [module_name_re.match(name).group(1) for name in ls_ad]
42 for fname in os.listdir(tools.config['addons_path']):
43 if zipfile.is_zipfile(fname):
44 modules.append( fname.split('.')[0])
45 for module in modules:
46 if module in known_modules:
48 terp = mod_obj.get_module_info(module)
49 if not terp.get('installable', True):
52 # XXX check if this code is correct...
53 fm = imp.find_module(module)
55 imp.load_module(module, *fm)
60 values = mod_obj.get_values_from_terp(terp)
61 mod_id = mod_obj.create(cr, uid, dict(name=module, state='uninstalled', **values))
62 dependencies = terp.get('depends', [])
63 for d in dependencies:
64 cr.execute('insert into ir_module_module_dependency (module_id,name) values (%s, %s)', (mod_id, d))
65 for module in known_modules:
66 terp = mod_obj.get_module_info(module)
67 if terp.get('installable', True):
69 if mod['name'] == module and mod['state'] == 'uninstallable':
70 mod_obj.write(cr, uid, [mod['id']], {'state': 'uninstalled'})
75 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: