Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

70 rindas
2.4 KiB

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals, print_function
  4. """
  5. Sync's doctype and docfields from txt files to database
  6. perms will get synced only if none exist
  7. """
  8. import frappe
  9. import os
  10. from frappe.modules.import_file import import_file_by_path
  11. from frappe.modules.patch_handler import block_user
  12. from frappe.utils import update_progress_bar
  13. def sync_all(force=0, verbose=False, reset_permissions=False):
  14. block_user(True)
  15. for app in frappe.get_installed_apps():
  16. sync_for(app, force, verbose=verbose, reset_permissions=reset_permissions)
  17. block_user(False)
  18. frappe.clear_cache()
  19. def sync_for(app_name, force=0, sync_everything = False, verbose=False, reset_permissions=False):
  20. files = []
  21. if app_name == "frappe":
  22. # these need to go first at time of install
  23. for d in (("core", "docfield"), ("core", "docperm"), ("core", "has_role"), ("core", "doctype"),
  24. ("core", "user"), ("core", "role"), ("custom", "custom_field"),
  25. ("custom", "property_setter"), ("website", "web_form"),
  26. ("website", "web_form_field"), ("website", "portal_menu_item")):
  27. files.append(os.path.join(frappe.get_app_path("frappe"), d[0],
  28. "doctype", d[1], d[1] + ".json"))
  29. for module_name in frappe.local.app_modules.get(app_name) or []:
  30. folder = os.path.dirname(frappe.get_module(app_name + "." + module_name).__file__)
  31. get_doc_files(files, folder, force, sync_everything, verbose=verbose)
  32. l = len(files)
  33. if l:
  34. for i, doc_path in enumerate(files):
  35. import_file_by_path(doc_path, force=force, ignore_version=True,
  36. reset_permissions=reset_permissions, for_sync=True)
  37. #print module_name + ' | ' + doctype + ' | ' + name
  38. frappe.db.commit()
  39. # show progress bar
  40. update_progress_bar("Updating DocTypes for {0}".format(app_name), i, l)
  41. print()
  42. def get_doc_files(files, start_path, force=0, sync_everything = False, verbose=False):
  43. """walk and sync all doctypes and pages"""
  44. document_type = ['doctype', 'page', 'report', 'print_format', 'website_theme', 'web_form', 'email_alert']
  45. for doctype in document_type:
  46. doctype_path = os.path.join(start_path, doctype)
  47. if os.path.exists(doctype_path):
  48. for docname in os.listdir(doctype_path):
  49. if os.path.isdir(os.path.join(doctype_path, docname)):
  50. doc_path = os.path.join(doctype_path, docname, docname) + ".json"
  51. if os.path.exists(doc_path):
  52. if not doc_path in files:
  53. files.append(doc_path)