Ejemplo n.º 1
0
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__)
		get_doc_files(files, folder, force, sync_everything, verbose=verbose)

	l = len(files)
	if l:
		for i, doc_path in enumerate(files):
			import_file_by_path(doc_path, force=force)
			#print module_name + ' | ' + doctype + ' | ' + name

			frappe.db.commit()

			# show progress bar
			update_progress_bar("Updating {0}".format(app_name), i, l)

		print ""
Ejemplo n.º 2
0
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__)
        get_doc_files(files, folder, force, sync_everything, verbose=verbose)

    l = len(files)
    if l:
        for i, doc_path in enumerate(files):
            import_file_by_path(doc_path, force=force)
            #print module_name + ' | ' + doctype + ' | ' + name

            frappe.db.commit()

            # show progress bar
            update_progress_bar("Updating {0}".format(app_name), i, l)

        print ""
Ejemplo n.º 3
0
def make_records(path, filters=None):
    if os.path.isdir(path):
        for fname in os.listdir(path):
            if os.path.isdir(join(path, fname)):
                if fname == '__pycache__':
                    continue
                import_file_by_path("{path}/{fname}/{fname}.json".format(
                    path=path, fname=fname))
Ejemplo n.º 4
0
def add_web_forms():
	"""Import web forms for Issues and Addresses"""
	from frappe.modules.import_file import import_file_by_path

	import_file_by_path(frappe.get_app_path("erpnext", "setup/fixtures/web_form/issues.json"),
		data_import=True)
	import_file_by_path(frappe.get_app_path("erpnext", "setup/fixtures/web_form/addresses.json"),
		data_import=True)
