Exemple #1
0
def grep_(record, *args, **kwargs):
    # type: (BaseModel, object, object) -> None
    """grep through all XML definitions of the record.

    See help(odoo_repl.grep) for more information.

    Note: because of technical limitations, formatting and line numbers don't
    always match up.
    """
    import lxml.etree

    argv = grep.build_grep_argv(args, kwargs)
    for rec in record:
        for rec_id in reversed(util.xml_ids(rec)):
            for definition in sources.xml_records[rec_id]:
                try:
                    grep.partial_grep(
                        argv,
                        lxml.etree.tostring(definition.elem,
                                            encoding="unicode"),
                        header=definition.fname,
                        lnum=definition.elem.sourceline,
                    )
                except grep.BadCommandline as err:
                    print(err, file=sys.stderr)
                    return
                except grep.NoResults:
                    continue
                else:
                    print()
Exemple #2
0
    def grep_(self, *args, **kwargs):
        # type: (object, object) -> None
        """grep through the addon's directory.

        See help(odoo_repl.grep) for more information.
        """
        argv = grep.build_grep_argv(args, kwargs, recursive=True)
        argv.append(self.path)
        subprocess.Popen(argv).wait()
Exemple #3
0
    def grep_(self, *args, **kwargs):
        # type: (object, object) -> None
        """grep through the combined source code of the model.

        See help(odoo_repl.grep) for more information.
        """
        assert self._real is not None
        # TODO: handle multiple classes in single file properly
        argv = grep.build_grep_argv(args, kwargs)
        seen = set()  # type: t.Set[t.Text]
        for src in sources.find_source(self._real):
            if src.fname not in seen:
                seen.add(src.fname)
                argv.append(src.fname)
        subprocess.Popen(argv).wait()
Exemple #4
0
    def grep_(self, *args, **kwargs):
        # type: (object, object) -> None
        """grep through all of the method's definitions, ignoring other file content.

        See ModelProxy.grep_ for options.

        The implementation is hacky. If you get weird results it's probably not
        your fault.
        """
        argv = grep.build_grep_argv(args, kwargs)
        for cls in type(self.model).__mro__[1:]:
            if self.name in vars(cls):
                func = util.unpack_function(vars(cls)[self.name])
                try:
                    grep.partial_grep(argv, func)
                except grep.BadCommandline as err:
                    print(err, file=sys.stderr)
                    return
                except grep.NoResults:
                    continue
                else:
                    print()
Exemple #5
0
    def grep_(*args, **kwargs):
        # type: (object, object) -> None
        """grep through all installed addons.

        See help(odoo_repl.grep) for more information.
        """
        argv = grep.build_grep_argv(args, kwargs, recursive=True)
        mods = util.sql(
            env,
            "SELECT name FROM ir_module_module WHERE state = 'installed'",
        )
        paths = [
            odoo.modules.module.get_module_path(mod, display_warning=False)
            for mod in mods
            # The `base` module is typically included inside the odoo module
            # and we don't want to search it twice
            # A more principled way to filter it out would be to check all
            # addons for being a subdirectory of `odoo`
            if mod != "base"
        ]
        paths.append(os.path.dirname(odoo.__file__))
        argv.extend(os.path.realpath(path) for path in paths if path)
        subprocess.Popen(argv).wait()