2
0
mirror of https://github.com/frappe/bench.git synced 2024-09-23 04:29:02 +00:00

Fix migrate-3to4, fix #37

This commit is contained in:
Pratik Vyas 2014-07-25 12:09:02 +05:30
parent 4845ed51fa
commit fedf007a11

View File

@ -1,17 +1,38 @@
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
import subprocess
sites_path = os.environ.get('SITES_PATH', 'sites')
last_3_patch = 'patches.1401.fix_planned_qty'
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)
@ -59,10 +80,14 @@ def migrate(site):
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)