Skip to content

Commit

Permalink
[UP] to support addons
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafabarmshory committed Feb 1, 2025
1 parent 626d711 commit d5e38d0
Show file tree
Hide file tree
Showing 27 changed files with 502 additions and 324 deletions.
1 change: 0 additions & 1 deletion odoo/odoo
Submodule odoo deleted from a72ccd
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ python_requires = >=3.8
install_requires =
importlib-metadata; python_version<"3.8"
rich>=13.9.4
typer
chevron
setuptools

Expand Down
185 changes: 110 additions & 75 deletions src/otoolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
"""Load general CLI and tools related to odoo"""
import sys
import argparse
import importlib
import typer
import chevron


from otoolbox import args
from otoolbox import workspace
from otoolbox import developer
from otoolbox import maintainer
from otoolbox import env
from otoolbox import utils

from otoolbox.constants import (

ERROR_CODE_PRE_VERIFICATION,
ERROR_CODE_POST_VERIFICATION

)


if sys.version_info[:2] >= (3, 8):
Expand All @@ -24,87 +35,111 @@
del version, PackageNotFoundError


def init_cli():
"""Initialize the command-line interface for the Odoo Toolbox."""
arg_parser = argparse.ArgumentParser(
prog='odoo-util',
description="""
Odoonix Toolbox is a comprehensive suite of tools designed to streamline
the workflows of developers and maintainers working with Odoo. It
simplifies tasks such as tracking changes in addons, cloning
repositories, managing databases, and configuring development
environments. With its user-friendly interface and automation
features, Odoonix Toolbox enables teams to maintain consistency,
reduce manual effort, and speed up development cycles. By integrating
essential functionalities into one cohesive package, it empowers
developers to focus on creating and maintaining high-quality Odoo
solutions efficiently.
""",
epilog='Developer toolbox'
)

arg_parser.add_argument(
"--path",
help="""The workspace directory, default is current directory""",
action="store",
dest="path",
required=False,
default=".")

arg_parser.add_argument(
"--verbose",
help="""The workspace directory, default is current directory""",
action="count",
dest="verbose",
required=False,
default=0)

arg_parser.add_argument(
"--silent",
help="""Do not print extra information""",
action="count",
dest="silent",
required=False,
default=0)

return arg_parser, arg_parser.add_subparsers()


def load_resources(*args):
def call_init(package_name):
# Import the package dynamically
package = importlib.import_module(package_name)



# def init_cli():
# """Initialize the command-line interface for the Odoo Toolbox."""
# arg_parser = argparse.ArgumentParser(
# prog='odoo-util',
# description="""
# Odoonix Toolbox is a comprehensive suite of tools designed to streamline
# the workflows of developers and maintainers working with Odoo. It
# simplifies tasks such as tracking changes in addons, cloning
# repositories, managing databases, and configuring development
# environments. With its user-friendly interface and automation
# features, Odoonix Toolbox enables teams to maintain consistency,
# reduce manual effort, and speed up development cycles. By integrating
# essential functionalities into one cohesive package, it empowers
# developers to focus on creating and maintaining high-quality Odoo
# solutions efficiently.
# """,
# epilog='Developer toolbox'
# )

# arg_parser.add_argument(
# "--path",
# help="""The workspace directory, default is current directory""",
# action="store",
# dest="path",
# required=False,
# default=".")

# arg_parser.add_argument(
# "--verbose",
# help="""The workspace directory, default is current directory""",
# action="count",
# dest="verbose",
# required=False,
# default=0)

# arg_parser.add_argument(
# "--silent",
# help="""Do not print extra information""",
# action="count",
# dest="silent",
# required=False,
# default=0)

# return arg_parser, arg_parser.add_subparsers()


def _load_resources(*args):
# Example usage
for path in args:
# Import the package dynamically
package = importlib.import_module(path)
# Check if the package has an __init__ method and call it if it exists
if hasattr(package, 'init'):
package.init()

# Example usage
for path in args:
call_init(path)


