Last active
April 19, 2024 15:40
-
-
Save mao-odoo/8a938dcb5b5806370530aad304489a92 to your computer and use it in GitHub Desktop.
get a list of all custom apps installed on a odoo.sh database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
standard_apps=$(find /home/odoo/src/{odoo,enterprise,themes} -name __manifest__.py | jq -nRr '[inputs] | map(split("/")[-2]) | join(",")'); psql -c "select name, state from ir_module_module where NOT (name = ANY('{$standard_apps,studio_customization}'::text[]) ) and state not in ('uninstalled', 'uninstallable') order by name;" | |
# explanation of the code | |
# find /home/odoo/src/{odoo,enterprise,themes} -name "__manifest__.py" --> list the path to each odoo standard modules | |
# in Jq | |
# [inputs] --> transforms the input text to an array of lines | |
# map(split("/")[-2]) --> for each line, get the directory's name | |
# join(",") --> join the result as a comma seperated list | |
# psql -c XXXXXX --> no need to specify the datbase on odoo.sh | |
# state not in ('uninstalled', 'uninstallable'); --> could be just state = 'installed', but this way we also see modules left in weird states | |
# name = ANY('{a,b}'::text[]) --> alternative syntac for `name in ('a', 'b')` | |
# however, it does require quotes and works fine when the array is empty | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIT License | |
Copyright (c) 2023 Alexandre Moens | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
Contributers : Walravens Mathieu |
Did you know both Jq and PostgreSQL are wonderful? (and jq
is available on odoo.sh)
My alternative command, which does not involve regexes:
psql -c "select name, state from ir_module_module where name = ANY('{$(find /home/odoo/src/user -name __manifest__.py | jq -nRr '[inputs] | map(split("/")[-2]) | join(",")')}'::text[]) and state not in ('uninstalled', 'uninstallable');"
# explanation of Jq
# [inputs] --> transforms the input text to an array of lines
# map(split("/")[-2]) --> for each line, get the directory's name
# join(",") --> join the result
# explanation of psql
# name = ANY('{a,b}'::text[]) --> alternative syntac for `name in ('a', 'b')`
# however, it does require quotes and works fine when the array is empty
Okay that's pretty cool, and much more readable ^^
I'm just gonna keep it as 2 calls for the sake of easy reusability of each part of the commands
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[this comment is outdated and is referring to revision prior to the introduction of jq]
All the string manipulation could probably be done in a single call to sed, but this was simpler to write and I'm lazy