您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

46 行
1.3 KiB

  1. from __future__ import unicode_literals
  2. """
  3. Sync's doctype and docfields from txt files to database
  4. perms will get synced only if none exist
  5. """
  6. import webnotes
  7. import os
  8. import conf
  9. from webnotes.modules.import_file import import_file
  10. def sync_all(force=0):
  11. sync_for("lib", force)
  12. sync_for("app", force)
  13. webnotes.clear_cache()
  14. def sync_for(folder, force=0, sync_everything = False):
  15. return walk_and_sync(os.path.join(os.path.dirname(os.path.abspath(conf.__file__)),
  16. folder), force, sync_everything)
  17. def walk_and_sync(start_path, force=0, sync_everything = False):
  18. """walk and sync all doctypes and pages"""
  19. modules = []
  20. document_type = ['doctype', 'page', 'report']
  21. for path, folders, files in os.walk(start_path):
  22. # sort folders so that doctypes are synced before pages or reports
  23. folders.sort()
  24. if sync_everything or (os.path.basename(os.path.dirname(path)) in document_type):
  25. for f in files:
  26. if f.endswith(".txt"):
  27. doc_name = f.split(".txt")[0]
  28. if doc_name == os.path.basename(path):
  29. module_name = path.split(os.sep)[-3]
  30. doctype = path.split(os.sep)[-2]
  31. name = path.split(os.sep)[-1]
  32. if import_file(module_name, doctype, name, force):
  33. print module_name + ' | ' + doctype + ' | ' + name
  34. webnotes.conn.commit()
  35. return modules