Skip to content

Commit

Permalink
feat(remove-app): Options for no backup of app & force removal
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed May 19, 2022
1 parent a3b859b commit 69e14e5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
20 changes: 13 additions & 7 deletions bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# imports - module imports
import bench
from bench.exceptions import ValidationError
from bench.exceptions import AppNotInstalledError, InvalidRemoteException
from bench.config.common_site_config import setup_config
from bench.utils import (
paths_in_bench,
Expand Down Expand Up @@ -49,7 +49,7 @@ def run(self, cmd, cwd=None):
class Validator:
def validate_app_uninstall(self, app):
if app not in self.apps:
raise ValidationError(f"No app named {app}")
raise AppNotInstalledError(f"No app named {app}")
validate_app_installed_on_sites(app, bench_path=self.name)


Expand Down Expand Up @@ -119,11 +119,16 @@ def install(self, app, branch=None):
self.apps.append(app)
self.apps.sync()

def uninstall(self, app):
def uninstall(self, app, no_backup=False, force=False):
from bench.app import App

self.validate_app_uninstall(app)
self.apps.remove(App(app, bench=self, to_clone=False))
if not force:
self.validate_app_uninstall(app)
try:
self.apps.remove(App(app, bench=self, to_clone=False), no_backup=no_backup)
except InvalidRemoteException:
if not force:
raise
self.apps.sync()
# self.build() - removed because it seems unnecessary
self.reload()
Expand Down Expand Up @@ -305,9 +310,10 @@ def add(self, app: "App"):
super().append(app.repo)
self.apps.sort()

def remove(self, app: "App"):
def remove(self, app: "App", no_backup: bool = False):
app.uninstall()
app.remove()
if not no_backup:
app.remove()
super().remove(app.repo)

def append(self, app: "App"):
Expand Down
6 changes: 4 additions & 2 deletions bench/commands/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,14 @@ def new_app(app_name, no_git=None):
"Completely remove app from bench and re-build assets if not installed on any site"
),
)
@click.option("--no-backup", is_flag=True, help="Do not backup app before removing")
@click.option("--force", is_flag=True, help="Force remove app")
@click.argument("app-name")
def remove_app(app_name):
def remove_app(app_name, no_backup=False, force=False):
from bench.bench import Bench

bench = Bench(".")
bench.uninstall(app_name)
bench.uninstall(app_name, no_backup=no_backup, force=force)


@click.command("exclude-app", help="Exclude app from updating")
Expand Down
6 changes: 6 additions & 0 deletions bench/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ class BenchNotFoundError(Exception):
class ValidationError(Exception):
pass


class AppNotInstalledError(ValidationError):
pass


class CannotUpdateReleaseBench(ValidationError):
pass


class FeatureDoesNotExistError(CommandFailedError):
pass

Expand Down
4 changes: 2 additions & 2 deletions bench/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# imports - module imports
from bench import PROJECT_NAME, VERSION

from bench.exceptions import CommandFailedError, InvalidRemoteException, ValidationError
from bench.exceptions import CommandFailedError, InvalidRemoteException, AppNotInstalledError


logger = logging.getLogger(PROJECT_NAME)
Expand Down Expand Up @@ -294,7 +294,7 @@ def set_git_remote_url(git_url, bench_path="."):
app = git_url.rsplit("/", 1)[1].rsplit(".", 1)[0]

if app not in Bench(bench_path).apps:
raise ValidationError(f"No app named {app}")
raise AppNotInstalledError(f"No app named {app}")

app_dir = get_repo_dir(app, bench_path=bench_path)

Expand Down

0 comments on commit 69e14e5

Please sign in to comment.