mirror of
https://github.com/frappe/bench.git
synced 2025-01-26 08:08:23 +00:00
feat(remove-app): Options for no backup of app & force removal
This commit is contained in:
parent
a3b859bf50
commit
69e14e512f
@ -10,7 +10,7 @@ from typing import List, MutableSequence, TYPE_CHECKING, Union
|
|||||||
|
|
||||||
# imports - module imports
|
# imports - module imports
|
||||||
import bench
|
import bench
|
||||||
from bench.exceptions import ValidationError
|
from bench.exceptions import AppNotInstalledError, InvalidRemoteException
|
||||||
from bench.config.common_site_config import setup_config
|
from bench.config.common_site_config import setup_config
|
||||||
from bench.utils import (
|
from bench.utils import (
|
||||||
paths_in_bench,
|
paths_in_bench,
|
||||||
@ -49,7 +49,7 @@ class Base:
|
|||||||
class Validator:
|
class Validator:
|
||||||
def validate_app_uninstall(self, app):
|
def validate_app_uninstall(self, app):
|
||||||
if app not in self.apps:
|
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)
|
validate_app_installed_on_sites(app, bench_path=self.name)
|
||||||
|
|
||||||
|
|
||||||
@ -119,11 +119,16 @@ class Bench(Base, Validator):
|
|||||||
self.apps.append(app)
|
self.apps.append(app)
|
||||||
self.apps.sync()
|
self.apps.sync()
|
||||||
|
|
||||||
def uninstall(self, app):
|
def uninstall(self, app, no_backup=False, force=False):
|
||||||
from bench.app import App
|
from bench.app import App
|
||||||
|
|
||||||
self.validate_app_uninstall(app)
|
if not force:
|
||||||
self.apps.remove(App(app, bench=self, to_clone=False))
|
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.apps.sync()
|
||||||
# self.build() - removed because it seems unnecessary
|
# self.build() - removed because it seems unnecessary
|
||||||
self.reload()
|
self.reload()
|
||||||
@ -305,9 +310,10 @@ class BenchApps(MutableSequence):
|
|||||||
super().append(app.repo)
|
super().append(app.repo)
|
||||||
self.apps.sort()
|
self.apps.sort()
|
||||||
|
|
||||||
def remove(self, app: "App"):
|
def remove(self, app: "App", no_backup: bool = False):
|
||||||
app.uninstall()
|
app.uninstall()
|
||||||
app.remove()
|
if not no_backup:
|
||||||
|
app.remove()
|
||||||
super().remove(app.repo)
|
super().remove(app.repo)
|
||||||
|
|
||||||
def append(self, app: "App"):
|
def append(self, app: "App"):
|
||||||
|
@ -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"
|
"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")
|
@click.argument("app-name")
|
||||||
def remove_app(app_name):
|
def remove_app(app_name, no_backup=False, force=False):
|
||||||
from bench.bench import Bench
|
from bench.bench import Bench
|
||||||
|
|
||||||
bench = 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")
|
@click.command("exclude-app", help="Exclude app from updating")
|
||||||
|
@ -21,9 +21,15 @@ class BenchNotFoundError(Exception):
|
|||||||
class ValidationError(Exception):
|
class ValidationError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class AppNotInstalledError(ValidationError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CannotUpdateReleaseBench(ValidationError):
|
class CannotUpdateReleaseBench(ValidationError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FeatureDoesNotExistError(CommandFailedError):
|
class FeatureDoesNotExistError(CommandFailedError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import requests
|
|||||||
# imports - module imports
|
# imports - module imports
|
||||||
from bench import PROJECT_NAME, VERSION
|
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)
|
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]
|
app = git_url.rsplit("/", 1)[1].rsplit(".", 1)[0]
|
||||||
|
|
||||||
if app not in Bench(bench_path).apps:
|
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)
|
app_dir = get_repo_dir(app, bench_path=bench_path)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user