29 lines
1 KiB
Python
29 lines
1 KiB
Python
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
# MIT License. See license.txt
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import frappe, os
|
|
from frappe.core.page.data_import_tool.data_import_tool import import_doc, export_json
|
|
|
|
def sync_fixtures(app=None):
|
|
if app:
|
|
apps = [app]
|
|
else:
|
|
apps = frappe.get_installed_apps()
|
|
for app in apps:
|
|
if os.path.exists(frappe.get_app_path(app, "fixtures")):
|
|
for fname in os.listdir(frappe.get_app_path(app, "fixtures")):
|
|
if fname.endswith(".json") or fname.endswith(".csv"):
|
|
import_doc(frappe.get_app_path(app, "fixtures", fname), ignore_links=True, overwrite=True)
|
|
|
|
frappe.db.commit()
|
|
|
|
def export_fixtures():
|
|
for app in frappe.get_installed_apps():
|
|
for fixture in frappe.get_hooks("fixtures", app_name=app):
|
|
print "Exporting {0}".format(fixture)
|
|
if not os.path.exists(frappe.get_app_path(app, "fixtures")):
|
|
os.mkdir(frappe.get_app_path(app, "fixtures"))
|
|
|
|
export_json(fixture, frappe.get_app_path(app, "fixtures", frappe.scrub(fixture) + ".json"))
|