Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

sync.py 1.7 KiB

11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
12 lat temu
11 lat temu
12 lat temu
12 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. """
  5. Sync's doctype and docfields from txt files to database
  6. perms will get synced only if none exist
  7. """
  8. import webnotes
  9. import os, sys
  10. from webnotes.modules.import_file import import_file_by_path
  11. from webnotes.utils import get_path, cstr
  12. def sync_all(force=0):
  13. for app in webnotes.get_installed_apps():
  14. sync_for(app, force)
  15. webnotes.clear_cache()
  16. def sync_for(app_name, force=0, sync_everything = False, verbose=False):
  17. for module_name in webnotes.local.app_modules.get(app_name) or []:
  18. folder = os.path.dirname(webnotes.get_module(app_name + "." + module_name).__file__)
  19. walk_and_sync(folder, force, sync_everything, verbose=verbose)
  20. def walk_and_sync(start_path, force=0, sync_everything = False, verbose=False):
  21. """walk and sync all doctypes and pages"""
  22. modules = []
  23. document_type = ['doctype', 'page', 'report']
  24. for path, folders, files in os.walk(start_path):
  25. # sort folders so that doctypes are synced before pages or reports
  26. for dontwalk in (".git", "locale", "public"):
  27. if dontwalk in folders:
  28. folders.remove(dontwalk)
  29. folders.sort()
  30. if sync_everything or (os.path.basename(os.path.dirname(path)) in document_type):
  31. for f in files:
  32. f = cstr(f)
  33. if f.endswith(".txt"):
  34. doc_name = f.split(".txt")[0]
  35. if doc_name == os.path.basename(path):
  36. module_name = path.split(os.sep)[-3]
  37. doctype = path.split(os.sep)[-2]
  38. name = path.split(os.sep)[-1]
  39. if import_file_by_path(os.path.join(path, f), force=force) and verbose:
  40. print module_name + ' | ' + doctype + ' | ' + name
  41. webnotes.conn.commit()
  42. return modules