def test_load_information_from_description_file_rdepends_key( self, super_mock, cr_mock, helper_mock): """It should correctly call rdepends helper if key present""" super_mock.return_value = self.test_manifest cr_mock.return_value = self.cr helper_mock.reset_mock() load_information_from_description_file(self.test_module_name) helper_mock.assert_called_once_with(*self.test_call)
def test_load_information_from_description_file_no_rdepends_key( self, super_mock, cr_mock, helper_mock): """It should not call rdepends helper if key not present""" del self.test_manifest['rdepends_if_installed'] super_mock.return_value = self.test_manifest cr_mock.return_value = self.cr helper_mock.reset_mock() load_information_from_description_file(self.test_module_name) helper_mock.assert_not_called()
def _get_test_files_by_module(modules): assert isinstance(modules, list), 'modules argument should be a list' test_files = {} for module in modules: info = load_information_from_description_file(module) test_files[module] = info.get('test', []) return test_files
def test_load_information_from_description_file_rdepends_to_process( self, super_mock, cr_mock): """It should correctly add pending rdepends to manifest""" del self.test_manifest['rdepends_if_installed'] super_mock.return_value = self.test_manifest cr_mock.return_value = self.cr test_depends = set(['Test Depend 1', 'Test Depend 2']) test_rdepend_dict = { self.test_module_name: test_depends, 'Other Module': set(['Other Depend']), } dict_path = MOCK_PATH + '.local.rdepends_to_process' with patch.dict(dict_path, test_rdepend_dict, clear=True): load_information_from_description_file(self.test_module_name) self.assertEqual(self.test_manifest['depends'], list(test_depends))
def _load_data(self, module_name, kind='demo', mode='update', noupdate=False): cr = self._cr info = load_information_from_description_file(module_name) for filename in info.get(kind, []): _logger.info('loading %s/%s...' % (module_name, filename)) _, ext = os.path.splitext(filename) pathname = os.path.join(module_name, filename) with tools.file_open(pathname, 'rb') as fp: if ext == '.sql': tools.convert_sql_import(cr, fp) elif ext == '.csv': tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref=None, mode=mode, noupdate=noupdate) elif ext == '.xml': tools.convert_xml_import(cr, module_name, fp, idref=None, mode=mode, noupdate=noupdate) return True
def get_manifests(path): def is_really_module(name): for mname in MANIFEST_NAMES: if os.path.isfile(os.path.join(path, name, mname)): return True modules = [it for it in os.listdir(path) if is_really_module(it)] res = [] for mname in modules: mod_path = os.path.join(path, mname) info = load_information_from_description_file(mname, mod_path) res[mname] = info return info
def get_checks_for_module(module_name): result = [] manifest = load_information_from_description_file(module_name) manifest_checks = manifest.get('environment_checkup') or {} dependencies = manifest_checks.get('dependencies') or {} for dependency in dependencies.get('python') or []: result.append(PythonDependencyCheck(module_name, dependency)) for dependency in dependencies.get('external') or []: result.append(ExternalDependencyCheck(module_name, dependency)) for dependency in dependencies.get('internal') or []: result.append(InternalDependencyCheck(module_name, dependency)) return result
def prepare_saas_module_info_data(): """ :return: dict {module_name: { 'name': module_name, 'version': module_version, 'author': module_author, etc...}, etc...} """ res = {} for mod in module.get_modules(): data = module.load_information_from_description_file(mod) data['auto_install'] = bool(data['auto_install']) res[mod] = data return res
def clean_unavailable_modules(ctx): """Clean unavailable modules When we migrate a project, we have a lot of modules which became unavailable in the new version. This function will clean the module list to delete unavailable modules. """ module_model = ctx.env['ir.module.module'] all_modules = module_model.search([ # Here we need to list: # all modules uninstalled we want to migrate # to avoid to remove them # Example: # ( # 'name', # 'not in', # [ # 'account_asset_management', # To migrate! # ] # ) ]) for module in all_modules: info = load_information_from_description_file(module.name) if not info: if module.state in ['uninstalled', 'uninstallable']: ctx.log_line('MODULE UNAVAILABLE (will be deleted) : %s' % module.name) if ctx.env['ir.model.data'].search([('module', '=', module.name)]): ctx.log_line( "===> CAN'T UNLINK MODULE, WE HAVE METADATA " "(See if we want to migrate or uninstall the module)") else: module.unlink() else: ctx.log_line('MODULE UNAVAILABLE BUT BAD STATE : %s (%s)' % (module.name, module.state)) module_model.update_list()
def test_base_manifest_extension(self): # write a test manifest module_path = tempfile.mkdtemp(dir=os.path.join( get_module_path('base_manifest_extension'), 'static')) manifest_path = os.path.join(module_path, '__manifest__.py') with open(manifest_path, 'w') as manifest: manifest.write( repr({ 'depends_if_installed': [ 'base_manifest_extension', 'not installed', ], })) # parse it parsed = load_information_from_description_file( # this name won't really be used, but avoids a warning 'base', mod_path=module_path, ) self.assertIn('base_manifest_extension', parsed['depends']) self.assertNotIn('not installed', parsed['depends']) self.assertNotIn('depends_if_installed', parsed)