if __name__ == '__main__':
# Init resources
load_resources(
'otoolbox.help',
'otoolbox.workspace',
'otoolbox.ubuntu',
'otoolbox.vscode',
'otoolbox.repositories'
_load_resources(
'otoolbox.addons.help',
'otoolbox.addons.workspace',
'otoolbox.addons.ubuntu',
'otoolbox.addons.vscode',
'otoolbox.addons.repositories'
)

# Init arguments
parser, parent_parser = init_cli()
args.workspace.init_cli(parent_parser)
args.developer.init_cli(parent_parser)
args.maintainer.init_cli(parent_parser)

args = parser.parse_args()
env.context.update(args.__dict__)
if not env.context.get('silent', 0):
print(chevron.render(
template=env.resource_string("data/banner.txt"),
data=env.context
))
args.func()

def callback_common_arguments(
odoo:str='18.0',
path:str='.',
silent:bool=False,
pre_check:bool=False,
post_check:bool=False,
continue_on_exception:bool=True
):
env.context.update({
'odoo_version': odoo,
'path': path,
'silent': silent,
'pre_check':pre_check,
'post_check': post_check,
'continue_on_exception': continue_on_exception
})
if not silent:
print(chevron.render(
template=env.resource_string("data/banner.txt"),
data=env.context
))
if pre_check:
utils.verify_all_resource()

def result_callback(*args, **kargs):
if env.context.get('post_check', False):
utils.verify_all_resource()

# Launch the CLI application
app = typer.Typer(
callback=callback_common_arguments,
result_callback=result_callback
)
app.add_typer(workspace.app, name="workspace")
app.add_typer(developer.app, name="dev")
app.add_typer(maintainer.app, name="admin")
app()
Empty file added src/otoolbox/addons/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@





###################################################################
# init
###################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

from otoolbox import env
from otoolbox import utils
from otoolbox import addons
from otoolbox.constants import (
RESOURCE_PRIORITY_ROOT
)

from otoolbox.repositories import git
from otoolbox.addons.repositories import git


REPOSITORIES_PATH = ".otoolbox/repositoires.json"
Expand All @@ -28,21 +32,42 @@ def _load_repositories():
data = f.read()

if not data:
with env.resource_string(reposiotires_path, 'w') as f:
data = f.read()
data = env.resource_string(
RESOURCE_REPOSITORIES_PATH,
packag_name=__name__
)
repo_list = json.loads(data)
workspaces = []
for item in repo_list:
env.add_resource(
path="{}/{}".format(item["workspace"], item["name"]),
parent=item["workspace"],
title="Git repository: {}/{}".format(item["workspace"], item["name"]),
description="""
Automaticaly added resources from git.
""",
description="""Automaticaly added resources from git.""",
constructors=[
git.git_clone
],
updates=[
git.git_pull
],
destructors=[],
validators=[],
)
if item["workspace"] not in workspaces:
workspaces.append(item["workspace"])

for workspace_path in workspaces:
env.add_resource(
priority=RESOURCE_PRIORITY_ROOT,
path=workspace_path,
title="Git workspace: {}".format(workspace_path),
description="""Automaticaly added resources from git.""",
constructors=[
utils.makedir
],
updates=[],
destructors=[],
validators=[]
validators=[],
)


Expand All @@ -51,12 +76,14 @@ def init():
"""
(env
.add_resource(
priority=100,
priority=RESOURCE_PRIORITY_ROOT,
path=REPOSITORIES_PATH,
title="List of managed repositories",
description="Adding, removing, and updating repositories in the workspace is done through this file",
constructors=[
utils.constructor_copy_resource(RESOURCE_REPOSITORIES_PATH)
utils.constructor_copy_resource(
RESOURCE_REPOSITORIES_PATH,
packag_name=__name__)
],
destructors=[
utils.delete_file
Expand All @@ -67,3 +94,4 @@ def init():
]
)
)
_load_repositories()
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
from . import linux
from . import admin


def update(**kargs):
# 1- load all repositories
admin.update_repositories(**kargs)

# TODO: check if need to update settings


def init(
repo=False,
vscode=False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def git_clone(context):
"""Clone the git repository from github
"""
branch_name = env.context.get("odoo_version", "18.0")
cwd = os.path.dirname(context.path)
cwd = env.get_workspace_path(context.parent)
depth = env.context.get("depth", "1")

result = utils.call_process_safe([
Expand All @@ -21,4 +21,19 @@ def git_clone(context):
], cwd=cwd)

if result != 0:
raise Exception("Fail to update the repository")
raise AssertionError("Fail to update the repository")



def git_pull(context):
"""Pull the git repository from github
"""
cwd = os.path.dirname(context.path)
result = utils.call_process_safe([
'git',
'pull',
f"[email protected]:{context.path}.git"
], cwd=cwd)

if result != 0:
raise AssertionError("Fail to update the repository")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions src/otoolbox/args/__init__.py

This file was deleted.

32 changes: 0 additions & 32 deletions src/otoolbox/args/common.py

This file was deleted.

Loading

0 comments on commit d5e38d0

Please sign in to comment.