mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 17:24:41 +00:00
feat: bench drop {bench_path}
* Drops bench if no sites' folders found * Tries to drop crontab entry made for backups
This commit is contained in:
parent
ce00798b5d
commit
906ad5a099
20
bench/app.py
20
bench/app.py
@ -188,6 +188,26 @@ def remove_from_excluded_apps_txt(app, bench_path='.'):
|
||||
apps.remove(app)
|
||||
return write_excluded_apps_txt(apps, bench_path=bench_path)
|
||||
|
||||
def drop_bench(bench_path):
|
||||
if not os.path.exists(bench_path):
|
||||
print(f"Bench {bench_path} does not exist")
|
||||
return
|
||||
|
||||
import shutil
|
||||
from bench.utils import remove_backups_crontab
|
||||
|
||||
sites_exist = [
|
||||
x for x in os.listdir(os.path.join(bench_path, 'sites')) if x not in ('assets', 'apps.txt', 'common_site_config.json')
|
||||
]
|
||||
if sites_exist:
|
||||
raise Exception("Cannot remove non-empty bench directory")
|
||||
remove_backups_crontab(bench_path)
|
||||
shutil.rmtree(bench_path)
|
||||
print('Bench dropped')
|
||||
|
||||
def get_bench_name(git_url, bench_path):
|
||||
return "temp-bench"
|
||||
|
||||
def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=False, restart_bench=True, overwrite=False):
|
||||
import requests
|
||||
import shutil
|
||||
|
@ -65,7 +65,7 @@ def cli():
|
||||
not is_bench_directory()
|
||||
and not cmd_requires_root()
|
||||
and len(sys.argv) > 1
|
||||
and sys.argv[1] not in ("init", "find", "src")
|
||||
and sys.argv[1] not in ("init", "find", "src", "drop", "get", "get-app")
|
||||
):
|
||||
log("Command not being executed in bench directory", level=3)
|
||||
|
||||
@ -100,6 +100,7 @@ def cli():
|
||||
if return_code:
|
||||
logger.warning(f"{command} executed with exit code {return_code}")
|
||||
if isinstance(e, Exception):
|
||||
click.secho(f"ERROR: {e}", fg="red")
|
||||
raise e
|
||||
finally:
|
||||
try:
|
||||
@ -209,6 +210,8 @@ def change_working_directory():
|
||||
"""Allows bench commands to be run from anywhere inside a bench directory"""
|
||||
cur_dir = os.path.abspath(".")
|
||||
bench_path = find_parent_bench(cur_dir)
|
||||
bench.current_path = os.getcwd()
|
||||
bench.updated_path = bench_path
|
||||
|
||||
if bench_path:
|
||||
os.chdir(bench_path)
|
||||
|
@ -17,8 +17,9 @@ def bench_command(bench_path='.'):
|
||||
bench.set_frappe_version(bench_path=bench_path)
|
||||
|
||||
|
||||
from bench.commands.make import init, get_app, new_app, remove_app, exclude_app_for_update, include_app_for_update, pip
|
||||
from bench.commands.make import init, drop, get_app, new_app, remove_app, exclude_app_for_update, include_app_for_update, pip
|
||||
bench_command.add_command(init)
|
||||
bench_command.add_command(drop)
|
||||
bench_command.add_command(get_app)
|
||||
bench_command.add_command(new_app)
|
||||
bench_command.add_command(remove_app)
|
||||
|
@ -50,6 +50,13 @@ def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups, c
|
||||
shutil.rmtree(path)
|
||||
|
||||
|
||||
@click.command('drop')
|
||||
@click.argument('path')
|
||||
def drop(path):
|
||||
from bench.app import drop_bench
|
||||
drop_bench(path)
|
||||
|
||||
|
||||
@click.command('get-app', help='Clone an app from the internet or filesystem and set it up in your bench')
|
||||
@click.argument('name', nargs=-1) # Dummy argument for backward compatibility
|
||||
@click.argument('git-url')
|
||||
|
@ -415,6 +415,21 @@ def setup_backups(bench_path='.'):
|
||||
system_crontab.write()
|
||||
|
||||
|
||||
def remove_backups_crontab(bench_path='.'):
|
||||
from crontab import CronTab, CronItem
|
||||
from bench.config.common_site_config import get_config
|
||||
logger.log('removing backup cronjob')
|
||||
|
||||
bench_dir = os.path.abspath(bench_path)
|
||||
user = get_config(bench_path=bench_dir).get('frappe_user')
|
||||
logfile = os.path.join(bench_dir, 'logs', 'backup.log')
|
||||
system_crontab = CronTab(user=user)
|
||||
backup_command = f"cd {bench_dir} && {sys.argv[0]} --verbose --site all backup"
|
||||
job_command = f"{backup_command} >> {logfile} 2>&1"
|
||||
|
||||
system_crontab.remove_all(command=job_command)
|
||||
|
||||
|
||||
def setup_sudoers(user):
|
||||
if not os.path.exists('/etc/sudoers.d'):
|
||||
os.makedirs('/etc/sudoers.d')
|
||||
|
Loading…
Reference in New Issue
Block a user