Skip to content

Commit

Permalink
Fix regexp that detects new/upgraded pkgs form pip (#71)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
raneq authored Sep 16, 2019
1 parent dd20796 commit 078bdce
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions tasks/community-modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 078bdce

Please sign in to comment.