-
Notifications
You must be signed in to change notification settings - Fork 7
[ADD] Database command to change database parameters without starting it #107
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
Draft
brinkflew
wants to merge
1
commit into
main
Choose a base branch
from
avs-command-db
base: main
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.
Draft
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
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,111 @@ | ||
| from odev.common import args, progress | ||
| from odev.common.commands import GitCommand, LocalDatabaseCommand | ||
| from odev.common.connectors import GitConnector | ||
| from odev.common.logging import logging | ||
| from odev.common.python import PythonEnv | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class DatabaseSetCommand(LocalDatabaseCommand, GitCommand): | ||
| """Edit local databases' parameters.""" | ||
|
|
||
| _name = "database" | ||
| _aliases = ["db"] | ||
|
|
||
| set_repository = args.String( | ||
| aliases=["--set-repo"], | ||
| description="Change the repository linked to the database, in the format <organization>/<repository>.", | ||
| metavar="REPOSITORY", | ||
| ) | ||
| remove_repository = args.Flag( | ||
| aliases=["--remove-repo"], | ||
| description="Remove the repository linked to the database.", | ||
| ) | ||
|
|
||
| set_venv = args.String( | ||
| aliases=["--set-venv"], | ||
| description="Change the virtualenv linked to the database.", | ||
| metavar="VENV", | ||
| ) | ||
| remove_venv = args.Flag( | ||
| aliases=["--remove-venv"], | ||
| description="Remove the virtualenv linked to the database.", | ||
| ) | ||
|
|
||
| set_worktree = args.String( | ||
| aliases=["--set-worktree"], | ||
| description="Change the worktree linked to the database.", | ||
| metavar="WORKTREE", | ||
| ) | ||
| remove_worktree = args.Flag( | ||
| aliases=["--remove-worktree"], | ||
| description="Remove the worktree linked to the database.", | ||
| ) | ||
|
|
||
| whitelist = args.FlagOptional( | ||
| aliases=["--whitelist"], | ||
lse-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| description="Whitelist or unwhitelist the database.", | ||
| ) | ||
|
|
||
| @classmethod | ||
| def prepare_command(cls, *args, **kwargs) -> None: | ||
| super().prepare_command(*args, **kwargs) | ||
| cls.remove_argument("version") | ||
|
|
||
| def run(self): | ||
| self.args.version = None | ||
|
|
||
| with progress.spinner("Setting database parameters"): | ||
| self._set_values() | ||
| self._remove_values() | ||
|
|
||
| def _set_values(self): | ||
| if self.args.set_repository: | ||
| repo = GitConnector(self.args.set_repository) | ||
|
|
||
| if not repo.exists and self.console.confirm("Repository not found locally, clone now?"): | ||
| self.odev.run_command("clone", repo.name) | ||
|
|
||
| self.store.databases.set_value(self._database, "repository", f"{self.args.set_repository!r}") | ||
| self.store.databases.set_value(self._database, "branch", "NULL") | ||
| logger.info(f"Repository set to {self.args.set_repository!r}") | ||
|
|
||
| if self.args.set_venv: | ||
| venv = PythonEnv(self.args.set_venv) | ||
|
|
||
| if venv.exists: | ||
| self.store.databases.set_value(self._database, "virtualenv", f"{self.args.set_venv!r}") | ||
| logger.info(f"Virtualenv set to {self.args.set_venv!r}") | ||
| else: | ||
| logger.error(f"Virtualenv {self.args.set_venv!r} not found, please create it and retry") | ||
|
|
||
| if self.args.set_worktree: | ||
| if self.args.set_worktree in self.grouped_worktrees: | ||
| self.store.databases.set_value(self._database, "worktree", f"{self.args.set_worktree!r}") | ||
| logger.info(f"Worktree set to {self.args.set_worktree!r}") | ||
| else: | ||
| logger.error(f"Worktree {self.args.set_worktree!r} not found, please create it and retry") | ||
|
|
||
| if self.args.whitelist is True: | ||
| self.store.databases.set_value(self._database, "whitelisted", "TRUE") | ||
| logger.info("Database whitelisted") | ||
|
|
||
| def _remove_values(self): | ||
| if self.args.remove_repository: | ||
| self.store.databases.set_value(self._database, "repository", "NULL") | ||
| self.store.databases.set_value(self._database, "branch", "NULL") | ||
| logger.info("Repository removed") | ||
|
|
||
| if self.args.remove_venv: | ||
| self.store.databases.set_value(self._database, "virtualenv", "NULL") | ||
| logger.info("Virtualenv removed") | ||
|
|
||
| if self.args.remove_worktree: | ||
| self.store.databases.set_value(self._database, "worktree", "NULL") | ||
| logger.info("Worktree removed") | ||
|
|
||
| if self.args.whitelist is False: | ||
| self.store.databases.set_value(self._database, "whitelisted", "FALSE") | ||
| logger.info("Database unwhitelisted") | ||
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
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
Oops, something went wrong.
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.