Ejemplo n.º 5
0
def sync_for(app_name, force=0, reset_permissions=False):
	files = []

	if app_name == "frappe":
		# these need to go first at time of install

		FRAPPE_PATH = frappe.get_app_path("frappe")

		for core_module in ["docfield", "docperm", "doctype_action", "doctype_link", "role", "has_role", "doctype"]:
			files.append(os.path.join(FRAPPE_PATH, "core", "doctype", core_module, f"{core_module}.json"))

		for custom_module in ["custom_field", "property_setter"]:
			files.append(os.path.join(FRAPPE_PATH, "custom", "doctype", custom_module, f"{custom_module}.json"))

		for website_module in ["web_form", "web_template", "web_form_field", "portal_menu_item"]:
			files.append(os.path.join(FRAPPE_PATH, "website", "doctype", website_module, f"{website_module}.json"))

		for data_migration_module in [
			"data_migration_mapping_detail",
			"data_migration_mapping",
			"data_migration_plan_mapping",
			"data_migration_plan",
		]:
			files.append(os.path.join(FRAPPE_PATH, "data_migration", "doctype", data_migration_module, f"{data_migration_module}.json"))

		for desk_module in [
			"number_card",
			"dashboard_chart",
			"dashboard",
			"onboarding_permission",
			"onboarding_step",
			"onboarding_step_map",
			"module_onboarding",
			"workspace_link",
			"workspace_chart",
			"workspace_shortcut",
			"workspace",
		]:
			files.append(os.path.join(FRAPPE_PATH, "desk", "doctype", desk_module, f"{desk_module}.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(files=files, start_path=folder)

	l = len(files)

	if l:
		for i, doc_path in enumerate(files):
			import_file_by_path(doc_path, force=force, ignore_version=True, reset_permissions=reset_permissions)

			frappe.db.commit()

			# show progress bar
			update_progress_bar("Updating DocTypes for {0}".format(app_name), i, l)

		# print each progress bar on new line
		print()
Ejemplo n.º 6
0
def sync_for(app_name,
             force=0,
             sync_everything=False,
             verbose=False,
             reset_permissions=False):
    files = []

    if app_name == "frappe":
        # these need to go first at time of install
        for d in (("core", "docfield"), ("core", "docperm"),
                  ("core", "doctype_action"), ("core", "doctype_link"),
                  ("core", "role"), ("core", "has_role"), ("core", "doctype"),
                  ("core", "user"), ("custom", "custom_field"),
                  ("custom", "property_setter"), ("website", "web_form"),
                  ("website", "web_template"), ("website", "web_form_field"),
                  ("website",
                   "portal_menu_item"), ("data_migration",
                                         "data_migration_mapping_detail"),
                  ("data_migration", "data_migration_mapping"),
                  ("data_migration",
                   "data_migration_plan_mapping"), ("data_migration",
                                                    "data_migration_plan"),
                  ("desk", "number_card"), ("desk", "dashboard_chart"),
                  ("desk", "dashboard"), ("desk", "onboarding_permission"),
                  ("desk", "onboarding_step"), ("desk", "onboarding_step_map"),
                  ("desk", "module_onboarding"), ("desk", "workspace_link"),
                  ("desk",
                   "workspace_chart"), ("desk",
                                        "workspace_shortcut"), ("desk",
                                                                "workspace")):
            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__)
        get_doc_files(files, folder)

    l = len(files)
    if l:
        for i, doc_path in enumerate(files):
            import_file_by_path(doc_path,
                                force=force,
                                ignore_version=True,
                                reset_permissions=reset_permissions,
                                for_sync=True)

            frappe.db.commit()

            # show progress bar
            update_progress_bar("Updating DocTypes for {0}".format(app_name),
                                i, l)

        # print each progress bar on new line
        print()
Ejemplo n.º 7
0
def add_web_forms():
    """Import web forms for Issues and Addresses"""
    from frappe.modules.import_file import import_file_by_path

    import_file_by_path(frappe.get_app_path(
        "erpnext", "setup/fixtures/web_form/issues.json"),
                        data_import=True)
    import_file_by_path(frappe.get_app_path(
        "erpnext", "setup/fixtures/web_form/addresses.json"),
                        data_import=True)
Ejemplo n.º 8
0
def walk_and_sync(start_path, force=0, sync_everything=False, verbose=False):
    """walk and sync all doctypes and pages"""

    modules = []

    document_type = ['doctype', 'page', 'report', 'print_format']

    for path, folders, files in os.walk(start_path):
        # sort folders so that doctypes are synced before pages or reports

        for dontwalk in (".git", "locale", "public"):
            if dontwalk in folders:
                folders.remove(dontwalk)

        folders.sort()

        if sync_everything or (os.path.basename(os.path.dirname(path))
                               in document_type):
            for f in files:
                f = cstr(f)
                if f.endswith(".json"):
                    doc_name = f.split(".json")[0]
                    if doc_name == os.path.basename(path):

                        module_name = path.split(os.sep)[-3]
                        doctype = path.split(os.sep)[-2]
                        name = path.split(os.sep)[-1]

                        if import_file_by_path(os.path.join(path, f),
                                               force=force) and verbose:
                            print module_name + ' | ' + doctype + ' | ' + name

                        frappe.db.commit()

    return modules
Ejemplo n.º 9
0
def walk_and_sync(start_path, force=0, sync_everything = False, verbose=False):
	"""walk and sync all doctypes and pages"""

	modules = []

	document_type = ['doctype', 'page', 'report', 'print_format']

	for path, folders, files in os.walk(start_path):
		# sort folders so that doctypes are synced before pages or reports

		for dontwalk in (".git", "locale", "public"):
			if dontwalk in folders:
				folders.remove(dontwalk)

		folders.sort()

		if sync_everything or (os.path.basename(os.path.dirname(path)) in document_type):
			for f in files:
				f = cstr(f)
				if f.endswith(".json"):
					doc_name = f.split(".json")[0]
					if doc_name == os.path.basename(path):

						module_name = path.split(os.sep)[-3]
						doctype = path.split(os.sep)[-2]
						name = path.split(os.sep)[-1]

						if import_file_by_path(os.path.join(path, f), force=force) and verbose:
							print module_name + ' | ' + doctype + ' | ' + name

						frappe.db.commit()

	return modules
Ejemplo n.º 10
0
    def import_package(self):
        attachment = get_attachments(self.doctype, self.name)

        if not attachment:
            frappe.throw(frappe._('Please attach the package'))

        attachment = attachment[0]

        # get package_name from file (package_name-0.0.0.tar.gz)
        package_name = attachment.file_name.split('.')[0].rsplit('-', 1)[0]
        if not os.path.exists(frappe.get_site_path('packages')):
            os.makedirs(frappe.get_site_path('packages'))

        # extract
        subprocess.check_output([
            'tar', 'xzf',
            frappe.get_site_path(attachment.file_url.strip('/')), '-C',
            frappe.get_site_path('packages')
        ])

        package_path = frappe.get_site_path('packages', package_name)

        # import Package
        with open(os.path.join(package_path, package_name + '.json'),
                  'r') as packagefile:
            doc_dict = json.loads(packagefile.read())

        frappe.flags.package = import_doc(doc_dict)

        # collect modules
        files = []
        log = []
        for module in os.listdir(package_path):
            module_path = os.path.join(package_path, module)
            if os.path.isdir(module_path):
                get_doc_files(files, module_path)

        # import files
        for file in files:
            import_file_by_path(file,
                                force=self.force,
                                ignore_version=True,
                                for_sync=True)
            log.append('Imported {}'.format(file))

        self.log = '\n'.join(log)
Ejemplo n.º 11
0
def import_doc(path, pre_process=None):
	if os.path.isdir(path):
		files = [os.path.join(path, f) for f in os.listdir(path)]
	else:
		files = [path]

	for f in files:
		if f.endswith(".json"):
			frappe.flags.mute_emails = True
			import_file_by_path(
				f, data_import=True, force=True, pre_process=pre_process, reset_permissions=True
			)
			frappe.flags.mute_emails = False
			frappe.db.commit()
		elif f.endswith(".csv"):
			validate_csv_import_file(f)
			frappe.db.commit()
Ejemplo n.º 12
0
def sync_for(app_name, force=0, sync_everything = False, verbose=False):
	files = []
	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)

	l = len(files)
	if l:
		for i, doc_path in enumerate(files):
			import_file_by_path(doc_path, force=force)
			#print module_name + ' | ' + doctype + ' | ' + name

			frappe.db.commit()

			# show progress bar
			update_progress_bar("Updating {0}".format(app_name), i, l)

		print ""
