From 078bdce87b3468251dee6ef7382d957c0c9db6b5 Mon Sep 17 00:00:00 2001 From: raneq <46573858+raneq@users.noreply.github.com> Date: Mon, 16 Sep 2019 18:20:55 +0200 Subject: [PATCH] Fix regexp that detects new/upgraded pkgs form pip (#71) * Fix regexp that detects new/upgraded pkgs form pip * It doesn't assume that versions are numbers only. See for instance: https://pypi.org/project/odoo11-addon-l10n-es-mis-report/11.0.2.2.0.99.dev4/ * It uses the Odoo version number (supports from 10 to 19) as a delimiter between odoo module name and version * Add infinite% more of explanation about sed wizardry, and the expected input and output * Update tasks/community-modules.yml --- tasks/community-modules.yml | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tasks/community-modules.yml b/tasks/community-modules.yml index 2ce0eee..db23239 100644 --- a/tasks/community-modules.yml +++ b/tasks/community-modules.yml @@ -14,17 +14,36 @@ become: yes become_user: "{{ odoo_role_odoo_user }}" + # Using the output of pip, detect which packages have been installed, + # both fresh or upgraded. Save the list with a register so that we can + # feed better odoo with it. - name: Detect upgraded packages - shell: > - grep 'Successfully installed' | - sed -r 's/ /\n/g' | - egrep '^odoo1[0-9]-addon-[^ ]+-[0-9\.]+' | - sed -r 's/odoo1[0-9]-addon-([^ ]+)-[0-9\.]+/\1/g' | - tr -- '-' '_' - args: + # Example input (delete '# ' from each line below) + # + # Installing collected packages: odoo11-addon-account-financial-report + # Found existing installation: odoo11-addon-account-financial-report 11.0.2.4.3 + # Uninstalling odoo11-addon-account-financial-report-11.0.2.4.3: + # Successfully uninstalled odoo11-addon-account-financial-report-11.0.2.4.3 + # Successfully installed odoo11-addon-account-financial-report-11.0.2.5.1.99.dev12 odoo11-addon-l10n-es-aeat-mod303-11.0.2.1.0 stdin: "{{ reg_pip.stdout }}" executable: bash + # Expected "output" using input from above (delete '# ' from each line below) + # note: "output" means `reg_pip_upgraded.stdout` + # note: to debug the second regexp you can use https://regexr.com/4l2c3 + # + # account-financial-report + # l10n-es-aeat-mod303 + + # About sed: + # - option `-r` switches to standard perl regexp, instead of GNU ones. Similar to `egrep` or `grep -E` + # - option `-n` combined with flag `/p` prints "nothing" except the result of the script. Therefore, unmatching lines are hidden, and matching lines are shown after processed. + # - capturing groups `(something)` can be referenced inside the matching part or at the replacing part with \1, \2, in order of appearence. + shell: > + grep 'Successfully installed' | + sed -r 's/ /\n/g' | + sed -rn 's/^odoo(1[0-9])-addon-(.+)-\1\..+$/\2/p' | + tr '-' '_' register: reg_pip_upgraded changed_when: reg_pip_upgraded.stdout failed_when: false # noqa 306 "shell and pipefail". Both grep and sed must be able to fail