mirror of
https://github.com/frappe/bench.git
synced 2024-11-11 15:51:03 +00:00
cleanup
This commit is contained in:
parent
d82a67be9e
commit
e426c00e3a
45
bench/cli.py
45
bench/cli.py
@ -20,7 +20,6 @@ from .app import new_app as _new_app
|
|||||||
from .app import pull_all_apps, get_apps, get_current_frappe_version, is_version_upgrade, switch_to_v4, switch_to_v5, switch_to_master, switch_to_develop
|
from .app import pull_all_apps, get_apps, get_current_frappe_version, is_version_upgrade, switch_to_v4, switch_to_v5, switch_to_master, switch_to_develop
|
||||||
from .config.nginx import make_nginx_conf
|
from .config.nginx import make_nginx_conf
|
||||||
from .production_setup import setup_production as _setup_production
|
from .production_setup import setup_production as _setup_production
|
||||||
from .migrate_to_v5 import migrate_to_v5
|
|
||||||
from .config.common_site_config import get_config, make_config, update_config
|
from .config.common_site_config import get_config, make_config, update_config
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -304,15 +303,6 @@ def start(no_dev=False):
|
|||||||
"Start Frappe development processes"
|
"Start Frappe development processes"
|
||||||
_start(no_dev=no_dev)
|
_start(no_dev=no_dev)
|
||||||
|
|
||||||
@click.command('migrate-3to4')
|
|
||||||
@click.argument('path')
|
|
||||||
def migrate_3to4(path):
|
|
||||||
"Migrate from ERPNext v3.x"
|
|
||||||
exec_cmd("{python} {migrate_3to4} {site}".format(
|
|
||||||
python=os.path.join('env', 'bin', 'python'),
|
|
||||||
migrate_3to4=os.path.join(os.path.dirname(__file__), 'migrate3to4.py'),
|
|
||||||
site=path))
|
|
||||||
|
|
||||||
@click.command('switch-to-master')
|
@click.command('switch-to-master')
|
||||||
@click.option('--upgrade',is_flag=True)
|
@click.option('--upgrade',is_flag=True)
|
||||||
def _switch_to_master(upgrade=False):
|
def _switch_to_master(upgrade=False):
|
||||||
@ -459,10 +449,6 @@ def setup_backups():
|
|||||||
"Add cronjob for bench backups"
|
"Add cronjob for bench backups"
|
||||||
_setup_backups()
|
_setup_backups()
|
||||||
|
|
||||||
@click.command('dnsmasq')
|
|
||||||
def setup_dnsmasq():
|
|
||||||
pass
|
|
||||||
|
|
||||||
@click.command('env')
|
@click.command('env')
|
||||||
def setup_env():
|
def setup_env():
|
||||||
"Setup virtualenv for bench"
|
"Setup virtualenv for bench"
|
||||||
@ -489,7 +475,6 @@ setup.add_command(setup_sudoers)
|
|||||||
setup.add_command(setup_supervisor)
|
setup.add_command(setup_supervisor)
|
||||||
setup.add_command(setup_redis)
|
setup.add_command(setup_redis)
|
||||||
setup.add_command(setup_auto_update)
|
setup.add_command(setup_auto_update)
|
||||||
setup.add_command(setup_dnsmasq)
|
|
||||||
setup.add_command(setup_backups)
|
setup.add_command(setup_backups)
|
||||||
setup.add_command(setup_env)
|
setup.add_command(setup_env)
|
||||||
setup.add_command(setup_procfile)
|
setup.add_command(setup_procfile)
|
||||||
@ -559,34 +544,6 @@ config.add_command(config_dns_multitenant)
|
|||||||
config.add_command(config_serve_default_site)
|
config.add_command(config_serve_default_site)
|
||||||
config.add_command(config_http_timeout)
|
config.add_command(config_http_timeout)
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
|
||||||
def patch():
|
|
||||||
pass
|
|
||||||
|
|
||||||
@click.command('fix-prod-perms')
|
|
||||||
def _fix_prod_perms():
|
|
||||||
"Fix permissions if supervisor processes were run as root"
|
|
||||||
if os.path.exists("config/supervisor.conf"):
|
|
||||||
bench_name = get_bench_name(bench_path=".")
|
|
||||||
exec_cmd("supervisorctl stop {bench_name}-processes:".format(bench_name=bench_name))
|
|
||||||
|
|
||||||
fix_prod_setup_perms()
|
|
||||||
|
|
||||||
if os.path.exists("config/supervisor.conf"):
|
|
||||||
exec_cmd("{bench} setup supervisor".format(bench=sys.argv[0]))
|
|
||||||
exec_cmd("supervisorctl reload")
|
|
||||||
|
|
||||||
|
|
||||||
@click.command('fix-file-perms')
|
|
||||||
def _fix_file_perms():
|
|
||||||
"Fix file permissions"
|
|
||||||
fix_file_perms()
|
|
||||||
|
|
||||||
patch.add_command(_fix_file_perms)
|
|
||||||
patch.add_command(_fix_prod_perms)
|
|
||||||
|
|
||||||
|
|
||||||
@click.command('download-translations')
|
@click.command('download-translations')
|
||||||
def _download_translations():
|
def _download_translations():
|
||||||
"Download latest translations"
|
"Download latest translations"
|
||||||
@ -608,7 +565,6 @@ bench.add_command(_set_ssl_certificate)
|
|||||||
bench.add_command(_set_ssl_certificate_key)
|
bench.add_command(_set_ssl_certificate_key)
|
||||||
bench.add_command(_set_mariadb_host)
|
bench.add_command(_set_mariadb_host)
|
||||||
bench.add_command(set_default_site)
|
bench.add_command(set_default_site)
|
||||||
bench.add_command(migrate_3to4)
|
|
||||||
bench.add_command(_switch_to_master)
|
bench.add_command(_switch_to_master)
|
||||||
bench.add_command(_switch_to_develop)
|
bench.add_command(_switch_to_develop)
|
||||||
bench.add_command(_switch_to_v4)
|
bench.add_command(_switch_to_v4)
|
||||||
@ -617,7 +573,6 @@ bench.add_command(shell)
|
|||||||
bench.add_command(_backup_all_sites)
|
bench.add_command(_backup_all_sites)
|
||||||
bench.add_command(_backup_site)
|
bench.add_command(_backup_site)
|
||||||
bench.add_command(_release)
|
bench.add_command(_release)
|
||||||
bench.add_command(patch)
|
|
||||||
bench.add_command(set_url_root)
|
bench.add_command(set_url_root)
|
||||||
bench.add_command(retry_upgrade)
|
bench.add_command(retry_upgrade)
|
||||||
bench.add_command(_download_translations)
|
bench.add_command(_download_translations)
|
||||||
|
@ -15,6 +15,7 @@ default_config = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def make_config(bench_path):
|
def make_config(bench_path):
|
||||||
|
make_pid_folder(bench_path)
|
||||||
bench_config = get_config(bench_path)
|
bench_config = get_config(bench_path)
|
||||||
bench_config.update(default_config)
|
bench_config.update(default_config)
|
||||||
bench_config.update(get_gunicorn_workers())
|
bench_config.update(get_gunicorn_workers())
|
||||||
@ -100,4 +101,8 @@ def make_ports(bench_path):
|
|||||||
ports[key] = value
|
ports[key] = value
|
||||||
|
|
||||||
return ports
|
return ports
|
||||||
|
|
||||||
|
def make_pid_folder(bench_path):
|
||||||
|
pids_path = os.path.join(bench_path, 'config', 'pids')
|
||||||
|
if not os.path.exists(pids_path):
|
||||||
|
os.makedirs(pids_path)
|
@ -1,106 +0,0 @@
|
|||||||
from frappe.installer import add_to_installed_apps
|
|
||||||
from frappe.cli import latest, backup
|
|
||||||
from frappe.modules.patch_handler import executed
|
|
||||||
from frappe.installer import make_site_dirs
|
|
||||||
import frappe
|
|
||||||
import argparse
|
|
||||||
import os
|
|
||||||
import imp
|
|
||||||
import json
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
sites_path = os.environ.get('SITES_PATH', 'sites')
|
|
||||||
last_3_patch = 'patches.1401.fix_pos_outstanding'
|
|
||||||
|
|
||||||
|
|
||||||
def get_frappe(bench='.'):
|
|
||||||
frappe = os.path.abspath(os.path.join(bench, 'env', 'bin', 'frappe'))
|
|
||||||
if not os.path.exists(frappe):
|
|
||||||
print 'frappe app is not installed. Run the following command to install frappe'
|
|
||||||
print 'bench get-app frappe https://github.com/frappe/frappe.git'
|
|
||||||
return frappe
|
|
||||||
|
|
||||||
def get_sites(bench='.'):
|
|
||||||
sites_dir = os.path.join(bench, "sites")
|
|
||||||
sites = [site for site in os.listdir(sites_dir)
|
|
||||||
if os.path.isdir(os.path.join(sites_dir, site)) and site not in ('assets',)]
|
|
||||||
return sites
|
|
||||||
|
|
||||||
def exec_cmd(cmd, cwd='.'):
|
|
||||||
try:
|
|
||||||
subprocess.check_call(cmd, cwd=cwd, shell=True)
|
|
||||||
except subprocess.CalledProcessError, e:
|
|
||||||
print "Error:", e.output
|
|
||||||
raise
|
|
||||||
|
|
||||||
def main(path):
|
|
||||||
site = copy_site(path)
|
|
||||||
migrate(site)
|
|
||||||
|
|
||||||
def copy_site(path):
|
|
||||||
if not os.path.exists(path):
|
|
||||||
raise Exception("Source site does not exist")
|
|
||||||
site = os.path.basename(path)
|
|
||||||
site_path = os.path.join(sites_path, site)
|
|
||||||
confpy_path = os.path.join(path, 'conf.py')
|
|
||||||
confjson_path = os.path.join(path, 'site_config.json')
|
|
||||||
if os.path.exists(site_path):
|
|
||||||
raise Exception("Site already exists")
|
|
||||||
|
|
||||||
os.mkdir(site_path)
|
|
||||||
print os.path.join(path, 'public')
|
|
||||||
if os.path.exists(os.path.join(path, 'public')):
|
|
||||||
exec_cmd("cp -r {src} {dest}".format(
|
|
||||||
src=os.path.join(path, 'public'),
|
|
||||||
dest=os.path.join(site_path, 'public')))
|
|
||||||
|
|
||||||
if os.path.exists(confpy_path):
|
|
||||||
with open(os.path.join(site_path, 'site_config.json'), 'w') as f:
|
|
||||||
f.write(module_to_json(confpy_path, indent=1))
|
|
||||||
if os.path.exists(confjson_path):
|
|
||||||
shutil.copy(confjson_path, os.path.join(site_path, 'site_config.json'))
|
|
||||||
if len(get_sites()) == 1:
|
|
||||||
exec_cmd("{frappe} --use {site}".format(frappe=get_frappe(), site=site), cwd='sites')
|
|
||||||
return site
|
|
||||||
|
|
||||||
def validate(site):
|
|
||||||
frappe.init(site=site, sites_path=sites_path)
|
|
||||||
make_site_dirs()
|
|
||||||
backup()
|
|
||||||
frappe.init(site=site, sites_path=sites_path)
|
|
||||||
frappe.connect()
|
|
||||||
if not executed(last_3_patch):
|
|
||||||
raise Exception, "site not ready to migrate to version 4"
|
|
||||||
frappe.destroy()
|
|
||||||
|
|
||||||
|
|
||||||
def migrate(site):
|
|
||||||
validate(site)
|
|
||||||
os.chdir(sites_path)
|
|
||||||
frappe.init(site=site)
|
|
||||||
frappe.connect()
|
|
||||||
add_to_installed_apps('frappe', rebuild_website=False)
|
|
||||||
add_to_installed_apps('erpnext', rebuild_website=False)
|
|
||||||
add_to_installed_apps('shopping_cart', rebuild_website=False)
|
|
||||||
latest()
|
|
||||||
|
|
||||||
def module_to_json(module_path, indent=None, keys=None):
|
|
||||||
module = imp.load_source('tempmod', module_path)
|
|
||||||
json_keys = [x for x in dir(module) if not x.startswith('_')]
|
|
||||||
|
|
||||||
if keys:
|
|
||||||
json_keys = [x for x in json_keys if x in keys]
|
|
||||||
if 'unicode_literals' in json_keys:
|
|
||||||
json_keys.remove('unicode_literals')
|
|
||||||
if 'backup_path' in json_keys:
|
|
||||||
json_keys.remove('backup_path')
|
|
||||||
|
|
||||||
module = {x:getattr(module, x) for x in json_keys}
|
|
||||||
return json.dumps(module, indent=indent)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('site')
|
|
||||||
args = parser.parse_args()
|
|
||||||
main(args.site)
|
|
@ -1,47 +0,0 @@
|
|||||||
from .utils import exec_cmd, get_frappe, run_frappe_cmd
|
|
||||||
from .release import get_current_version
|
|
||||||
from .app import remove_from_appstxt
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import sys
|
|
||||||
|
|
||||||
repos = ('frappe', 'erpnext')
|
|
||||||
|
|
||||||
def migrate_to_v5(bench='.'):
|
|
||||||
validate_v4(bench=bench)
|
|
||||||
for repo in repos:
|
|
||||||
checkout_v5(repo, bench=bench)
|
|
||||||
remove_shopping_cart(bench=bench)
|
|
||||||
exec_cmd("{bench} update".format(bench=sys.argv[0]))
|
|
||||||
|
|
||||||
def remove_shopping_cart(bench='.'):
|
|
||||||
archived_apps_dir = os.path.join(bench, 'archived_apps')
|
|
||||||
shopping_cart_dir = os.path.join(bench, 'apps', 'shopping_cart')
|
|
||||||
|
|
||||||
if not os.path.exists(shopping_cart_dir):
|
|
||||||
return
|
|
||||||
|
|
||||||
run_frappe_cmd('--site', 'all', 'remove-from-installed-apps', 'shopping_cart', bench=bench)
|
|
||||||
remove_from_appstxt('shopping_cart', bench=bench)
|
|
||||||
exec_cmd("{pip} --no-input uninstall -y shopping_cart".format(pip=os.path.join(bench, 'env', 'bin', 'pip')))
|
|
||||||
|
|
||||||
if not os.path.exists(archived_apps_dir):
|
|
||||||
os.mkdir(archived_apps_dir)
|
|
||||||
shutil.move(shopping_cart_dir, archived_apps_dir)
|
|
||||||
|
|
||||||
def validate_v4(bench='.'):
|
|
||||||
for repo in repos:
|
|
||||||
path = os.path.join(bench, 'apps', repo)
|
|
||||||
if os.path.exists(path):
|
|
||||||
current_version = get_current_version(path)
|
|
||||||
if not current_version.startswith('4'):
|
|
||||||
raise Exception("{} is not on v4.x.x".format(repo))
|
|
||||||
|
|
||||||
def checkout_v5(repo, bench='.'):
|
|
||||||
cwd = os.path.join(bench, 'apps', repo)
|
|
||||||
unshallow = "--unshallow" if os.path.exists(os.path.join(cwd, ".git", "shallow")) else ""
|
|
||||||
if os.path.exists(cwd):
|
|
||||||
exec_cmd("git config --add remote.upstream.fetch '+refs/heads/*:refs/remotes/upstream/*'", cwd=cwd)
|
|
||||||
exec_cmd("git fetch upstream {unshallow}".format(unshallow=unshallow), cwd=cwd)
|
|
||||||
exec_cmd("git checkout v5.0", cwd=cwd)
|
|
||||||
exec_cmd("git clean -df", cwd=cwd)
|
|
@ -32,11 +32,4 @@
|
|||||||
# setup frappe-bench
|
# setup frappe-bench
|
||||||
- include: setup_bench.yml
|
- include: setup_bench.yml
|
||||||
|
|
||||||
# setup procfile
|
|
||||||
|
|
||||||
# setup config for redis/socketio
|
|
||||||
|
|
||||||
# setup common_site_config
|
|
||||||
|
|
||||||
# set developer_mode
|
|
||||||
|
|
@ -8,9 +8,33 @@
|
|||||||
command: bench init {{ bench_path }}
|
command: bench init {{ bench_path }}
|
||||||
args:
|
args:
|
||||||
creates: "{{ bench_path }}"
|
creates: "{{ bench_path }}"
|
||||||
|
|
||||||
|
# setup common_site_config
|
||||||
|
- name: setup config
|
||||||
|
command: bench setup config
|
||||||
|
args:
|
||||||
|
creates: "{{ bench_path }}/sites/common_site_config.json"
|
||||||
|
chdir: "{{ bench_path }}"
|
||||||
|
|
||||||
- name: install frappe app
|
- name: install frappe app
|
||||||
command: bench get-app frappe https://github.com/frappe/frappe
|
command: bench get-app frappe https://github.com/frappe/frappe
|
||||||
args:
|
args:
|
||||||
creates: "{{ bench_path }}/apps/frappe"
|
creates: "{{ bench_path }}/apps/frappe"
|
||||||
chdir: "{{ bench_path }}"
|
chdir: "{{ bench_path }}"
|
||||||
|
|
||||||
|
# setup procfile
|
||||||
|
- name: setup procfile
|
||||||
|
command: bench setup procfile
|
||||||
|
args:
|
||||||
|
creates: "{{ bench_path }}/Procfile"
|
||||||
|
chdir: "{{ bench_path }}"
|
||||||
|
|
||||||
|
|
||||||
|
# setup config for redis/socketio
|
||||||
|
- name: setup redis
|
||||||
|
command: bench setup redis
|
||||||
|
args:
|
||||||
|
creates: "{{ bench_path }}/config/redis_socketio.conf"
|
||||||
|
chdir: "{{ bench_path }}"
|
||||||
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
|||||||
# wget setup_frappe.py | python
|
# wget setup_frappe.py | python
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import pwd
|
|
||||||
import stat
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import string
|
|
||||||
|
|
||||||
from random import choice
|
|
||||||
from distutils.spawn import find_executable
|
from distutils.spawn import find_executable
|
||||||
from setuptools.command import easy_install as easy_install
|
from setuptools.command import easy_install as easy_install
|
||||||
|
|
||||||
@ -19,7 +15,7 @@ def install_bench(args):
|
|||||||
install_git()
|
install_git()
|
||||||
|
|
||||||
# clone bench repo
|
# clone bench repo
|
||||||
cloned = clone_bench_repo()
|
clone_bench_repo()
|
||||||
|
|
||||||
if args.develop:
|
if args.develop:
|
||||||
run_playbook('develop/install.yml', sudo=True)
|
run_playbook('develop/install.yml', sudo=True)
|
||||||
@ -83,7 +79,7 @@ def clone_bench_repo():
|
|||||||
|
|
||||||
os.makedirs('/usr/local/frappe')
|
os.makedirs('/usr/local/frappe')
|
||||||
success = run_os_command(
|
success = run_os_command(
|
||||||
{"git": "git clone https://github.com/frappe/bench {bench_repo}".format(bench_repo=bench_repo)}
|
{"git": "git clone https://github.com/frappe/bench {bench_repo} --branch new-install".format(bench_repo=bench_repo)}
|
||||||
)
|
)
|
||||||
|
|
||||||
return success
|
return success
|
||||||
|
Loading…
Reference in New Issue
Block a user