2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-11 15:51:03 +00:00

Add 3to4 migration, fix #23

This commit is contained in:
Pratik Vyas 2014-07-17 15:08:26 +05:30
parent 7ff05eb387
commit 07df02ce9a
2 changed files with 76 additions and 0 deletions

View File

@ -12,6 +12,7 @@ from .app import get_app as _get_app
from .app import new_app as _new_app
from .app import pull_all_apps
from .config import generate_config
from .migrate3to4 import main as _migrate_3to4
import os
import sys
import logging
@ -101,6 +102,12 @@ def start():
"Start Frappe development processes"
_start()
@click.command('migrate-3to4')
@click.argument('path')
def migrate_3to4(path):
"Migrate from ERPNext v3.x"
_migrate_3to4(path)
## Setup
@click.group()
def setup():
@ -198,4 +205,5 @@ bench.add_command(update)
bench.add_command(restart)
bench.add_command(config)
bench.add_command(start)
bench.add_command(migrate_3to4)

68
bench/migrate3to4.py Normal file
View File

@ -0,0 +1,68 @@
from frappe.installer import add_to_installed_apps
from frappe.cli import latest
from frappe.modules.patch_handler import executed
from .utils import exec_cmd, get_sites, get_frappe
import frappe
import argparse
import os
import imp
import json
import shutil
sites_path = os.environ.get('SITES_PATH', 'sites')
last_3_patch = 'patches.1401.fix_planned_qty'
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')
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 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)
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)
frappe.init(site=site, sites_path=sites_path)
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')
module = {x:getattr(module, x) for x in json_keys}
return json.dumps(module, indent=indent)