From a045967331f2f48bbb360947fc55c523e3a631f5 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 9 Sep 2014 13:05:13 +0530 Subject: [PATCH] [refactor] install fix --- frappe/model/delete_doc.py | 4 +++- frappe/model/sync.py | 26 +++++++++++++++----------- frappe/utils/install.py | 3 +++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/frappe/model/delete_doc.py b/frappe/model/delete_doc.py index eda985b30c..625b8ceaa2 100644 --- a/frappe/model/delete_doc.py +++ b/frappe/model/delete_doc.py @@ -98,7 +98,9 @@ def delete_from_table(doctype, name, ignore_doctypes, doc): return frappe.db.sql_list("""select options from `tab{}` where fieldtype='Table' and parent=%s""".format(field_doctype), doctype) - tables = get_table_fields("DocField") + get_table_fields("Custom Field") + tables = get_table_fields("DocField") + if not frappe.flags.in_install_app=="frappe": + tables += get_table_fields("Custom Field") # delete from child tables for t in list(set(tables)): diff --git a/frappe/model/sync.py b/frappe/model/sync.py index a3d411797b..24deeed32b 100644 --- a/frappe/model/sync.py +++ b/frappe/model/sync.py @@ -7,7 +7,7 @@ from __future__ import unicode_literals perms will get synced only if none exist """ import frappe -import os, sys +import os from frappe.modules.import_file import import_file_by_path from frappe.modules.patch_handler import block_user from frappe.utils import update_progress_bar @@ -24,9 +24,18 @@ def sync_all(force=0, verbose=False): def sync_for(app_name, force=0, sync_everything = False, verbose=False): files = [] + + if app_name == "frappe": + # these need to go first at time of install + for d in (("core", "docfield"), ("core", "docperm"), ("core", "doctype"), + ("core", "user"), ("core", "role"), ("custom", "custom_field"), + ("custom", "property_setter")): + files.append(os.path.join(frappe.get_app_path("frappe"), d[0], + "doctype", d[1], d[1] + ".json")) + for module_name in frappe.local.app_modules.get(app_name) or []: folder = os.path.dirname(frappe.get_module(app_name + "." + module_name).__file__) - files += get_doc_files(folder, force, sync_everything, verbose=verbose) + get_doc_files(files, folder, force, sync_everything, verbose=verbose) l = len(files) if l: @@ -42,22 +51,17 @@ def sync_for(app_name, force=0, sync_everything = False, verbose=False): print "" -def get_doc_files(start_path, force=0, sync_everything = False, verbose=False): +def get_doc_files(files, start_path, force=0, sync_everything = False, verbose=False): """walk and sync all doctypes and pages""" - out = [] document_type = ['doctype', 'page', 'report', 'print_format'] for doctype in document_type: doctype_path = os.path.join(start_path, doctype) if os.path.exists(doctype_path): - # Note: sorted is a hack because custom* and doc* need - # be synced first - - for docname in sorted(os.listdir(doctype_path)): + for docname in os.listdir(doctype_path): if os.path.isdir(os.path.join(doctype_path, docname)): doc_path = os.path.join(doctype_path, docname, docname) + ".json" if os.path.exists(doc_path): - out.append(doc_path) - - return out + if not doc_path in files: + files.append(doc_path) diff --git a/frappe/utils/install.py b/frappe/utils/install.py index ef04d527e8..7ff8f3ffdd 100644 --- a/frappe/utils/install.py +++ b/frappe/utils/install.py @@ -62,8 +62,11 @@ def before_tests(): def import_country_and_currency(): from frappe.geo.country_info import get_all + print "Importing Geo..." + data = get_all() + for name in data: country = frappe._dict(data[name]) add_country_and_currency(name, country)