-
Notifications
You must be signed in to change notification settings - Fork 65
[ADD] utils: Util to launch an industry easily #689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arthurrrm
wants to merge
1
commit into
odoo:saas-18.3
Choose a base branch
from
odoo-dev:saas-18.3-utils-zip-import-modules-amer
base: saas-18.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+114
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# Usage function | ||
usage() { | ||
echo "Usage: ./industry/run_industry.sh -i <industry-name> [-d] [-t] [-r]" | ||
echo " -i <industry-name> (re)Install this industry" | ||
echo " -d Enable demo data when installing" | ||
echo " -t Run tests for the installed industry" | ||
echo " -r Reset the database before running" | ||
exit 1 | ||
} | ||
|
||
# Default values | ||
INDUSTRY_NAME="" | ||
INSTALL=false | ||
TEST=false | ||
RESET_DB=false | ||
DEMO=False | ||
|
||
# Parse arguments | ||
while getopts ":i:dtr" opt; do | ||
case $opt in | ||
i) INDUSTRY_NAME="$OPTARG"; INSTALL=true ;; | ||
d) DEMO=True ;; | ||
t) TEST=true ;; | ||
r) RESET_DB=true ;; | ||
*) usage ;; | ||
esac | ||
done | ||
|
||
|
||
echo "Industry: $INDUSTRY_NAME" | ||
echo "Install: $INSTALL" | ||
echo "Demo: $DEMO" | ||
echo "Test: $TEST" | ||
echo "Reset DB: $RESET_DB" | ||
|
||
PYTHON_BIN="python3" | ||
ODOO_BIN="odoo/odoo-bin" | ||
ADDONS_PATH="industry/tests,enterprise,odoo/addons,odoo/odoo/addons,design-themes" | ||
TEST_TAGS="/test_generic,/test_$INDUSTRY_NAME" | ||
DB="test" | ||
|
||
if $RESET_DB; then | ||
echo "Resetting database '$DB'..." | ||
dropdb --if-exists "$DB" | ||
$PYTHON_BIN $ODOO_BIN --addons-path="$ADDONS_PATH" -i base_import_module,test_generic,test_$INDUSTRY_NAME -d $DB --without-demo=1 --stop-after-init | ||
fi | ||
|
||
if $INSTALL; then | ||
echo "Initializing modules..." | ||
|
||
TMP_INSTALL_PY=$(mktemp) | ||
cat <<EOF > "$TMP_INSTALL_PY" | ||
import sys | ||
sys.path.append('industry/') | ||
from utils import get_zip | ||
def main(): | ||
zip = get_zip('$INDUSTRY_NAME', env) | ||
res = env['ir.module.module'].sudo()._import_zipfile(zip, force=False, with_demo=$DEMO) | ||
print(res[0]) | ||
main() | ||
env.cr.commit() | ||
exit() | ||
EOF | ||
cat "$TMP_INSTALL_PY" | $PYTHON_BIN $ODOO_BIN shell --addons-path="$ADDONS_PATH" -d $DB | ||
rm -f "$TMP_INSTALL_PY" | ||
fi | ||
|
||
if $TEST; then | ||
echo "Running tests..." | ||
$PYTHON_BIN $ODOO_BIN --addons-path="$ADDONS_PATH" -d $DB --test-tags $TEST_TAGS | ||
else | ||
echo "Starting Odoo server..." | ||
$PYTHON_BIN $ODOO_BIN --addons-path="$ADDONS_PATH" -d $DB | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
import ast | ||
import os | ||
import shutil | ||
from io import BytesIO | ||
from zipfile import ZipFile, ZIP_DEFLATED | ||
from odoo.tools import file_open, file_open_temporary_directory | ||
|
||
|
||
def get_zip(module_name, env): | ||
output = BytesIO() | ||
zf = ZipFile(output, "w", ZIP_DEFLATED) | ||
external_modules = get_external_dependencies('industry/' + module_name, env) | ||
dirs = ['industry/' + module_name] + ['industry/' + module for module in external_modules] | ||
for dir in dirs: | ||
for dirname, subdirs, files in os.walk(dir): | ||
zip_dirname = os.sep.join(dirname.split(os.sep)[1:]) | ||
zf.write(dirname, zip_dirname) | ||
for filename in files: | ||
zf.write(os.path.join(dirname, filename), os.path.join(zip_dirname, filename)) | ||
zf.close() | ||
return output | ||
|
||
|
||
def get_external_dependencies(dir, env): | ||
manifest_file = dir + '/__manifest__.py' | ||
if not os.path.exists(manifest_file): | ||
raise FileNotFoundError(f"Manifest file not found: {manifest_file}") | ||
with file_open_temporary_directory(env) as temp_dir: | ||
temp_manifest_path = os.path.join(temp_dir, '__manifest__.py') | ||
shutil.copy(manifest_file, temp_manifest_path) | ||
with file_open(temp_manifest_path, env=env) as f: | ||
manifest = ast.literal_eval(f.read()) | ||
dependencies = set(manifest.get('depends', ['base'])) | ||
known_modules = env['ir.module.module'].search([]).mapped('name') | ||
return dependencies.difference(known_modules) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.