def bench_command(bench_path='.'): """Bench manager for Frappe""" import bench from bench.utils import setup_logging bench.set_frappe_version(bench_path=bench_path) setup_logging(bench_path=bench_path)
def build_assets(bench_path='.'): bench.set_frappe_version(bench_path=bench_path) if bench.FRAPPE_VERSION == 4: exec_cmd("{frappe} --build".format(frappe=get_frappe(bench_path=bench_path)), cwd=os.path.join(bench_path, 'sites')) else: run_frappe_cmd('build', bench_path=bench_path)
def init(path, apps_path=None, no_procfile=False, no_backups=False, no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None, verbose=False, clone_from=None, skip_redis_config_generation=False, ignore_exist = False, python = 'python'): # Let's change when we're ready. - <*****@*****.**> from .app import get_app, install_apps_from_path from .config.common_site_config import make_config from .config import redis from .config.procfile import setup_procfile from bench.patches import set_all_patches_executed import os.path as osp if osp.exists(path): if not ignore_exist: raise ValueError('Bench Instance {path} already exists.'.format(path = path)) else: os.makedirs(path) for dirname in folders_in_bench: try: os.makedirs(os.path.join(path, dirname)) except OSError as e: if e.errno != os.errno.EEXIST: pass setup_logging() setup_env(bench_path=path, python = python) make_config(path) if clone_from: clone_apps_from(bench_path=path, clone_from=clone_from) else: if not frappe_path: frappe_path = '[email protected]:srajelli/frappe.git' get_app(frappe_path, branch=frappe_branch, bench_path=path, build_asset_files=False, verbose=verbose) if apps_path: install_apps_from_path(apps_path, bench_path=path) bench.set_frappe_version(bench_path=path) if bench.FRAPPE_VERSION > 5: update_node_packages(bench_path=path) set_all_patches_executed(bench_path=path) build_assets(bench_path=path) if not skip_redis_config_generation: redis.generate_config(path) if not no_procfile: setup_procfile(path) if not no_backups: setup_backups(bench_path=path) if not no_auto_update: setup_auto_update(bench_path=path)
def init(path, apps_path=None, no_procfile=False, no_backups=False, no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None, verbose=False, clone_from=None): from .app import get_app, install_apps_from_path from .config.common_site_config import make_config from .config import redis from .config.procfile import setup_procfile from bench.patches import set_all_patches_executed if os.path.exists(path): print 'Directory {} already exists!'.format(path) raise Exception("Site directory already exists") # sys.exit(1) os.makedirs(path) for dirname in folders_in_bench: os.mkdir(os.path.join(path, dirname)) setup_logging() setup_env(bench_path=path) make_config(path) if clone_from: clone_apps_from(bench_path=path, clone_from=clone_from) else: if not frappe_path: frappe_path = 'https://github.com/frappe/frappe.git' get_app(frappe_path, branch=frappe_branch, bench_path=path, build_asset_files=False, verbose=verbose) if apps_path: install_apps_from_path(apps_path, bench_path=path) bench.set_frappe_version(bench_path=path) if bench.FRAPPE_VERSION > 5: setup_socketio(bench_path=path) set_all_patches_executed(bench_path=path) build_assets(bench_path=path) redis.generate_config(path) if not no_procfile: setup_procfile(path) if not no_backups: setup_backups(bench_path=path) if not no_auto_update: setup_auto_update(bench_path=path)
def setup_backups(bench_path='.'): from bench.config.common_site_config import get_config logger.log('setting up backups') 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') bench.set_frappe_version(bench_path=bench_path) system_crontab = CronTab(user=user) if bench.FRAPPE_VERSION == 4: backup_command = "cd {sites_dir} && {frappe} --backup all".format( frappe=get_frappe(bench_path=bench_path), ) else: backup_command = "cd {bench_dir} && {bench} --verbose --site all backup".format( bench_dir=bench_dir, bench=sys.argv[0]) job_command = "{backup_command} >> {logfile} 2>&1".format( backup_command=backup_command, logfile=logfile) if job_command not in str(system_crontab): job = system_crontab.new( command=job_command, comment="bench auto backups set for every 6 hours") job.every(6).hours() system_crontab.write()
def init(path, apps_path=None, no_procfile=False, no_backups=False, no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None, verbose=False, clone_from=None, skip_redis_config_generation=False, clone_without_update=False, ignore_exist = False, skip_assets=False, python='python3'): from bench.app import get_app, install_apps_from_path from bench.config import redis from bench.config.common_site_config import make_config from bench.config.procfile import setup_procfile from bench.patches import set_all_patches_executed if os.path.exists(path) and not ignore_exist: log('Path {path} already exists!'.format(path=path)) sys.exit(0) elif not os.path.exists(path): # only create dir if it does not exist os.makedirs(path) for dirname in folders_in_bench: try: os.makedirs(os.path.join(path, dirname)) except OSError as e: if e.errno == errno.EEXIST: pass setup_logging() setup_env(bench_path=path, python=python) make_config(path) if clone_from: clone_apps_from(bench_path=path, clone_from=clone_from, update_app=not clone_without_update) else: if not frappe_path: frappe_path = 'https://github.com/frappe/frappe.git' get_app(frappe_path, branch=frappe_branch, bench_path=path, skip_assets=True, verbose=verbose) if apps_path: install_apps_from_path(apps_path, bench_path=path) bench.set_frappe_version(bench_path=path) if bench.FRAPPE_VERSION > 5: if not skip_assets: update_node_packages(bench_path=path) set_all_patches_executed(bench_path=path) if not skip_assets: build_assets(bench_path=path) if not skip_redis_config_generation: redis.generate_config(path) if not no_procfile: setup_procfile(path) if not no_backups: setup_backups(bench_path=path) if not no_auto_update: setup_auto_update(bench_path=path) copy_patches_txt(path)
def backup_site(site, bench_path='.'): bench.set_frappe_version(bench_path=bench_path) if bench.FRAPPE_VERSION == 4: exec_cmd("{frappe} --backup {site}".format(frappe=get_frappe(bench_path=bench_path), site=site), cwd=os.path.join(bench_path, 'sites')) else: run_frappe_cmd('--site', site, 'backup', bench_path=bench_path)
def init( path, apps_path=None, no_procfile=False, no_backups=False, no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None, verbose=False, clone_from=None, ): from .app import get_app, install_apps_from_path from .config.common_site_config import make_config from .config import redis from .config.procfile import setup_procfile from bench.patches import set_all_patches_executed if os.path.exists(path): print "Directory {} already exists!".format(path) raise Exception("Site directory already exists") # sys.exit(1) os.makedirs(path) for dirname in folders_in_bench: os.mkdir(os.path.join(path, dirname)) setup_logging() setup_env(bench_path=path) make_config(path) if clone_from: clone_apps_from(bench_path=path, clone_from=clone_from) else: if not frappe_path: frappe_path = "https://github.com/frappe/frappe.git" get_app(frappe_path, branch=frappe_branch, bench_path=path, build_asset_files=False, verbose=verbose) if apps_path: install_apps_from_path(apps_path, bench_path=path) bench.set_frappe_version(bench_path=path) if bench.FRAPPE_VERSION > 5: setup_socketio(bench_path=path) set_all_patches_executed(bench_path=path) build_assets(bench_path=path) redis.generate_config(path) if not no_procfile: setup_procfile(path) if not no_backups: setup_backups(bench_path=path) if not no_auto_update: setup_auto_update(bench_path=path)
def patch_sites(bench_path='.'): bench.set_frappe_version(bench_path=bench_path) try: if bench.FRAPPE_VERSION == 4: exec_cmd("{frappe} --latest all".format(frappe=get_frappe(bench_path=bench_path)), cwd=os.path.join(bench_path, 'sites')) else: run_frappe_cmd('--site', 'all', 'migrate', bench_path=bench_path) except subprocess.CalledProcessError: raise PatchError
def backup_site(site, bench_path="."): bench.set_frappe_version(bench_path=bench_path) if bench.FRAPPE_VERSION == 4: exec_cmd( "{frappe} --backup {site}".format(frappe=get_frappe(bench_path=bench_path), site=site), cwd=os.path.join(bench_path, "sites"), ) else: run_frappe_cmd("--site", site, "backup", bench_path=bench_path)
def build_assets(bench_path='.', app=None): bench.set_frappe_version(bench_path=bench_path) if bench.FRAPPE_VERSION == 4: exec_cmd("{frappe} --build".format(frappe=get_frappe(bench_path=bench_path)), cwd=os.path.join(bench_path, 'sites')) else: command = 'bench build' if app: command += ' --app {}'.format(app) exec_cmd(command, cwd=bench_path)
def setup_backups(bench_path='.'): logger.info('setting up backups') bench_dir = get_bench_dir(bench_path=bench_path) bench.set_frappe_version(bench_path=bench_path) if bench.FRAPPE_VERSION == 4: backup_command = "cd {sites_dir} && {frappe} --backup all".format(frappe=get_frappe(bench_path=bench_path),) else: backup_command = "cd {bench_dir} && {bench} --site all backup".format(bench_dir=bench_dir, bench=sys.argv[0]) add_to_crontab('0 */6 * * * {backup_command} >> {logfile} 2>&1'.format(backup_command=backup_command, logfile=os.path.join(get_bench_dir(bench_path=bench_path), 'logs', 'backup.log')))
def new_app(app, bench_path='.'): # For backwards compatibility app = app.lower().replace(" ", "_").replace("-", "_") logger.info('creating new app {}'.format(app)) apps = os.path.abspath(os.path.join(bench_path, 'apps')) bench.set_frappe_version(bench_path=bench_path) if bench.FRAPPE_VERSION == 4: exec_cmd("{frappe} --make_app {apps} {app}".format( frappe=get_frappe(bench_path=bench_path), apps=apps, app=app)) else: run_frappe_cmd('make-app', apps, app, bench_path=bench_path) install_app(app, bench_path=bench_path)
def patch_sites(bench_path="."): bench.set_frappe_version(bench_path=bench_path) try: if bench.FRAPPE_VERSION == 4: exec_cmd( "{frappe} --latest all".format(frappe=get_frappe(bench_path=bench_path)), cwd=os.path.join(bench_path, "sites"), ) else: run_frappe_cmd("--site", "all", "migrate", bench_path=bench_path) except subprocess.CalledProcessError: raise PatchError
def new_app(app, bench_path='.'): # For backwards compatibility app = app.lower().replace(" ", "_").replace("-", "_") logger.info('creating new app {}'.format(app)) apps = os.path.abspath(os.path.join(bench_path, 'apps')) bench.set_frappe_version(bench_path=bench_path) if bench.FRAPPE_VERSION == 4: exec_cmd("{frappe} --make_app {apps} {app}".format(frappe=get_frappe(bench_path=bench_path), apps=apps, app=app)) else: run_frappe_cmd('make-app', apps, app, bench_path=bench_path) install_app(app, bench_path=bench_path)
make_config(path) if clone_from: clone_apps_from(bench_path=path, clone_from=clone_from) else: if not frappe_path: frappe_path = 'https://github.com/frappe/frappe.git' get_app(frappe_path, branch=frappe_branch, bench_path=path, build_asset_files=False, verbose=verbose) if apps_path: install_apps_from_path(apps_path, bench_path=path) bench.set_frappe_version(bench_path=path) if bench.FRAPPE_VERSION > 5: update_npm_packages(bench_path=path) set_all_patches_executed(bench_path=path) build_assets(bench_path=path) if not skip_redis_config_generation: redis.generate_config(path) if not no_procfile: setup_procfile(path) if not no_backups: setup_backups(bench_path=path) if not no_auto_update: setup_auto_update(bench_path=path)
def init(path, apps_path=None, no_procfile=False, no_backups=False, no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None, verbose=False, clone_from=None, skip_redis_config_generation=False, clone_without_update=False, ignore_exist=False, python='python' ): # Let's change when we're ready. - <*****@*****.**> from .app import get_app, install_apps_from_path from .config.common_site_config import make_config from .config import redis from .config.procfile import setup_procfile from bench.patches import set_all_patches_executed import os.path as osp if osp.exists(path): if not ignore_exist: raise ValueError( 'Bench Instance {path} already exists.'.format(path=path)) else: os.makedirs(path) for dirname in folders_in_bench: try: os.makedirs(os.path.join(path, dirname)) except OSError as e: if e.errno == os.errno.EEXIST: pass setup_logging() setup_env(bench_path=path, python=python) make_config(path) if clone_from: clone_apps_from(bench_path=path, clone_from=clone_from, update_app=not clone_without_update) else: if not frappe_path: frappe_path = 'https://github.com/frappe/frappe.git' get_app(frappe_path, branch=frappe_branch, bench_path=path, build_asset_files=False, verbose=verbose) if apps_path: install_apps_from_path(apps_path, bench_path=path) bench.set_frappe_version(bench_path=path) if bench.FRAPPE_VERSION > 5: update_node_packages(bench_path=path) set_all_patches_executed(bench_path=path) build_assets(bench_path=path) if not skip_redis_config_generation: redis.generate_config(path) if not no_procfile: setup_procfile(path) if not no_backups: setup_backups(bench_path=path) if not no_auto_update: setup_auto_update(bench_path=path) copy_patches_txt(path)
if clone_from: clone_apps_from(bench_path=path, clone_from=clone_from) else: if not frappe_path: frappe_path = 'https://github.com/jvfiel/frappe-v9.git' get_app(frappe_path, branch=frappe_branch, bench_path=path, build_asset_files=False, verbose=verbose) if apps_path: install_apps_from_path(apps_path, bench_path=path) bench.set_frappe_version(bench_path=path) if bench.FRAPPE_VERSION > 5: update_npm_packages(bench_path=path) set_all_patches_executed(bench_path=path) build_assets(bench_path=path) if not skip_redis_config_generation: redis.generate_config(path) if not no_procfile: setup_procfile(path) if not no_backups: setup_backups(bench_path=path) if not no_auto_update: setup_auto_update(bench_path=path)
def bench_command(bench_path='.'): import bench bench.set_frappe_version(bench_path=bench_path)