2
0
mirror of https://github.com/frappe/bench.git synced 2024-09-28 23:09:03 +00:00

feat(remove-app): Options for no backup of app & force removal

This commit is contained in:
gavin 2022-05-19 13:00:09 +05:30
parent a3b859bf50
commit 69e14e512f
4 changed files with 25 additions and 11 deletions

View File

@ -10,7 +10,7 @@ from typing import List, MutableSequence, TYPE_CHECKING, Union
# 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,
@ -49,7 +49,7 @@ class Base:
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)
@ -119,11 +119,16 @@ class Bench(Base, Validator):
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()
@ -305,9 +310,10 @@ class BenchApps(MutableSequence):
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"):

View File

@ -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")

View File

@ -21,9 +21,15 @@ class BenchNotFoundError(Exception):
class ValidationError(Exception):
pass
class AppNotInstalledError(ValidationError):
pass
class CannotUpdateReleaseBench(ValidationError):
pass
class FeatureDoesNotExistError(CommandFailedError):
pass

View File

@ -17,7 +17,7 @@ import requests
# 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)
@ -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)