def main(): args = sys.argv[1:] # The only shared option is '--addons-path=' needed to discover additional # commands from modules if len(args) > 1 and args[0].startswith('--addons-path=') and not args[1].startswith("-"): # parse only the addons-path, do not setup the logger... flectra.tools.config._parse_config([args[0]]) args = args[1:] # Default legacy command command = "server" # TODO: find a way to properly discover addons subcommands without importing the world # Subcommand discovery if len(args) and not args[0].startswith("-"): logging.disable(logging.CRITICAL) for module in get_modules(): if isdir(joinpath(get_module_path(module), 'cli')): __import__('flectra.addons.' + module) logging.disable(logging.NOTSET) command = args[0] args = args[1:] if command in commands: o = commands[command]() o.run(args) else: sys.exit('Unknow command %r' % (command,))
def test_dunderinit(self): """ Test that __init__.py exists in Flectra modules, otherwise they won't get packaged""" modules_list = [mod for mod in get_modules() if mod not in WHITELIST] for mod in modules_list: dunderinit_path = Path(get_module_path(mod)) / '__init__.py' self.assertTrue(dunderinit_path.is_file(), "Missing `__init__.py ` in module %s" % mod) _logger.info('%s modules checked', len(modules_list))
def iter_module_files(self, *globs): """ Yields the paths of all the module files matching the provided globs (AND-ed) """ for modroot in map(get_module_path, get_modules()): for root, _, fnames in os.walk(modroot): fnames = [j(root, n) for n in fnames] for glob in globs: fnames = fnmatch.filter(fnames, glob) yield from fnames
def update_list(self): res = [0, 0] # [update, add] default_version = modules.adapt_version('1.0') known_mods = self.with_context(lang=None).search([]) known_mods_names = {mod.name: mod for mod in known_mods} # iterate through detected modules and update/create them in db for mod_name in modules.get_modules(): mod = known_mods_names.get(mod_name) terp = self.get_module_info(mod_name) values = self.get_values_from_terp(terp) if mod: updated_values = {} for key in values: old = getattr(mod, key) updated = tools.ustr(values[key]) if isinstance( values[key], pycompat.string_types) else values[key] if (old or updated) and updated != old: updated_values[key] = values[key] if terp.get('installable', True) and mod.state == 'uninstallable': updated_values['state'] = 'uninstalled' if parse_version(terp.get( 'version', default_version)) > parse_version( mod.latest_version or default_version): res[0] += 1 if terp.get('contract_certificate'): mod.write({ 'contract_certificate': terp.get('contract_certificate') or False }) if updated_values: mod.write(updated_values) else: mod_path = modules.get_module_path(mod_name) if not mod_path: continue if not terp or not terp.get('installable', True): continue mod = self.create( dict(name=mod_name, state='uninstalled', **values)) res[1] += 1 mod._update_dependencies(terp.get('depends', [])) mod._update_exclusions(terp.get('excludes', [])) mod._update_category(terp.get('category', 'Uncategorized')) return res
def test_pot_duplicate_entries(self): def format(entry): # TranslationFileReader only returns those three types if entry['type'] == 'model': return ('model', entry['name'], entry['imd_name']) elif entry['type'] == 'model_terms': return ('model_terms', entry['name'], entry['imd_name'], entry['src']) elif entry['type'] == 'code': return ('code', entry['src']) # retrieve all modules, and their corresponding POT file for module in get_modules(): filename = get_resource_path(module, 'i18n', module + '.pot') if not filename: continue counts = Counter(map(format, TranslationFileReader(filename))) duplicates = [key for key, count in counts.items() if count > 1] self.assertFalse(duplicates, "Duplicate entries found in %s" % filename)
def test_pylint(self): if pylint is None: self._skip_test('please install pylint') required_pylint_version = LooseVersion('1.6.4') if sys.version_info >= (3, 6): required_pylint_version = LooseVersion('1.7.0') if LooseVersion(getattr(pylint, '__version__', '0.0.1')) < required_pylint_version: self._skip_test('please upgrade pylint to >= %s' % required_pylint_version) paths = [tools.config['root_path']] for module in get_modules(): module_path = get_module_path(module) if not module_path.startswith( join(tools.config['root_path'], 'addons')): paths.append(module_path) options = [ '--rcfile=%s' % os.devnull, '--disable=all', '--enable=%s' % ','.join(self.ENABLED_CODES), '--reports=n', "--msg-template='{msg} ({msg_id}) at {path}:{line}'", '--load-plugins=pylint.extensions.bad_builtin,_flectra_checker_sql_injection,_flectra_checker_gettext', '--bad-functions=%s' % ','.join(self.BAD_FUNCTIONS), '--deprecated-modules=%s' % ','.join(self.BAD_MODULES) ] pypath = HERE + os.pathsep + os.environ.get('PYTHONPATH', '') env = dict(os.environ, PYTHONPATH=pypath) try: pylint_bin = tools.which('pylint') process = subprocess.Popen( [pylint_bin] + options + paths, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, ) except (OSError, IOError): self._skip_test('pylint executable not found in the path') else: out, err = process.communicate() if process.returncode: self.fail("pylint test failed:\n" + (b"\n" + out + b"\n" + err).decode('utf-8').strip())
def update_list(self): res = [0, 0] # [update, add] default_version = modules.adapt_version('1.0') known_mods = self.with_context(lang=None).search([]) known_mods_names = {mod.name: mod for mod in known_mods} # iterate through detected modules and update/create them in db for mod_name in modules.get_modules(): mod = known_mods_names.get(mod_name) terp = self.get_module_info(mod_name) values = self.get_values_from_terp(terp) if mod: updated_values = {} for key in values: old = getattr(mod, key) if (old or values[key]) and values[key] != old: updated_values[key] = values[key] if terp.get('installable', True) and mod.state == 'uninstallable': updated_values['state'] = 'uninstalled' if parse_version(terp.get('version', default_version)) > parse_version(mod.latest_version or default_version): res[0] += 1 if updated_values: mod.write(updated_values) else: mod_path = modules.get_module_path(mod_name) if not mod_path or not terp: continue state = "uninstalled" if terp.get('installable', True) else "uninstallable" mod = self.create(dict(name=mod_name, state=state, **values)) res[1] += 1 mod._update_dependencies(terp.get('depends', []), terp.get('auto_install')) mod._update_exclusions(terp.get('excludes', [])) mod._update_category(terp.get('category', 'Uncategorized')) return res