Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ __pycache__
htmlcov

# --- Odev plugins, loaded as submodules
odev/plugins/*
tests/plugins/*
Empty file added __init__.py
Empty file.
2 changes: 1 addition & 1 deletion __manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# or merged change.
# ------------------------------------------------------------------------------

__version__ = "1.2.3"
__version__ = "1.3.0"

# --- Dependencies -------------------------------------------------------------
# List other odev plugins from which this current plugin depends.
Expand Down
Empty file added commands/__init__.py
Empty file.
23 changes: 22 additions & 1 deletion commands/code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from odev.common import args
from odev.common.commands import DatabaseOrRepositoryCommand
from odev.common.version import OdooVersion

from odev.plugins.odev_plugin_editor_base.common.editor import Editor

Expand All @@ -10,6 +12,21 @@ class EditorCommand(DatabaseOrRepositoryCommand):

_name = "code"

_database_allowed_platforms = ["local"]

_exclusive_arguments = [("database", "version")]

version = args.String(
aliases=["-V", "--version"],
description="Odoo version to open a workspace for.",
)

@classmethod
def prepare_command(cls, *args, **kwargs) -> None:
super().prepare_command(*args, **kwargs)
cls.remove_argument("platform")
cls.remove_argument("branch")

def run(self):
editor_subclasses = Editor.__subclasses__()

Expand All @@ -21,7 +38,11 @@ def run(self):
editor_class = Editor.__subclasses__()[0]

try:
editor = editor_class(self._database, self.args.repository)
editor = editor_class(
self._database,
self.args.repository,
OdooVersion(self.args.version) if self.args.version else None,
)
except ValueError as error:
raise self.error(str(error)) from error

Expand Down
Empty file added common/__init__.py
Empty file.
24 changes: 18 additions & 6 deletions common/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from odev.common.connectors import GitConnector
from odev.common.databases import DummyDatabase, LocalDatabase, Repository
from odev.common.logging import logging
from odev.common.version import OdooVersion


logger = logging.getLogger(__name__)
Expand All @@ -20,20 +21,25 @@ class Editor(ABC):
_display_name: ClassVar[str]
"""Display name of the code editor."""

def __init__(self, database: DummyDatabase | LocalDatabase, repository: Optional[str] = None):
def __init__(
self,
database: DummyDatabase | LocalDatabase,
repository: Optional[str] = None,
version: Optional[OdooVersion] = None,
):
"""Initialize the editor with a database or repository.
:param database: The database linked to the project to open in the editor.
:param repository: The repository to open in the editor.
"""
if isinstance(database, LocalDatabase) and repository is not None:
raise ValueError("Cannot provide both database and repository")

self.database = database
"""The database linked to the project to open in the editor."""

self.repository: str = "odoo/odoo"
"""The repository to open in the editor."""

self.version = version
"""The Odoo version to open in the editor."""

if repository:
self.repository = repository
elif database.repository:
Expand All @@ -45,6 +51,11 @@ def __init__(self, database: DummyDatabase | LocalDatabase, repository: Optional
elif isinstance(database, LocalDatabase):
logger.warning(f"No repository associated with local database {database.name!r}")

@property
def display_name(self) -> str:
"""The display name of the editor."""
return self._display_name

@property
def git(self) -> GitConnector:
"""The Git connector for the project."""
Expand All @@ -53,7 +64,7 @@ def git(self) -> GitConnector:
@property
def path(self) -> Path:
"""The path to the project."""
return self.git.path
return self.git.path if isinstance(self.database, LocalDatabase) else Path("~/odev/workspaces/").expanduser()

@property
def command(self) -> str:
Expand All @@ -79,7 +90,8 @@ def configure(self):
def open(self):
"""Open the editor with the project loaded."""
self.configure()
logger.info(f"Opening project {self.repository!r} in {self._display_name}")
project = f"project {self.repository!r}" if not self.version else f"Odoo {self.version}"
logger.info(f"Opening {project} in {self.display_name}")

if not self.git.exists:
logger.warning(f"Local repository {self.path} does not exist, opening the editor may fail")
Expand Down