From a82a43ba50a511edbbb406ab7eb846b640172532 Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Sun, 26 Sep 2021 12:21:01 +0100 Subject: [PATCH] wip --- base_module_pip/README.rst | 1 + base_module_pip/__init__.py | 2 + base_module_pip/__manifest__.py | 19 ++++++++ base_module_pip/models/__init__.py | 1 + base_module_pip/models/base_module.py | 26 +++++++++++ base_module_pip/readme/DESCRIPTION.rst | 1 + base_module_pip/security/ir.model.access.csv | 2 + base_module_pip/tests/__init__.py | 1 + base_module_pip/tests/test_pip_install.py | 12 +++++ base_module_pip/wizards/__init__.py | 1 + .../wizards/base_module_pip_install.py | 31 +++++++++++++ .../wizards/base_module_pip_install_views.xml | 46 +++++++++++++++++++ .../odoo/addons/base_module_pip | 1 + setup/base_module_pip/setup.py | 6 +++ 14 files changed, 150 insertions(+) create mode 100644 base_module_pip/README.rst create mode 100644 base_module_pip/__init__.py create mode 100644 base_module_pip/__manifest__.py create mode 100644 base_module_pip/models/__init__.py create mode 100644 base_module_pip/models/base_module.py create mode 100644 base_module_pip/readme/DESCRIPTION.rst create mode 100644 base_module_pip/security/ir.model.access.csv create mode 100644 base_module_pip/tests/__init__.py create mode 100644 base_module_pip/tests/test_pip_install.py create mode 100644 base_module_pip/wizards/__init__.py create mode 100644 base_module_pip/wizards/base_module_pip_install.py create mode 100644 base_module_pip/wizards/base_module_pip_install_views.xml create mode 120000 setup/base_module_pip/odoo/addons/base_module_pip create mode 100644 setup/base_module_pip/setup.py diff --git a/base_module_pip/README.rst b/base_module_pip/README.rst new file mode 100644 index 000000000..876fdb5f4 --- /dev/null +++ b/base_module_pip/README.rst @@ -0,0 +1 @@ +Generated diff --git a/base_module_pip/__init__.py b/base_module_pip/__init__.py new file mode 100644 index 000000000..aee8895e7 --- /dev/null +++ b/base_module_pip/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/base_module_pip/__manifest__.py b/base_module_pip/__manifest__.py new file mode 100644 index 000000000..92a8580c4 --- /dev/null +++ b/base_module_pip/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright (C) 2021 Daniel Reis +# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Pip Install Odoo Modules", + "version": "14.0.1.0.0", + "category": "Tools", + "author": "Daniel Reis, Odoo Community Association (OCA)", + "license": "LGPL-3", + "website": "https://github.com/OCA/server-backend", + "depends": ["base"], + "data": [ + "security/ir.model.access.csv", + "wizards/base_module_pip_install_views.xml", + ], + "installable": True, + "maintainers": ["dreispt"], + "development_status": "Beta", +} diff --git a/base_module_pip/models/__init__.py b/base_module_pip/models/__init__.py new file mode 100644 index 000000000..933659154 --- /dev/null +++ b/base_module_pip/models/__init__.py @@ -0,0 +1 @@ +from . import base_module diff --git a/base_module_pip/models/base_module.py b/base_module_pip/models/base_module.py new file mode 100644 index 000000000..35ea4a733 --- /dev/null +++ b/base_module_pip/models/base_module.py @@ -0,0 +1,26 @@ +# Copyright (C) 2021 Daniel Reis +# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import subprocess +import sys + +from odoo import api, models +from odoo.release import version_info + + +class BaseModule(models.Model): + _inherit = "ir.module.module" + + def _get_pypi_package_name(self, module_name): + server_version = version_info[0] + return "odoo%d-addon-%s" % (server_version, module_name.replace("_", "-")) + + @api.model + def action_pip_install(self, module_name): + pkg_name = self._get_pypi_package_name(module_name) + cmd = (sys.executable, "-m", "pip", "install", pkg_name) + res = subprocess.run( + *cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True + ) + # TODO: find a way for res to have line breaks? + return res diff --git a/base_module_pip/readme/DESCRIPTION.rst b/base_module_pip/readme/DESCRIPTION.rst new file mode 100644 index 000000000..1333ed77b --- /dev/null +++ b/base_module_pip/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +TODO diff --git a/base_module_pip/security/ir.model.access.csv b/base_module_pip/security/ir.model.access.csv new file mode 100644 index 000000000..b3ad12f26 --- /dev/null +++ b/base_module_pip/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_base_module_pip_install,access_base_module_pip_install,model_base_module_pip_install,base.group_system,1,1,1,1 diff --git a/base_module_pip/tests/__init__.py b/base_module_pip/tests/__init__.py new file mode 100644 index 000000000..9e3ab42f5 --- /dev/null +++ b/base_module_pip/tests/__init__.py @@ -0,0 +1 @@ +from . import test_pip_install diff --git a/base_module_pip/tests/test_pip_install.py b/base_module_pip/tests/test_pip_install.py new file mode 100644 index 000000000..d3c4faef8 --- /dev/null +++ b/base_module_pip/tests/test_pip_install.py @@ -0,0 +1,12 @@ +# Copyright (C) 2021 Daniel Reis +# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.tests.common import TransactionCase + + +class TestPipInstall(TransactionCase): + def test_get_pypi_package_name(self): + module_name = "mis_builder" + pkg_name = self.env["ir.module.module"]._get_pypi_package_name(module_name) + self.assertEqual(pkg_name, "odoo14-addon-mis-builder") diff --git a/base_module_pip/wizards/__init__.py b/base_module_pip/wizards/__init__.py new file mode 100644 index 000000000..c923868dc --- /dev/null +++ b/base_module_pip/wizards/__init__.py @@ -0,0 +1 @@ +from . import base_module_pip_install diff --git a/base_module_pip/wizards/base_module_pip_install.py b/base_module_pip/wizards/base_module_pip_install.py new file mode 100644 index 000000000..20d932461 --- /dev/null +++ b/base_module_pip/wizards/base_module_pip_install.py @@ -0,0 +1,31 @@ +# Copyright (C) 2021 Daniel Reis +# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import fields, models + + +class BaseModulePipInstall(models.TransientModel): + _name = "base.module.pip.install" + _description = "Pip Install Module" + + module_name = fields.Char() + + def action_module_open(self): + return { + "domain": [], # TODO: filter by module name + "name": "Modules", + "view_mode": "tree,form", + "res_model": "ir.module.module", + "view_id": False, + "type": "ir.actions.act_window", + } + + def button_pip_install(self): + Module = self.env["ir.module.module"] + for wizard in self: + Module.action_pip_install(wizard.module_name) + # TODO: present output on form (mayve use states on wizard form) + # TODO: update modules list + # TODO: also install module_name? + return self.action_module_open() diff --git a/base_module_pip/wizards/base_module_pip_install_views.xml b/base_module_pip/wizards/base_module_pip_install_views.xml new file mode 100644 index 000000000..2d7d122f3 --- /dev/null +++ b/base_module_pip/wizards/base_module_pip_install_views.xml @@ -0,0 +1,46 @@ + + + + + Pip Install Modules + base.module.pip.install + + +
+

Type the modeule name to be installed.

+

The module name will be converted into the Pypi expected package name, + and that package will be installed

+ + +
+
+ + +
+
+ + + Pip Install Module + ir.actions.act_window + base.module.pip.install + form + new + + + + +
diff --git a/setup/base_module_pip/odoo/addons/base_module_pip b/setup/base_module_pip/odoo/addons/base_module_pip new file mode 120000 index 000000000..ad1b60c46 --- /dev/null +++ b/setup/base_module_pip/odoo/addons/base_module_pip @@ -0,0 +1 @@ +../../../../base_module_pip \ No newline at end of file diff --git a/setup/base_module_pip/setup.py b/setup/base_module_pip/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/base_module_pip/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)