Ejemplo n.º 13
0
def import_doc(path, pre_process=None):
    if os.path.isdir(path):
        files = [os.path.join(path, f) for f in os.listdir(path)]
    else:
        files = [path]

    for f in files:
        if f.endswith(".json"):
            frappe.flags.mute_emails = True
            import_file_by_path(f,
                                data_import=True,
                                force=True,
                                pre_process=pre_process,
                                reset_permissions=True)
            frappe.flags.mute_emails = False
            frappe.db.commit()
        else:
            raise NotImplementedError("Only .json files can be imported")
Ejemplo n.º 14
0
def sync_for(app_name, force=0, sync_everything=False, verbose=False):
    files = []
    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)

    l = len(files)
    if l:
        for i, doc_path in enumerate(files):
            import_file_by_path(doc_path, force=force)
            #print module_name + ' | ' + doctype + ' | ' + name

            frappe.db.commit()

            # show progress bar
            update_progress_bar("Updating {0}".format(app_name), i, l)

        print ""
Ejemplo n.º 15
0
def add_dashboards():
    from erpnext.setup.setup_wizard.data.dashboard_charts import get_company_for_dashboards

    if not get_company_for_dashboards():
        return

    from erpnext.setup.setup_wizard.data.dashboard_charts import get_default_dashboards
    from frappe.modules.import_file import import_file_by_path

    dashboard_data = get_default_dashboards()

    # create account balance timeline before creating dashbaord charts
    doctype = "dashboard_chart_source"
    docname = "account_balance_timeline"
    folder = os.path.dirname(frappe.get_module("erpnext.accounts").__file__)
    doc_path = os.path.join(folder, doctype, docname, docname) + ".json"
    import_file_by_path(doc_path, force=0, for_sync=True)

    make_records(dashboard_data["Charts"])
    make_records(dashboard_data["Dashboards"])
Ejemplo n.º 16
0
def sync_for(app_name, force=0, sync_everything = False, verbose=False, reset_permissions=False):
	files = []

	if app_name == "frappe":
		# these need to go first at time of install
		for d in (("core", "docfield"),
			("core", "docperm"),
			("core", "has_role"),
			("core", "doctype"),
			("core", "user"),
			("core", "role"),
			("custom", "custom_field"),
			("custom", "property_setter"),
			("website", "web_form"),
			("website", "web_form_field"),
			("website", "portal_menu_item"),
			("data_migration", "data_migration_mapping_detail"),
			("data_migration", "data_migration_mapping"),
			("data_migration", "data_migration_plan_mapping"),
			("data_migration", "data_migration_plan")):
			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__)
		get_doc_files(files, folder, force, sync_everything, verbose=verbose)

	l = len(files)
	if l:
		for i, doc_path in enumerate(files):
			import_file_by_path(doc_path, force=force, ignore_version=True,
				reset_permissions=reset_permissions, for_sync=True)
			#print module_name + ' | ' + doctype + ' | ' + name

			frappe.db.commit()

			# show progress bar
			update_progress_bar("Updating DocTypes for {0}".format(app_name), i, l)

		# print each progress bar on new line
		print()