Skip to content

Commit 49acfc2

Browse files
[UP] add more tool in workspace
1 parent 67abd76 commit 49acfc2

17 files changed

Lines changed: 274 additions & 100 deletions

.vscode/launch.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
"copilot"
3636
],
3737
"cwd": "${input:odooProjectPath}"
38+
},
39+
{
40+
"name": "Init Ubuntu",
41+
"type": "debugpy",
42+
"request": "launch",
43+
"program": "${workspaceFolder}/src/otoolbox/__init__.py",
44+
"console": "integratedTerminal",
45+
"args": [
46+
"ubuntu",
47+
"init"
48+
],
49+
"cwd": "${input:odooProjectPath}"
3850
}
3951
]
4052
}

src/otoolbox/addons/help/WORKSPACE_README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,15 @@ This is a maintainer tool from odoonix
1111

1212
### MoonSun
1313

14-
### Odoonix
14+
### Odoonix
15+
16+
17+
### Tools
18+
19+
Run the command to see list of commands:
20+
21+
ls .venv/bin/bulk-*
22+
23+
NOTE: the VENV must be active to use tools.
24+
25+
.

src/otoolbox/addons/logger/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Resources:
44
- README.md
55
6+
7+
8+
9+
NOTE: logger must be configured via the .env or command line arguments
610
"""
711

812
import logging

src/otoolbox/addons/ubuntu/__init__.py

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,31 @@
1010
import typer
1111
from typing_extensions import Annotated
1212

13+
import otoolbox
1314
from otoolbox import env
1415
from otoolbox import utils
1516
from otoolbox.constants import RESOURCE_PRIORITY_DEFAULT
1617

1718

1819
LINUX_SCRIPTS = [
19-
"bulk-add-repos.sh",
20-
"bulk-clone-al.sh",
21-
"bulk-commit.sh",
22-
"bulk-init-tests.sh",
23-
"bulk-pre-commit.sh",
24-
"bulk-pull.sh",
25-
"bulk-push-shielded.sh",
26-
"bulk-push.sh",
27-
"bulk-repo-init.sh",
28-
"bulk-sync-shielded.sh",
29-
"ubuntu-install-apps.sh",
30-
"ubuntu-office-conf.sh",
20+
"bulk-common",
21+
"bulk-add-repos",
22+
"bulk-clone-al",
23+
"bulk-commit",
24+
"bulk-init-tests",
25+
"bulk-pre-commit",
26+
"bulk-pull",
27+
"bulk-push-shielded",
28+
"bulk-push",
29+
"bulk-repo-init",
30+
"bulk-sync-shielded",
31+
"ubuntu-install-apps",
32+
"ubuntu-office-conf",
33+
]
34+
35+
PIPX_APPLICATIONS = [
36+
"copier",
37+
"pre-commit",
3138
]
3239

3340

@@ -43,6 +50,16 @@ def install():
4350
env.console.print("Run ./ubuntu-install-apps.sh in terminal.")
4451

4552

53+
54+
@app.command(name="init")
55+
def init():
56+
env.console.print("Update working directory to the current workspace.")
57+
otoolbox.command_run(
58+
steps=["init", "update", "verify"],
59+
tags=["ubuntu"],
60+
ssh_auth=True,
61+
)
62+
4663
###################################################################
4764
# init
4865
###################################################################
@@ -52,19 +69,20 @@ def init():
5269
"""Init the resources for the workspace"""
5370
env.add_resource(
5471
priority=RESOURCE_PRIORITY_DEFAULT,
55-
path=".bin",
56-
title="Workspace configuration directory",
57-
description="All configuration related to current workspace are located in this folder",
72+
path=".venv/bin",
73+
title="Workspace binary tools directory",
74+
description="All binary tools related to the current workspace are located in this folder",
75+
destroy=[],
5876
init=[utils.makedir],
59-
destroy=[utils.delete_dir],
6077
verify=[utils.is_dir, utils.is_readable],
78+
tags=["ubuntu", "folder", ".venv/bin"],
6179
)
6280

6381

6482
for script in LINUX_SCRIPTS:
6583
env.add_resource(
6684
priority=RESOURCE_PRIORITY_DEFAULT,
67-
path=script,
85+
path=f".venv/bin/{script}",
6886
title=f"Ubuntu utility script {script}",
6987
description="Install all required application in ubuntu.",
7088
init=[
@@ -79,32 +97,22 @@ def init():
7997
],
8098
destroy=[utils.delete_file],
8199
verify=[utils.is_file, utils.is_executable],
82-
tags=["bash", "utility", "ubuntu"],
100+
tags=["ubuntu", "tools", script],
83101
)
84102

85-
env.add_resource(
86-
priority=RESOURCE_PRIORITY_DEFAULT,
87-
path="application://copier",
88-
title="Copier tool",
89-
description="Copier",
90-
init=[utils.pipx_install, utils.pipx_ensurepath],
91-
update=[],
92-
destroy=[utils.pipx_remove],
93-
verify=[utils.pipx_is_install, utils.pipx_ensurepath],
94-
tags=["application", "oca", "maintainer"],
95-
)
103+
for app in PIPX_APPLICATIONS:
104+
env.add_resource(
105+
priority=RESOURCE_PRIORITY_DEFAULT,
106+
path=f"application://{app}",
107+
title=f"{app} tool",
108+
description=f"{app} tool installed via pipx",
109+
init=[utils.pipx_install, utils.pipx_ensurepath],
110+
update=[utils.pipx_update, utils.pipx_ensurepath],
111+
destroy=[utils.pipx_remove],
112+
verify=[utils.pipx_is_install, utils.pipx_ensurepath],
113+
tags=["ubuntu", "tools", app],
114+
)
96115

97-
env.add_resource(
98-
priority=RESOURCE_PRIORITY_DEFAULT,
99-
path="application://pre-commit",
100-
title="pre-commit tool",
101-
description="pre-commit",
102-
init=[utils.pipx_install, utils.pipx_ensurepath],
103-
update=[utils.pipx_update, utils.pipx_ensurepath],
104-
destroy=[utils.pipx_remove],
105-
verify=[utils.pipx_is_install, utils.pipx_ensurepath],
106-
tags=["application", "oca", "maintainer"],
107-
)
108116

109117

110118
###################################################################

src/otoolbox/addons/ubuntu/bin/bulk-add-repos.sh renamed to src/otoolbox/addons/ubuntu/bin/bulk-add-repos

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
# #
1313
# Copyright (c) The otoolbox contributors. #
1414
#############################################################################
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
COMMON_SCRIPT="$SCRIPT_DIR/bulk-common"
17+
if [[ ! -f "$COMMON_SCRIPT" ]]; then
18+
echo "Error: required script not found: $COMMON_SCRIPT" >&2
19+
exit 1
20+
fi
21+
# shellcheck source=/dev/null
22+
source "$SCRIPT_DIR/.env"
23+
source "$COMMON_SCRIPT"
24+
bulk_init "$@"
1525

1626

1727
# Supported repositoires

src/otoolbox/addons/ubuntu/bin/bulk-clone-al.sh renamed to src/otoolbox/addons/ubuntu/bin/bulk-clone-al

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
# #
1313
# Copyright (c) The otoolbox contributors. #
1414
#############################################################################
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
COMMON_SCRIPT="$SCRIPT_DIR/bulk-common"
17+
if [[ ! -f "$COMMON_SCRIPT" ]]; then
18+
echo "Error: required script not found: $COMMON_SCRIPT" >&2
19+
exit 1
20+
fi
21+
# shellcheck source=/dev/null
22+
source "$SCRIPT_DIR/.env"
23+
source "$COMMON_SCRIPT"
24+
bulk_init "$@"
25+
26+
1527
# Constants
1628
repos=(
1729
"odoonix/account" \

src/otoolbox/addons/ubuntu/bin/bulk-commit.sh renamed to src/otoolbox/addons/ubuntu/bin/bulk-commit

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
# #
1313
# Copyright (c) The otoolbox contributors. #
1414
#############################################################################
15-
# Constants
16-
WORKDIR="$(pwd)"
17-
PROCESS_DATE=$(date +%Y-%m-%d)
18-
LOG_FILE="$WORKDIR/commit-log-$PROCESS_DATE.log"
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
COMMON_SCRIPT="$SCRIPT_DIR/bulk-common"
17+
if [[ ! -f "$COMMON_SCRIPT" ]]; then
18+
echo "Error: required script not found: $COMMON_SCRIPT" >&2
19+
exit 1
20+
fi
21+
# shellcheck source=/dev/null
22+
source "$SCRIPT_DIR/.env"
23+
source "$COMMON_SCRIPT"
24+
bulk_init "$@"
1925

20-
# copy changes to the moonsunsoft repo
21-
echo "Current directory is: $CURRENT_DIR"
22-
cd "$WORKDIR"
2326

2427
#For each folder in moonsun (it must be part of a shielded project)
2528
for dir in "$WORKDIR/odoonix"/*/; do
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
4+
5+
########################################################################################
6+
# Pre-requisites #
7+
########################################################################################
8+
# maso, 2025: check if the current directory is workspace root. The workspace
9+
# root is the dirctory that contains the .venv/bin/bulk-pull.sh script (current script).
10+
# If not, change the current directory to the workspace root.
11+
#
12+
# The script may be a symbol link, we need to resolve the symbol link to get the actual
13+
# directory of the script.
14+
# We must store current direcotry before changing it to the workspace root, because
15+
# we need to return to the original directory after pulling changes from the
16+
# repositories even there is error.
17+
########################################################################################
18+
19+
20+
function bulk_init_working_dir() {
21+
CURRENT_DIR="$(pwd)"
22+
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
23+
SCRIPT_NAME="$(basename "$(readlink -f "$0")")"
24+
25+
TEMP_DIR="$SCRIPT_DIR/../.."
26+
cd "$TEMP_DIR"
27+
WORKSPACE_ROOT="$(pwd)"
28+
29+
# [] workspace root
30+
echo "Working director: $WORKSPACE_ROOT."
31+
echo "Current directory: $CURRENT_DIR."
32+
cd "$WORKSPACE_ROOT"
33+
}
34+
35+
36+
function bulk_init_temp_dir() {
37+
# Create a temporary directory to store the log file.
38+
WORKDIR="$(pwd)"
39+
TEMP_DIR="${WORKDIR}/.tmp"
40+
if [[ ! -d "$TEMP_DIR" ]]; then
41+
mkdir -p "$TEMP_DIR"
42+
fi
43+
echo "Temporary directory: $TEMP_DIR."
44+
}
45+
46+
function bulk_init_log_file() {
47+
WORKDIR="$(pwd)"
48+
PROCESS_DATE=$(date +%Y-%m-%d)
49+
LOG_FILE="${WORKDIR}/.tmp/${SCRIPT_NAME}-${PROCESS_DATE}.log"
50+
if [[ -f "$LOG_FILE" ]]; then
51+
rm -f "$LOG_FILE"
52+
touch "$LOG_FILE"
53+
fi
54+
echo "Log file: $LOG_FILE"
55+
}
56+
57+
function bulk_init() {
58+
echo "#############################################################################"
59+
echo "Pre-requisites: Checking current directory and changing to workspace root if needed..."
60+
echo
61+
echo
62+
63+
64+
# Inintialize the working directory and log file.
65+
echo "Initializing working dircitories and log file..."
66+
echo
67+
bulk_init_working_dir
68+
bulk_init_temp_dir
69+
bulk_init_log_file
70+
71+
echo
72+
echo
73+
echo "Pre-requisites check completed."
74+
}
75+

src/otoolbox/addons/ubuntu/bin/bulk-init-tests.sh renamed to src/otoolbox/addons/ubuntu/bin/bulk-init-tests

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
# #
1313
# Copyright (c) The otoolbox contributors. #
1414
#############################################################################
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
COMMON_SCRIPT="$SCRIPT_DIR/bulk-common"
17+
if [[ ! -f "$COMMON_SCRIPT" ]]; then
18+
echo "Error: required script not found: $COMMON_SCRIPT" >&2
19+
exit 1
20+
fi
21+
# shellcheck source=/dev/null
22+
source "$SCRIPT_DIR/.env"
23+
source "$COMMON_SCRIPT"
24+
bulk_init "$@"
25+
26+
1527

1628
# Constants
1729
WORKDIR=$(pwd -P) # Use pwd with -P flag for canonicalization

src/otoolbox/addons/ubuntu/bin/bulk-pre-commit.sh renamed to src/otoolbox/addons/ubuntu/bin/bulk-pre-commit

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
# #
1313
# Copyright (c) The otoolbox contributors. #
1414
#############################################################################
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
COMMON_SCRIPT="$SCRIPT_DIR/bulk-common"
17+
if [[ ! -f "$COMMON_SCRIPT" ]]; then
18+
echo "Error: required script not found: $COMMON_SCRIPT" >&2
19+
exit 1
20+
fi
21+
# shellcheck source=/dev/null
22+
source "$SCRIPT_DIR/.env"
23+
source "$COMMON_SCRIPT"
24+
bulk_init "$@"
25+
26+
1527

16-
# Constants
17-
WORKDIR=$(pwd -P) # Use pwd with -P flag for canonicalization
18-
PRECOMMIT_DATE=$(date +"%Y-%m-%d") # Use format string to avoid locale issues
19-
LOG_FILE="${WORKDIR}/precommit-log-${PRECOMPUT_DATE}.log" # Use double quotes and template strings
2028

21-
# load variables
22-
source .env
2329

2430
# ... rest of the code remains the same ...
2531

0 commit comments

Comments
 (0)