diff --git a/module_auto_update/README.rst b/module_auto_update/README.rst new file mode 100644 index 00000000000..7f0ef057d88 --- /dev/null +++ b/module_auto_update/README.rst @@ -0,0 +1,129 @@ +================== +Module Auto Update +================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3544468e931dc11637cfb88c85e1486accc4d9252d879ce9e8a0ba4a7ccedfbd + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/18.0/module_auto_update + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-module_auto_update + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon provides mechanisms to compute sha1 hashes of installed +addons, and save them in the database. It also provides a method that +exploits these mechanisms to update a database by upgrading only the +modules for which the hash has changed since the last successful +upgrade. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +This module supports the following system parameters: + +- ``module_auto_update.exclude_patterns``: comma-separated list of file + name patterns to ignore when computing addon checksums. Defaults to + ``*.pyc,*.pyo,i18n/*.pot,i18n_extra/*.pot,static/*``. Filename + patterns must be compatible with the python ``fnmatch`` function. + +In addition to the above pattern, .po files corresponding to languages +that are not installed in the Odoo database are ignored when computing +checksums. + +Usage +===== + +The main method provided by this module is ``upgrade_changed_checksum`` +on ``ir.module.module``. It runs a database upgrade for all installed +modules for which the hash has changed since the last successful run of +this method. On success it saves the hashes in the database. + +The first time this method is invoked after installing the module, it +runs an upgrade of all modules, because it has not saved the hashes yet. +This is by design, priviledging safety. Should this be an issue, the +method ``_save_installed_checksums`` can be invoked in a situation where +one is sure all modules on disk are installed and up-to-date in the +database. + +To invoke the upgrade mechanism, navigate to *Apps* menu and use the +*Auto-Upgrade Modules* button, available only in developer mode. +Restarting the Odoo instance is highly recommended to minify risk of any +possible issues. + +Another easy way to invoke this upgrade mechanism is by issuing the +following in an Odoo shell session: + +.. code:: python + + env['ir.module.module'].upgrade_changed_checksum() + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* LasLabs +* Juan José Scarafía +* Tecnativa +* ACSONE SA/NV + +Contributors +------------ + +- Brent Hughes +- Juan José Scarafía +- Jairo Llopis +- Stéphane Bidoul (https://acsone.eu) +- Eric Antones +- Manuel Engel + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/module_auto_update/__init__.py b/module_auto_update/__init__.py new file mode 100644 index 00000000000..c5d48b349d3 --- /dev/null +++ b/module_auto_update/__init__.py @@ -0,0 +1,4 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import models +from .hooks import uninstall_hook diff --git a/module_auto_update/__manifest__.py b/module_auto_update/__manifest__.py new file mode 100644 index 00000000000..7eeb64d6699 --- /dev/null +++ b/module_auto_update/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 Brainbean Apps (https://brainbeanapps.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +{ + "name": "Module Auto Update", + "summary": "Automatically update Odoo modules", + "version": "18.0.1.0.0", + "category": "Extra Tools", + "website": "https://github.com/OCA/server-tools", + "author": "LasLabs, " + "Juan José Scarafía, " + "Tecnativa, " + "ACSONE SA/NV, " + "Odoo Community Association (OCA)", + "license": "LGPL-3", + "installable": True, + "uninstall_hook": "uninstall_hook", + "depends": ["base"], + "data": ["views/ir_module_module.xml"], + "development_status": "Production/Stable", +} diff --git a/module_auto_update/addon_hash.py b/module_auto_update/addon_hash.py new file mode 100644 index 00000000000..4027bcd8971 --- /dev/null +++ b/module_auto_update/addon_hash.py @@ -0,0 +1,44 @@ +# Copyright 2018 ACSONE SA/NV. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +import hashlib +import os +from fnmatch import fnmatch + + +def _fnmatch(filename, patterns): + for pattern in patterns: + if fnmatch(filename, pattern): + return True + return False + + +def _walk(top, exclude_patterns, keep_langs): + keep_langs = {language.split("_")[0] for language in keep_langs} + for dirpath, dirnames, filenames in os.walk(top): + dirnames.sort() + reldir = os.path.relpath(dirpath, top) + if reldir == ".": + reldir = "" + for filename in sorted(filenames): + filepath = os.path.join(reldir, filename) + if _fnmatch(filepath, exclude_patterns): + continue + if keep_langs and reldir in {"i18n", "i18n_extra"}: + basename, ext = os.path.splitext(filename) + if ext == ".po": + if basename.split("_")[0] not in keep_langs: + continue + yield filepath + + +def addon_hash(top, exclude_patterns, keep_langs): + """Compute a sha1 digest of file contents.""" + m = hashlib.sha1() + for filepath in _walk(top, exclude_patterns, keep_langs): + # hash filename so empty files influence the hash + m.update(filepath.encode("utf-8")) + # hash file content + with open(os.path.join(top, filepath), "rb") as f: + m.update(f.read()) + return m.hexdigest() diff --git a/module_auto_update/hooks.py b/module_auto_update/hooks.py new file mode 100644 index 00000000000..08e06ed8fdd --- /dev/null +++ b/module_auto_update/hooks.py @@ -0,0 +1,11 @@ +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from odoo import SUPERUSER_ID, api + +from .models.module import PARAM_INSTALLED_CHECKSUMS + + +def uninstall_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + env["ir.config_parameter"].set_param(PARAM_INSTALLED_CHECKSUMS, False) diff --git a/module_auto_update/i18n/ca.po b/module_auto_update/i18n/ca.po new file mode 100644 index 00000000000..b849b9d3b60 --- /dev/null +++ b/module_auto_update/i18n/ca.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-21 02:43+0000\n" +"PO-Revision-Date: 2017-07-21 02:43+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Catalan (https://www.transifex.com/oca/teams/23907/ca/)\n" +"Language: ca\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Mòdul" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" diff --git a/module_auto_update/i18n/cs_CZ.po b/module_auto_update/i18n/cs_CZ.po new file mode 100644 index 00000000000..c7b7232d841 --- /dev/null +++ b/module_auto_update/i18n/cs_CZ.po @@ -0,0 +1,71 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# Lukáš Spurný , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-03-03 10:08+0000\n" +"PO-Revision-Date: 2018-03-03 10:08+0000\n" +"Last-Translator: Lukáš Spurný , 2018\n" +"Language-Team: Czech (Czech Republic) (https://www.transifex.com/oca/" +"teams/23907/cs_CZ/)\n" +"Language: cs_CZ\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Modul" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" + +#~ msgid "Checksum Dir" +#~ msgstr "Kontrolní součet Dir" + +#~ msgid "Checksum Installed" +#~ msgstr "Kontrolní součet je nainstalován" + +#~ msgid "Module Upgrade" +#~ msgstr "Aktualizace modulů" + +#~ msgid "Perform Module Upgrades" +#~ msgstr "Provést aktualizaci modulů" + +#~ msgid "Modules" +#~ msgstr "Moduly" + +#~ msgid "Open Updates and Update Apps List Server Action" +#~ msgstr "Otevřít aktualizaci a aktualizovat seznam serverových akcí" + +#~ msgid "Scheduled Upgrades" +#~ msgstr "Plánované aktualizace" + +#~ msgid "Updates" +#~ msgstr "Aktualizace" diff --git a/module_auto_update/i18n/de.po b/module_auto_update/i18n/de.po new file mode 100644 index 00000000000..841baa2a324 --- /dev/null +++ b/module_auto_update/i18n/de.po @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# Niki Waibel , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-21 02:43+0000\n" +"PO-Revision-Date: 2017-07-21 02:43+0000\n" +"Last-Translator: Niki Waibel , 2017\n" +"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Modul" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" + +#~ msgid "Module Upgrade" +#~ msgstr "Modul aktualisieren" + +#, fuzzy +#~ msgid "Perform Module Upgrades" +#~ msgstr "Modul aktualisieren" diff --git a/module_auto_update/i18n/es.po b/module_auto_update/i18n/es.po new file mode 100644 index 00000000000..dd02e900d69 --- /dev/null +++ b/module_auto_update/i18n/es.po @@ -0,0 +1,65 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# OCA Transbot , 2018 +# enjolras , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-03-03 10:08+0000\n" +"PO-Revision-Date: 2023-09-03 00:15+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "Módulos de actualización automática" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "Actualización de la suma de comprobación completada." + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Módulo" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" +"No se ha detectado ningún cambio en la suma de comprobación de los módulos " +"instalados y todos los módulos están instalados, no hay nada que hacer." + +#~ msgid "Smart Search" +#~ msgstr "Búsqueda inteligente" + +#~ msgid "Module Upgrade" +#~ msgstr "Actualización de módulo" + +#~ msgid "Modules" +#~ msgstr "Módulos" + +#~ msgid "Scheduled Upgrades" +#~ msgstr "Actualizaciones programadas" + +#~ msgid "Updates" +#~ msgstr "Actualizaciones" diff --git a/module_auto_update/i18n/es_AR.po b/module_auto_update/i18n/es_AR.po new file mode 100644 index 00000000000..f944b1a6be4 --- /dev/null +++ b/module_auto_update/i18n/es_AR.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-06-09 16:09+0000\n" +"Last-Translator: Ignacio Buioli \n" +"Language-Team: none\n" +"Language: es_AR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "Módulos Auto-Actualizables" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "Actualización de suma de comprobación completa." + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Módulo" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" +"No se detectó ningún cambio de suma de comprobación en los módulos " +"instalados y todos los módulos instalados, nada que hacer." + +#~ msgid "Smart Search" +#~ msgstr "Búsqueda Inteligente" diff --git a/module_auto_update/i18n/es_MX.po b/module_auto_update/i18n/es_MX.po new file mode 100644 index 00000000000..41832a6b174 --- /dev/null +++ b/module_auto_update/i18n/es_MX.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-21 02:43+0000\n" +"PO-Revision-Date: 2017-07-21 02:43+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Spanish (Mexico) (https://www.transifex.com/oca/teams/23907/" +"es_MX/)\n" +"Language: es_MX\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Módulo" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" diff --git a/module_auto_update/i18n/fr.po b/module_auto_update/i18n/fr.po new file mode 100644 index 00000000000..b3454b0cbda --- /dev/null +++ b/module_auto_update/i18n/fr.po @@ -0,0 +1,77 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# Nicolas JEUDY , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-03-03 10:08+0000\n" +"PO-Revision-Date: 2021-05-14 19:47+0000\n" +"Last-Translator: Yves Le Doeuff \n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "Mise à jour automatique des modules" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Module" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" + +#~ msgid "Smart Search" +#~ msgstr "Recherche intelligente" + +#~ msgid "Display Name" +#~ msgstr "Nom affiché" + +#~ msgid "Checksum Dir" +#~ msgstr "Somme de contrôle du dossier" + +#~ msgid "Checksum Installed" +#~ msgstr "Somme de contrôle installée" + +#~ msgid "Module Upgrade" +#~ msgstr "Mise à niveau du module" + +#~ msgid "Perform Module Upgrades" +#~ msgstr "Appliquer les mise à jour de modules" + +#~ msgid "Modules" +#~ msgstr "Modules" + +#~ msgid "Open Updates and Update Apps List Server Action" +#~ msgstr "Afficher les mises à jour" + +#~ msgid "Scheduled Upgrades" +#~ msgstr "Planifier les mises à jour" + +#~ msgid "Updates" +#~ msgstr "Mises à jour" diff --git a/module_auto_update/i18n/hr.po b/module_auto_update/i18n/hr.po new file mode 100644 index 00000000000..b6cfb2113f9 --- /dev/null +++ b/module_auto_update/i18n/hr.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# Bole , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-21 02:43+0000\n" +"PO-Revision-Date: 2017-07-21 02:43+0000\n" +"Last-Translator: Bole , 2017\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Modul" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" diff --git a/module_auto_update/i18n/it.po b/module_auto_update/i18n/it.po new file mode 100644 index 00000000000..1faf9bdced5 --- /dev/null +++ b/module_auto_update/i18n/it.po @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-21 02:43+0000\n" +"PO-Revision-Date: 2024-05-03 16:34+0000\n" +"Last-Translator: mymage \n" +"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "Aggiorna Moduli Automaticamente" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "Aggiornamento checksum completo." + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Modulo" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" +"Nessuna modifica del checksum rilevata nei moduli installati e tutti i " +"moduli installati, niente da fare." + +#~ msgid "Smart Search" +#~ msgstr "Ricerca intelligente" + +#~ msgid "Display Name" +#~ msgstr "Nome da visualizzare" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Ultima modifica il" diff --git a/module_auto_update/i18n/module_auto_update.pot b/module_auto_update/i18n/module_auto_update.pot new file mode 100644 index 00000000000..3a59248b97f --- /dev/null +++ b/module_auto_update/i18n/module_auto_update.pot @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" diff --git a/module_auto_update/i18n/nl_NL.po b/module_auto_update/i18n/nl_NL.po new file mode 100644 index 00000000000..f1c0a5b96f7 --- /dev/null +++ b/module_auto_update/i18n/nl_NL.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# Peter Hageman , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-21 02:43+0000\n" +"PO-Revision-Date: 2017-07-21 02:43+0000\n" +"Last-Translator: Peter Hageman , 2017\n" +"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/" +"teams/23907/nl_NL/)\n" +"Language: nl_NL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Module" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" diff --git a/module_auto_update/i18n/pt_BR.po b/module_auto_update/i18n/pt_BR.po new file mode 100644 index 00000000000..5e06105a2fb --- /dev/null +++ b/module_auto_update/i18n/pt_BR.po @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-21 02:43+0000\n" +"PO-Revision-Date: 2019-08-30 14:37+0000\n" +"Last-Translator: Rodrigo Macedo \n" +"Language-Team: Portuguese (Brazil) (https://www.transifex.com/oca/" +"teams/23907/pt_BR/)\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 3.8\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "Módulos de atualização automática" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Módulo" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" diff --git a/module_auto_update/i18n/sl.po b/module_auto_update/i18n/sl.po new file mode 100644 index 00000000000..d7baeac7bab --- /dev/null +++ b/module_auto_update/i18n/sl.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-21 02:43+0000\n" +"PO-Revision-Date: 2017-07-21 02:43+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n" +"Language: sl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n" +"%100==4 ? 2 : 3);\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Modul" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" diff --git a/module_auto_update/i18n/tr.po b/module_auto_update/i18n/tr.po new file mode 100644 index 00000000000..e626244e4f2 --- /dev/null +++ b/module_auto_update/i18n/tr.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-21 02:43+0000\n" +"PO-Revision-Date: 2017-07-21 02:43+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Turkish (https://www.transifex.com/oca/teams/23907/tr/)\n" +"Language: tr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "Modül" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "" diff --git a/module_auto_update/i18n/zh_CN.po b/module_auto_update/i18n/zh_CN.po new file mode 100644 index 00000000000..77d784b1a08 --- /dev/null +++ b/module_auto_update/i18n/zh_CN.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * module_auto_update +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-06-16 11:08+0000\n" +"Last-Translator: xtanuiha \n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 4.17\n" + +#. module: module_auto_update +#: model:ir.actions.server,name:module_auto_update.ir_module_module_upgrade_changed_checksum +#: model:ir.ui.menu,name:module_auto_update.menu_ir_module_module_upgrade_changed_checksum +msgid "Auto-Upgrade Modules" +msgstr "自动升级模块" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "Checksum upgrade complete." +msgstr "校验升级完成。" + +#. module: module_auto_update +#: model:ir.model,name:module_auto_update.model_ir_module_module +msgid "Module" +msgstr "模块" + +#. module: module_auto_update +#. odoo-python +#: code:addons/module_auto_update/models/module.py:0 +#, python-format +msgid "" +"No checksum change detected in installed modules and all modules installed, " +"nothing to do." +msgstr "未检测到已安装模块中的校验变更,并且所有模块均已安装,无需操作。" diff --git a/module_auto_update/models/__init__.py b/module_auto_update/models/__init__.py new file mode 100644 index 00000000000..99672cfeb84 --- /dev/null +++ b/module_auto_update/models/__init__.py @@ -0,0 +1,3 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import module diff --git a/module_auto_update/models/module.py b/module_auto_update/models/module.py new file mode 100644 index 00000000000..45fe89103dc --- /dev/null +++ b/module_auto_update/models/module.py @@ -0,0 +1,194 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +import json +import logging +import os + +from odoo import _, api, exceptions, models, tools +from odoo.modules.module import get_module_path + +from ..addon_hash import addon_hash + +PARAM_INSTALLED_CHECKSUMS = "module_auto_update.installed_checksums" +PARAM_EXCLUDE_PATTERNS = "module_auto_update.exclude_patterns" +DEFAULT_EXCLUDE_PATTERNS = "*.pyc,*.pyo,i18n/*.pot,i18n_extra/*.pot,static/*" + +_logger = logging.getLogger(__name__) + + +class FailedUpgradeError(exceptions.UserError): + pass + + +class IncompleteUpgradeError(exceptions.UserError): + pass + + +def ensure_module_state(env, modules, state): + # read module states, bypassing any Odoo cache + if not modules: + return + env.cr.execute( + "SELECT name FROM ir_module_module " "WHERE id IN %s AND state != %s", + (tuple(modules.ids), state), + ) + names = [r[0] for r in env.cr.fetchall()] + if names: + raise FailedUpgradeError( + f"The following modules should be in state {state!r} " + f"at this stage: {','.join(names)}. Bailing out for safety." + ) + + +class Module(models.Model): + _inherit = "ir.module.module" + + def _get_checksum_dir(self): + self.ensure_one() + + exclude_patterns = self.env["ir.config_parameter"].get_param( + PARAM_EXCLUDE_PATTERNS, + DEFAULT_EXCLUDE_PATTERNS, + ) + exclude_patterns = [p.strip() for p in exclude_patterns.split(",")] + keep_langs = self.env["res.lang"].search([]).mapped("code") + + module_path = get_module_path(self.name) + if module_path and os.path.isdir(module_path): + checksum_dir = addon_hash( + module_path, + exclude_patterns, + keep_langs, + ) + else: + checksum_dir = False + + return checksum_dir + + @api.model + def _get_saved_checksums(self): + Icp = self.env["ir.config_parameter"] + return json.loads(Icp.get_param(PARAM_INSTALLED_CHECKSUMS, "{}")) + + @api.model + def _save_checksums(self, checksums): + Icp = self.env["ir.config_parameter"] + Icp.set_param(PARAM_INSTALLED_CHECKSUMS, json.dumps(checksums)) + Icp.flush_model() + + @api.model + def _save_installed_checksums(self): + checksums = {} + installed_modules = self.search([("state", "=", "installed")]) + for module in installed_modules: + checksums[module.name] = module._get_checksum_dir() + self._save_checksums(checksums) + + @api.model + def _get_modules_partially_installed(self): + return self.search([("state", "in", ("to install", "to remove", "to upgrade"))]) + + @api.model + def _get_modules_with_changed_checksum(self): + saved_checksums = self._get_saved_checksums() + installed_modules = self.search([("state", "=", "installed")]) + return installed_modules.filtered( + lambda r: r._get_checksum_dir() != saved_checksums.get(r.name), + ) + + @api.model + def upgrade_changed_checksum(self, overwrite_existing_translations=False): + """Run an upgrade of the database, upgrading only changed modules. + + Installed modules for which the checksum has changed since the + last successful run of this method are marked "to upgrade", + then the normal Odoo scheduled upgrade process + is launched. + + If there is no module with a changed checksum, and no module in state + other than installed, uninstalled, uninstallable, this method does + nothing, otherwise the normal Odoo upgrade process is launched. + + After a successful upgrade, the checksums of installed modules are + saved. + + In case of error during the upgrade, an exception is raised. + If any module remains to upgrade or to uninstall after the upgrade + process, an exception is raised as well. + + Note: this method commits the current transaction at each important + step, it is therefore not intended to be run as part of a + larger transaction. + """ + _logger.info( + "Checksum upgrade starting (i18n-overwrite=%s)...", + overwrite_existing_translations, + ) + + tools.config["overwrite_existing_translations"] = ( + overwrite_existing_translations + ) + + _logger.info("Updating modules list...") + self.update_list() + changed_modules = self._get_modules_with_changed_checksum() + if not changed_modules and not self._get_modules_partially_installed(): + _logger.info( + "No checksum change detected in installed modules " + "and all modules installed, nothing to do." + ) + + return { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "message": _( + "No checksum change detected in installed modules " + "and all modules installed, nothing to do." + ), + "type": "success", + "sticky": False, + }, + } + + _logger.info( + "Marking the following modules to upgrade, " + "for their checksums changed: %s...", + ",".join(changed_modules.mapped("name")), + ) + changed_modules.button_upgrade() + self.env.cr.commit() # pylint: disable=invalid-commit + # in rare situations, button_upgrade may fail without + # exception, this would lead to corruption because + # no upgrade would be performed and save_installed_checksums + # would update cheksums for modules that have not been upgraded + ensure_module_state(self.env, changed_modules, "to upgrade") + + _logger.info("Upgrading...") + self.env["base.module.upgrade"].upgrade_module() + self.env.cr.commit() # pylint: disable=invalid-commit + + _logger.info("Upgrade successful, updating checksums...") + self._save_installed_checksums() + self.env.cr.commit() # pylint: disable=invalid-commit + + partial_modules = self._get_modules_partially_installed() + if partial_modules: + raise IncompleteUpgradeError( + "Checksum upgrade successful " + "but incomplete for the following modules: " + f"{','.join(partial_modules.mapped('name'))}" + ) + + _logger.info("Checksum upgrade complete.") + return { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "message": _("Checksum upgrade complete."), + "type": "success", + "sticky": False, + }, + } diff --git a/module_auto_update/pyproject.toml b/module_auto_update/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/module_auto_update/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/module_auto_update/readme/CONFIGURE.md b/module_auto_update/readme/CONFIGURE.md new file mode 100644 index 00000000000..2a70fffeeff --- /dev/null +++ b/module_auto_update/readme/CONFIGURE.md @@ -0,0 +1,10 @@ +This module supports the following system parameters: + +- `module_auto_update.exclude_patterns`: comma-separated list of file + name patterns to ignore when computing addon checksums. Defaults to + `*.pyc,*.pyo,i18n/*.pot,i18n_extra/*.pot,static/*`. Filename patterns + must be compatible with the python `fnmatch` function. + +In addition to the above pattern, .po files corresponding to languages +that are not installed in the Odoo database are ignored when computing +checksums. diff --git a/module_auto_update/readme/CONTRIBUTORS.md b/module_auto_update/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..1f9de3e9429 --- /dev/null +++ b/module_auto_update/readme/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- Brent Hughes \<\> +- Juan José Scarafía \<\> +- Jairo Llopis \<\> +- Stéphane Bidoul \<\> () +- Eric Antones \<\> +- Manuel Engel \<\> diff --git a/module_auto_update/readme/DESCRIPTION.md b/module_auto_update/readme/DESCRIPTION.md new file mode 100644 index 00000000000..1d5c443af7a --- /dev/null +++ b/module_auto_update/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This addon provides mechanisms to compute sha1 hashes of installed +addons, and save them in the database. It also provides a method that +exploits these mechanisms to update a database by upgrading only the +modules for which the hash has changed since the last successful +upgrade. diff --git a/module_auto_update/readme/USAGE.md b/module_auto_update/readme/USAGE.md new file mode 100644 index 00000000000..e38b3a40356 --- /dev/null +++ b/module_auto_update/readme/USAGE.md @@ -0,0 +1,23 @@ +The main method provided by this module is `upgrade_changed_checksum` on +`ir.module.module`. It runs a database upgrade for all installed modules +for which the hash has changed since the last successful run of this +method. On success it saves the hashes in the database. + +The first time this method is invoked after installing the module, it +runs an upgrade of all modules, because it has not saved the hashes yet. +This is by design, priviledging safety. Should this be an issue, the +method `_save_installed_checksums` can be invoked in a situation where +one is sure all modules on disk are installed and up-to-date in the +database. + +To invoke the upgrade mechanism, navigate to *Apps* menu and use the +*Auto-Upgrade Modules* button, available only in developer mode. +Restarting the Odoo instance is highly recommended to minify risk of any +possible issues. + +Another easy way to invoke this upgrade mechanism is by issuing the +following in an Odoo shell session: + +``` python +env['ir.module.module'].upgrade_changed_checksum() +``` diff --git a/module_auto_update/static/description/icon.png b/module_auto_update/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/module_auto_update/static/description/icon.png differ diff --git a/module_auto_update/static/description/index.html b/module_auto_update/static/description/index.html new file mode 100644 index 00000000000..8a8f2b7e187 --- /dev/null +++ b/module_auto_update/static/description/index.html @@ -0,0 +1,472 @@ + + + + + +Module Auto Update + + + +
+

Module Auto Update

+ + +

Production/Stable License: LGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

This addon provides mechanisms to compute sha1 hashes of installed +addons, and save them in the database. It also provides a method that +exploits these mechanisms to update a database by upgrading only the +modules for which the hash has changed since the last successful +upgrade.

+

Table of contents

+ +
+

Configuration

+

This module supports the following system parameters:

+
    +
  • module_auto_update.exclude_patterns: comma-separated list of file +name patterns to ignore when computing addon checksums. Defaults to +*.pyc,*.pyo,i18n/*.pot,i18n_extra/*.pot,static/*. Filename +patterns must be compatible with the python fnmatch function.
  • +
+

In addition to the above pattern, .po files corresponding to languages +that are not installed in the Odoo database are ignored when computing +checksums.

+
+
+

Usage

+

The main method provided by this module is upgrade_changed_checksum +on ir.module.module. It runs a database upgrade for all installed +modules for which the hash has changed since the last successful run of +this method. On success it saves the hashes in the database.

+

The first time this method is invoked after installing the module, it +runs an upgrade of all modules, because it has not saved the hashes yet. +This is by design, priviledging safety. Should this be an issue, the +method _save_installed_checksums can be invoked in a situation where +one is sure all modules on disk are installed and up-to-date in the +database.

+

To invoke the upgrade mechanism, navigate to Apps menu and use the +Auto-Upgrade Modules button, available only in developer mode. +Restarting the Odoo instance is highly recommended to minify risk of any +possible issues.

+

Another easy way to invoke this upgrade mechanism is by issuing the +following in an Odoo shell session:

+
+env['ir.module.module'].upgrade_changed_checksum()
+
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • LasLabs
  • +
  • Juan José Scarafía
  • +
  • Tecnativa
  • +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/server-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/module_auto_update/tests/__init__.py b/module_auto_update/tests/__init__.py new file mode 100644 index 00000000000..98ee93c7ecf --- /dev/null +++ b/module_auto_update/tests/__init__.py @@ -0,0 +1,4 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import test_addon_hash +from . import test_module diff --git a/module_auto_update/tests/sample_module/README.rst b/module_auto_update/tests/sample_module/README.rst new file mode 100644 index 00000000000..e7d1726ca4c --- /dev/null +++ b/module_auto_update/tests/sample_module/README.rst @@ -0,0 +1 @@ +Sample module for tests addon_hash module. diff --git a/module_auto_update/tests/sample_module/data/f1.xml b/module_auto_update/tests/sample_module/data/f1.xml new file mode 100644 index 00000000000..23850747975 --- /dev/null +++ b/module_auto_update/tests/sample_module/data/f1.xml @@ -0,0 +1 @@ + diff --git a/module_auto_update/tests/sample_module/data/f2.xml b/module_auto_update/tests/sample_module/data/f2.xml new file mode 100644 index 00000000000..23850747975 --- /dev/null +++ b/module_auto_update/tests/sample_module/data/f2.xml @@ -0,0 +1 @@ + diff --git a/module_auto_update/tests/sample_module/i18n/en_US.po b/module_auto_update/tests/sample_module/i18n/en_US.po new file mode 100644 index 00000000000..e69de29bb2d diff --git a/module_auto_update/tests/sample_module/i18n/fr.po b/module_auto_update/tests/sample_module/i18n/fr.po new file mode 100644 index 00000000000..e69de29bb2d diff --git a/module_auto_update/tests/sample_module/i18n/fr_BE.po b/module_auto_update/tests/sample_module/i18n/fr_BE.po new file mode 100644 index 00000000000..e69de29bb2d diff --git a/module_auto_update/tests/sample_module/i18n/test.pot b/module_auto_update/tests/sample_module/i18n/test.pot new file mode 100644 index 00000000000..e69de29bb2d diff --git a/module_auto_update/tests/sample_module/i18n_extra/en.po b/module_auto_update/tests/sample_module/i18n_extra/en.po new file mode 100644 index 00000000000..e69de29bb2d diff --git a/module_auto_update/tests/sample_module/i18n_extra/fr.po b/module_auto_update/tests/sample_module/i18n_extra/fr.po new file mode 100644 index 00000000000..e69de29bb2d diff --git a/module_auto_update/tests/sample_module/i18n_extra/nl_NL.po b/module_auto_update/tests/sample_module/i18n_extra/nl_NL.po new file mode 100644 index 00000000000..e69de29bb2d diff --git a/module_auto_update/tests/sample_module/models/stuff.py b/module_auto_update/tests/sample_module/models/stuff.py new file mode 100644 index 00000000000..911c43ed15c --- /dev/null +++ b/module_auto_update/tests/sample_module/models/stuff.py @@ -0,0 +1 @@ +_ = 1 + 1 diff --git a/module_auto_update/tests/sample_module/models/stuff.pyc b/module_auto_update/tests/sample_module/models/stuff.pyc new file mode 100644 index 00000000000..2050f52c7c2 Binary files /dev/null and b/module_auto_update/tests/sample_module/models/stuff.pyc differ diff --git a/module_auto_update/tests/sample_module/models/stuff.pyo b/module_auto_update/tests/sample_module/models/stuff.pyo new file mode 100644 index 00000000000..b592f19841e Binary files /dev/null and b/module_auto_update/tests/sample_module/models/stuff.pyo differ diff --git a/module_auto_update/tests/sample_module/static/src/some.js b/module_auto_update/tests/sample_module/static/src/some.js new file mode 100644 index 00000000000..896fe66fe3e --- /dev/null +++ b/module_auto_update/tests/sample_module/static/src/some.js @@ -0,0 +1 @@ +/* Javascript */ diff --git a/module_auto_update/tests/test_addon_hash.py b/module_auto_update/tests/test_addon_hash.py new file mode 100644 index 00000000000..1923f57c865 --- /dev/null +++ b/module_auto_update/tests/test_addon_hash.py @@ -0,0 +1,76 @@ +# Copyright 2018 ACSONE SA/NV. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +import os + +from odoo.tests import TransactionCase + +from .. import addon_hash +from ..models.module import DEFAULT_EXCLUDE_PATTERNS + + +class TestAddonHash(TransactionCase): + def setUp(self): + super().setUp() + self.sample_dir = os.path.join( + os.path.dirname(__file__), + "sample_module", + ) + + def test_basic(self): + files = list( + addon_hash._walk( + self.sample_dir, + exclude_patterns=["*/__pycache__/*"], + keep_langs=[], + ) + ) + self.assertEqual( + files, + [ + "README.rst", + "data/f1.xml", + "data/f2.xml", + "i18n/en_US.po", + "i18n/fr.po", + "i18n/fr_BE.po", + "i18n/test.pot", + "i18n_extra/en.po", + "i18n_extra/fr.po", + "i18n_extra/nl_NL.po", + "models/stuff.py", + "models/stuff.pyc", + "models/stuff.pyo", + "static/src/some.js", + ], + ) + + def test_exclude(self): + files = list( + addon_hash._walk( + self.sample_dir, + exclude_patterns=DEFAULT_EXCLUDE_PATTERNS.split(","), + keep_langs=["fr_FR", "nl"], + ) + ) + self.assertEqual( + files, + [ + "README.rst", + "data/f1.xml", + "data/f2.xml", + "i18n/fr.po", + "i18n/fr_BE.po", + "i18n_extra/fr.po", + "i18n_extra/nl_NL.po", + "models/stuff.py", + ], + ) + + def test2(self): + checksum = addon_hash.addon_hash( + self.sample_dir, + exclude_patterns=["*.pyc", "*.pyo", "*.pot", "static/*"], + keep_langs=["fr_FR", "nl"], + ) + self.assertEqual(checksum, "5a14909e62f05c340f717bd87f64479a862b1941") diff --git a/module_auto_update/tests/test_module.py b/module_auto_update/tests/test_module.py new file mode 100644 index 00000000000..a010f31a039 --- /dev/null +++ b/module_auto_update/tests/test_module.py @@ -0,0 +1,232 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +import os +import tempfile +from unittest import mock + +import odoo +from odoo.modules import get_module_path +from odoo.tests import TransactionCase + +from ..addon_hash import addon_hash +from ..models.module import DEFAULT_EXCLUDE_PATTERNS, IncompleteUpgradeError + +MODULE_NAME = "module_auto_update" + + +class TestModule(TransactionCase): + def setUp(self): + super().setUp() + self.own_module = self.env["ir.module.module"].search( + [("name", "=", MODULE_NAME)] + ) + self.own_dir_path = get_module_path(MODULE_NAME) + keep_langs = self.env["res.lang"].search([]).mapped("code") + self.own_checksum = addon_hash( + self.own_dir_path, + exclude_patterns=DEFAULT_EXCLUDE_PATTERNS.split(","), + keep_langs=keep_langs, + ) + self.own_writeable = os.access(self.own_dir_path, os.W_OK) + + def test_compute_checksum_dir(self): + """It should compute the directory's SHA-1 hash""" + self.assertEqual( + self.own_module._get_checksum_dir(), + self.own_checksum, + "Module directory checksum not computed properly", + ) + + def test_compute_checksum_dir_ignore_excluded(self): + """It should exclude .pyc/.pyo extensions from checksum + calculations""" + if not self.own_writeable: + self.skipTest("Own directory not writeable") + with tempfile.NamedTemporaryFile(suffix=".pyc", dir=self.own_dir_path): + self.assertEqual( + self.own_module._get_checksum_dir(), + self.own_checksum, + "SHA1 checksum does not ignore excluded extensions", + ) + + def test_compute_checksum_dir_recomputes_when_file_added(self): + """It should return a different value when a non-.pyc/.pyo file is + added to the module directory""" + if not self.own_writeable: + self.skipTest("Own directory not writeable") + with tempfile.NamedTemporaryFile(suffix=".py", dir=self.own_dir_path): + self.assertNotEqual( + self.own_module._get_checksum_dir(), + self.own_checksum, + "SHA1 checksum not recomputed", + ) + + def test_saved_checksums(self): + Imm = self.env["ir.module.module"] + base_module = Imm.search([("name", "=", "base")]) + self.assertEqual(base_module.state, "installed") + self.assertFalse(Imm._get_saved_checksums()) + Imm._save_installed_checksums() + saved_checksums = Imm._get_saved_checksums() + self.assertTrue(saved_checksums) + self.assertTrue(saved_checksums["base"]) + + def test_get_modules_with_changed_checksum(self): + Imm = self.env["ir.module.module"] + self.assertTrue(Imm._get_modules_with_changed_checksum()) + Imm._save_installed_checksums() + self.assertFalse(Imm._get_modules_with_changed_checksum()) + + +@odoo.tests.tagged("post_install", "-at_install") +class TestModuleAfterInstall(TransactionCase): + def setUp(self): + super().setUp() + Imm = self.env["ir.module.module"] + self.own_module = Imm.search([("name", "=", MODULE_NAME)]) + self.base_module = Imm.search([("name", "=", "base")]) + + def test_get_modules_partially_installed(self): + Imm = self.env["ir.module.module"] + self.assertTrue(self.own_module not in Imm._get_modules_partially_installed()) + self.own_module.button_upgrade() + self.assertTrue(self.own_module in Imm._get_modules_partially_installed()) + self.own_module.button_upgrade_cancel() + self.assertTrue(self.own_module not in Imm._get_modules_partially_installed()) + + def test_upgrade_changed_checksum(self): + Imm = self.env["ir.module.module"] + Bmu = type(self.env["base.module.upgrade"]) + + # check modules are in installed state + installed_modules = Imm.search([("state", "=", "installed")]) + self.assertTrue(self.own_module in installed_modules) + self.assertTrue(self.base_module in installed_modules) + self.assertTrue(len(installed_modules) > 2) + # change the checksum of 'base' + Imm._save_installed_checksums() + saved_checksums = Imm._get_saved_checksums() + saved_checksums["base"] = False + Imm._save_checksums(saved_checksums) + changed_modules = Imm._get_modules_with_changed_checksum() + self.assertEqual(len(changed_modules), 1) + self.assertTrue(self.base_module in changed_modules) + + def upgrade_module_mock(self_model): + upgrade_module_mock.call_count += 1 + # since we are upgrading base, all installed module + # must have been marked to upgrade at this stage + self.assertEqual(self.base_module.state, "to upgrade") + self.assertEqual(self.own_module.state, "to upgrade") + installed_modules.write({"state": "installed"}) + + upgrade_module_mock.call_count = 0 + + # upgrade_changed_checksum commits, so mock that + with mock.patch.object(self.env.cr, "commit"): + # we simulate an install by setting module states + origin = Bmu.upgrade_module + Bmu.upgrade_module = upgrade_module_mock + try: + Imm.upgrade_changed_checksum() + self.assertEqual(upgrade_module_mock.call_count, 1) + self.assertEqual(self.base_module.state, "installed") + self.assertEqual(self.own_module.state, "installed") + saved_checksums = Imm._get_saved_checksums() + self.assertTrue(saved_checksums["base"]) + self.assertTrue(saved_checksums[MODULE_NAME]) + finally: + Bmu.upgrade_module = origin + + def test_incomplete_upgrade(self): + Imm = self.env["ir.module.module"] + Bmu = type(self.env["base.module.upgrade"]) + + installed_modules = Imm.search([("state", "=", "installed")]) + # change the checksum of 'base' + Imm._save_installed_checksums() + saved_checksums = Imm._get_saved_checksums() + saved_checksums["base"] = False + Imm._save_checksums(saved_checksums) + + def upgrade_module_mock(self_model): + upgrade_module_mock.call_count += 1 + # since we are upgrading base, all installed module + # must have been marked to upgrade at this stage + self.assertEqual(self.base_module.state, "to upgrade") + self.assertEqual(self.own_module.state, "to upgrade") + installed_modules.write({"state": "installed"}) + # simulate partial upgrade + self.own_module.write({"state": "to upgrade"}) + + upgrade_module_mock.call_count = 0 + + # upgrade_changed_checksum commits, so mock that + with mock.patch.object(self.env.cr, "commit"): + # we simulate an install by setting module states + origin = Bmu.upgrade_module + Bmu.upgrade_module = upgrade_module_mock + try: + with self.assertRaises(IncompleteUpgradeError): + Imm.upgrade_changed_checksum() + self.assertEqual(upgrade_module_mock.call_count, 1) + finally: + Bmu.upgrade_module = origin + + def test_incomplete_upgrade_no_checkusm(self): + Imm = self.env["ir.module.module"] + Bmu = type(self.env["base.module.upgrade"]) + + installed_modules = Imm.search([("state", "=", "installed")]) + # change the checksum of 'base' + Imm._save_installed_checksums() + saved_checksums = Imm._get_saved_checksums() + + Imm._save_checksums(saved_checksums) + self.base_module.write({"state": "to upgrade"}) + + def upgrade_module_mock(self_model): + upgrade_module_mock.call_count += 1 + # since we are upgrading base, all installed module + # must have been marked to upgrade at this stage + self.assertEqual(self.base_module.state, "to upgrade") + self.assertEqual(self.own_module.state, "installed") + installed_modules.write({"state": "installed"}) + + upgrade_module_mock.call_count = 0 + + # upgrade_changed_checksum commits, so mock that + with mock.patch.object(self.env.cr, "commit"): + # we simulate an install by setting module states + origin = Bmu.upgrade_module + Bmu.upgrade_module = upgrade_module_mock + # got just other modules to_upgrade and no checksum ones + try: + Imm.upgrade_changed_checksum() + self.assertEqual(upgrade_module_mock.call_count, 1) + finally: + Bmu.upgrade_module = origin + + def test_nothing_to_upgrade(self): + Imm = self.env["ir.module.module"] + Bmu = type(self.env["base.module.upgrade"]) + + Imm._save_installed_checksums() + + def upgrade_module_mock(self_model): + upgrade_module_mock.call_count += 1 + + upgrade_module_mock.call_count = 0 + + # upgrade_changed_checksum commits, so mock that + with mock.patch.object(self.env.cr, "commit"): + # we simulate an install by setting module states + origin = Bmu.upgrade_module + Bmu.upgrade_module = upgrade_module_mock + try: + Imm.upgrade_changed_checksum() + self.assertEqual(upgrade_module_mock.call_count, 0) + finally: + Bmu.upgrade_module = origin diff --git a/module_auto_update/views/ir_module_module.xml b/module_auto_update/views/ir_module_module.xml new file mode 100644 index 00000000000..05be0e927be --- /dev/null +++ b/module_auto_update/views/ir_module_module.xml @@ -0,0 +1,24 @@ + + + + + Auto-Upgrade Modules + ir.actions.server + + code + + action = model.upgrade_changed_checksum() + + + +