def collect(ctx): logger = (ctx.obj['logger']) from odoo.modules import get_modules, get_module_path from odoo.tools.osutil import listdir from odooku.backends import get_backend s3_backend = get_backend('s3') for module in get_modules(): if module in RESERVED: logger.warning("Module name %s clashes with a reserved key", module) continue static_dir = os.path.join(get_module_path(module), 'static') if os.path.exists(static_dir): for filename in listdir(static_dir, True): path = os.path.join(static_dir, filename) url = os.path.join(module, 'static', filename) logger.info("Uploading %s", url) s3_backend.client.upload_file(path, s3_backend.bucket, url, ExtraArgs={ 'ACL': 'public-read', 'CacheControl': ('max-age=%d, public' % (s3_backend.cache_time)) })
def load_test_file_py(registry, test_file): threading.currentThread().testing = True try: test_path, _ = os.path.splitext(os.path.abspath(test_file)) for mod in [m for m in get_modules() if '/%s/' % m in test_file]: for mod_mod in get_test_modules(mod): mod_path, _ = os.path.splitext(getattr(mod_mod, '__file__', '')) if test_path == mod_path: suite = unittest.TestSuite() for t in unittest.TestLoader().loadTestsFromModule( mod_mod): suite.addTest(t) _logger.log(logging.INFO, 'running tests %s.', mod_mod.__name__) stream = odoo.modules.module.TestStream() result = unittest.TextTestRunner(verbosity=2, stream=stream).run(suite) success = result.wasSuccessful() if hasattr(registry._assertion_report, 'report_result'): registry._assertion_report.report_result(success) if not success: _logger.error( '%s: at least one error occurred in a test', test_file) return finally: threading.currentThread().testing = False
def test_pylint(self): if pylint is None: self._skip_test("please install pylint") if LooseVersion(getattr(pylint, "__version__", "0.0.1")) < LooseVersion("1.6.4"): self._skip_test("please upgrade pylint to >= 1.6.4") 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 = [ "--disable=all", "--enable=%s" % ",".join(self.ENABLED_CODES), "--reports=n", "--msg-template='{msg} ({msg_id}) at {path}:{line}'", ] try: with open(devnull, "w") as devnull_file: process = subprocess.Popen(["pylint"] + options + paths, stdout=subprocess.PIPE, stderr=devnull_file) except (OSError, IOError): self._skip_test("pylint executable not found in the path") else: out = process.communicate()[0] if process.returncode: self.fail(msg="\n" + out)
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... odoo.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__('odoo.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('Unknown command %r' % (command,))
def main(starter, conf, version=None, just_test=False, server_wide_modules=None, gevent_script_path=None): """Call the `starter` script, dispatching configuration. All arguments are set in the standalone script produced by buildout through entry point options. :param starter: path to the main script source file (currently ``openerp-server``) :param conf: path to the Odoo configuration file (managed by the recipe) :param version: Odoo major version :param server_wide_modules: additional server wide modules, to pass with the ``--load`` command-line option (ignored if the option is actually there on the command line) :type version: tuple of integers :param just_test: if True, only run unit tests """ arguments = ['-c', conf] if just_test: arguments.extend(('--log-level', 'test' if version >= (6, 0) else 'info', '--stop-after-init')) if version >= (7, 0): arguments.append('--test-enable') if server_wide_modules: for opt in sys.argv[1:]: if opt.startswith('--load'): break else: arguments.append('--load=' + ','.join(server_wide_modules)) if '--install-all' in sys.argv: sys.argv.remove('--install-all') from odoo.tools import config # Maybe we should preparse config in all cases and therefore avoid # adding the '-c' on the fly ? # Still, cautious about pre-6.1 versions config.parse_config(['-c', conf]) from odoo.modules import get_modules arguments.extend(('-i', ','.join(get_modules()))) insert_args(arguments) if version >= (8, 0): # always true in a.r.odoo, but keeping for now assert gevent_script_path is not None patch_odoo.do_patch(gevent_script_path) os.chdir(os.path.split(starter)[0]) glob = globals() glob['__name__'] = '__main__' glob['__file__'] = starter sys.argv[0] = starter try: execfile(starter, globals()) except SystemExit as exc: return exc.code
def test_pylint(self): if pylint is None: self._skip_test('please install pylint') if LooseVersion(getattr(pylint, '__version__', '0.0.1')) < LooseVersion('1.6.4'): self._skip_test('please upgrade pylint to >= 1.6.4') 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 = [ '--disable=all', '--enable=%s' % ','.join(self.ENABLED_CODES), '--reports=n', "--msg-template='{msg} ({msg_id}) at {path}:{line}'", ] try: with open(devnull, 'w') as devnull_file: process = subprocess.Popen(['pylint'] + options + paths, stdout=subprocess.PIPE, stderr=devnull_file) except (OSError, IOError): self._skip_test('pylint executable not found in the path') else: out = process.communicate()[0] if process.returncode: self.fail("\n" + out)
def test_pylint(self): if pylint is None: self._skip_test('please install pylint') if LooseVersion(getattr(pylint, '__version__', '0.0.1')) < LooseVersion('1.6.4'): self._skip_test('please upgrade pylint to >= 1.6.4') 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 = [ '--disable=all', '--enable=%s' % ','.join(self.ENABLED_CODES), '--reports=n', "--msg-template='{msg} ({msg_id}) at {path}:{line}'", '--deprecated-modules=%s' % ','.join(self.BAD_MODULES), ] try: with open(devnull, 'w') as devnull_file: process = subprocess.Popen(['pylint'] + options + paths, stdout=subprocess.PIPE, stderr=devnull_file) except (OSError, IOError): self._skip_test('pylint executable not found in the path') else: out = process.communicate()[0] if process.returncode: self.fail(msg="\n" + out)
def test_pylint(self): if pylint is None: self._skip_test('please install pylint') if LooseVersion(getattr(pylint, '__version__', '0.0.1')) < LooseVersion('1.6.4'): self._skip_test('please upgrade pylint to >= 1.6.4') 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 = [ '--disable=all', '--enable=%s' % ','.join(self.ENABLED_CODES), '--reports=n', "--msg-template='{msg} ({msg_id}) at {path}:{line}'", '--load-plugins=pylint.extensions.bad_builtin', '--bad-functions=%s' % ','.join(self.BAD_FUNCTIONS), '--deprecated-modules=%s' % ','.join(self.BAD_MODULES) ] try: process = subprocess.Popen(['pylint'] + options + paths, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except (OSError, IOError): self._skip_test('pylint executable not found in the path') else: out, err = process.communicate() if process.returncode: self.fail("\n" + out + "\n" + err)
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... odoo.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__('odoo.addons.' + module) logging.disable(logging.NOTSET) command = args[0] args = args[1:] if command in commands: o = commands[command]() o.run(args)
def info(ctx): logger = ( ctx.obj['logger'] ) from odoo.modules import get_modules print INFO_MESSAGE.format( num_modules=len(get_modules()) )
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 test_dunderinit(self): """ Test that __init__.py exists in Odoo 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 update_list(self): res = [0, 0] # [update, add] default_version = modules.adapt_version('1.0') known_mods = self.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], basestring) 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 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_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,_odoo_checker_sql_injection,_odoo_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 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,_odoo_checkers', '--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 test_ecmascript_version(self): """ Test that there is no unsupported ecmascript in javascript files """ black_re = re.compile(r'summernote.+(intro\.js|outro.js)$') mod_paths = [get_module_path(m) for m in get_modules()] files_to_check = [] for p in mod_paths: for dp, _, file_names in os.walk(p): if 'static/test' in dp or "static/src/tests" in dp: continue for fn in file_names: fullpath_name = os.path.join(dp, fn) if fullpath_name.endswith('.js') and not black_re.search(fullpath_name): files_to_check.append(fullpath_name) _logger.info('Testing %s js files', len(files_to_check)) cmd = [es_check, MAX_ES_VERSION] + files_to_check process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = process.communicate() self.assertEqual(process.returncode, 0, msg=out.decode())
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 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 load_test_file_py(registry, test_file): threading.currentThread().testing = True try: test_path, _ = os.path.splitext(os.path.abspath(test_file)) for mod in [m for m in get_modules() if '/%s/' % m in test_file]: for mod_mod in get_test_modules(mod): mod_path, _ = os.path.splitext(getattr(mod_mod, '__file__', '')) if test_path == mod_path: suite = unittest.TestSuite() for t in unittest.TestLoader().loadTestsFromModule(mod_mod): suite.addTest(t) _logger.log(logging.INFO, 'running tests %s.', mod_mod.__name__) stream = odoo.modules.module.TestStream() result = unittest.TextTestRunner(verbosity=2, stream=stream).run(suite) success = result.wasSuccessful() if hasattr(registry._assertion_report,'report_result'): registry._assertion_report.report_result(success) if not success: _logger.error('%s: at least one error occurred in a test', test_file) return finally: threading.currentThread().testing = False
def test_manifests_keys(self): for module in get_modules(): with self.subTest(module=module): manifest_keys = load_manifest(module).keys() unknown_keys = manifest_keys - MANIFEST_KEYS self.assertEqual(unknown_keys, set(), f"Unknown manifest keys in module {module!r}. Either there are typos or they must be white listed.")