From c3efdb01abdddc2371f31802b26890414b9ac9a5 Mon Sep 17 00:00:00 2001 From: Valmik Jangla Date: Sun, 17 Jul 2016 22:57:05 -0700 Subject: [PATCH 1/2] Added command to remove app --- bench/app.py | 28 ++++++++++++++++++++++++++++ bench/commands/__init__.py | 3 ++- bench/commands/make.py | 8 ++++++++ bench/utils.py | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) mode change 100644 => 100755 bench/commands/__init__.py mode change 100644 => 100755 bench/commands/make.py mode change 100644 => 100755 bench/utils.py diff --git a/bench/app.py b/bench/app.py index 0ba81931..1b62a92b 100755 --- a/bench/app.py +++ b/bench/app.py @@ -10,6 +10,8 @@ import json import re import subprocess import bench +import sys +import shutil logging.basicConfig(level="DEBUG") logger = logging.getLogger(__name__) @@ -101,6 +103,32 @@ def install_app(app, bench_path='.', verbose=False): find_links=find_links)) add_to_appstxt(app, bench_path=bench_path) + +def remove_app(app, bench_path='.'): + if not app in get_apps(): + print "No app named {0}".format(app) + sys.exit(1) + + app_path = os.path.join(bench_path, 'apps', app) + site_path = os.path.join(bench_path, 'sites') + pip = os.path.join(bench_path, 'env', 'bin', 'pip') + + for site in os.listdir(site_path): + req_file = os.path.join(site_path, site, 'site_config.json') + if os.path.exists(req_file): + out = subprocess.check_output(["bench", "--site", site, "list-apps"], cwd=bench_path) + if re.search(r'\b' + app + r'\b', out): + print "Cannot remove, app is installed on site: {0}".format(site) + sys.exit(1) + + exec_cmd(["{0} uninstall -y {1}".format(pip, app_path)], cwd=bench_path) + remove_from_appstxt(app, bench_path) + shutil.rmtree(app_path) + run_frappe_cmd("build", cwd=bench_path) + if get_config(bench_path).get('restart_supervisor_on_update'): + restart_supervisor_processes(bench_path=bench_path) + + def pull_all_apps(bench_path='.'): rebase = '--rebase' if get_config(bench_path).get('rebase_on_pull') else '' diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py old mode 100644 new mode 100755 index a1f7f450..09f6af5c --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -21,10 +21,11 @@ def bench_command(bench_path='.'): setup_logging(bench_path=bench_path) -from bench.commands.make import init, get_app, new_app, new_site +from bench.commands.make import init, get_app, new_app, remove_app, new_site bench_command.add_command(init) bench_command.add_command(get_app) bench_command.add_command(new_app) +bench_command.add_command(remove_app) bench_command.add_command(new_site) diff --git a/bench/commands/make.py b/bench/commands/make.py old mode 100644 new mode 100755 index 3efc8da3..efc77d5e --- a/bench/commands/make.py +++ b/bench/commands/make.py @@ -36,6 +36,14 @@ def new_app(app_name): new_app(app_name) +@click.command('remove-app') +@click.argument('app-name') +def remove_app(app_name): + "completely remove new app from bench" + from bench.app import remove_app + remove_app(app_name) + + @click.command('new-site') @click.option('--mariadb-root-password', help="MariaDB root password") @click.option('--admin-password', help="admin password to set for site") diff --git a/bench/utils.py b/bench/utils.py old mode 100644 new mode 100755 index a94fd93c..d6cbc300 --- a/bench/utils.py +++ b/bench/utils.py @@ -77,6 +77,7 @@ def exec_cmd(cmd, cwd='.'): stderr = stdout = subprocess.PIPE else: stderr = stdout = None + print cmd p = subprocess.Popen(cmd, cwd=cwd, shell=True, stdout=stdout, stderr=stderr) if async: From 43e170e02d0567e2c2f2d34d4b9263b8d494a19f Mon Sep 17 00:00:00 2001 From: Valmik Jangla Date: Sun, 17 Jul 2016 23:57:48 -0700 Subject: [PATCH 2/2] Added tests for remove-app --- bench/commands/make.py | 2 +- bench/tests/test_init.py | 19 +++++++++++++++++++ bench/utils.py | 1 - 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bench/commands/make.py b/bench/commands/make.py index efc77d5e..ecfcec0a 100755 --- a/bench/commands/make.py +++ b/bench/commands/make.py @@ -39,7 +39,7 @@ def new_app(app_name): @click.command('remove-app') @click.argument('app-name') def remove_app(app_name): - "completely remove new app from bench" + "completely remove app from bench" from bench.app import remove_app remove_app(app_name) diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 09ed25de..bf9374e1 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -116,6 +116,25 @@ class TestBenchInit(unittest.TestCase): out = subprocess.check_output(["bench", "--site", site_name, "list-apps"], cwd=bench_path) self.assertTrue("erpnext" in out) + + def test_remove_app(self): + site_name = "test-site-4.dev" + self.init_bench('test-bench') + + self.new_site(site_name) + bench_path = os.path.join(self.benches_path, "test-bench") + + # get app + bench.app.get_app("https://github.com/frappe/erpnext", "develop", bench_path=bench_path) + + self.assertTrue(os.path.exists(os.path.join(bench_path, "apps", "erpnext"))) + + # remove it + bench.app.remove_app("erpnext", bench_path=bench_path) + + self.assertFalse(os.path.exists(os.path.join(bench_path, "apps", "erpnext"))) + + def test_switch_to_branch(self): self.init_bench('test-bench') diff --git a/bench/utils.py b/bench/utils.py index d6cbc300..a94fd93c 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -77,7 +77,6 @@ def exec_cmd(cmd, cwd='.'): stderr = stdout = subprocess.PIPE else: stderr = stdout = None - print cmd p = subprocess.Popen(cmd, cwd=cwd, shell=True, stdout=stdout, stderr=stderr) if async: