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.5 KiB

11 lat temu
11 lat temu
12 lat temu
12 lat temu
12 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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
  10. from webnotes.modules.import_file import import_file
  11. from webnotes.utils import get_path, cstr
  12. def sync_all(force=0):
  13. sync_for("lib", force)
  14. sync_for("app", force)
  15. webnotes.clear_cache()
  16. def sync_for(folder, force=0, sync_everything = False, verbose=False):
  17. return walk_and_sync(get_path(folder), force, sync_everything, verbose=verbose)
  18. def walk_and_sync(start_path, force=0, sync_everything = False, verbose=False):
  19. """walk and sync all doctypes and pages"""
  20. modules = []
  21. document_type = ['doctype', 'page', 'report']
  22. for path, folders, files in os.walk(start_path):
  23. # sort folders so that doctypes are synced before pages or reports
  24. if 'locale' in folders: folders.remove('locale')
  25. folders.sort()
  26. if sync_everything or (os.path.basename(os.path.dirname(path)) in document_type):
  27. for f in files:
  28. f = cstr(f)
  29. if f.endswith(".txt"):
  30. doc_name = f.split(".txt")[0]
  31. if doc_name == os.path.basename(path):
  32. module_name = path.split(os.sep)[-3]
  33. doctype = path.split(os.sep)[-2]
  34. name = path.split(os.sep)[-1]
  35. if import_file(module_name, doctype, name, force=force) and verbose:
  36. print module_name + ' | ' + doctype + ' | ' + name
  37. webnotes.conn.commit()
  38. return modules