You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

43 lines
1.2 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 reload_doc
  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. if sync_everything or (os.path.basename(os.path.dirname(path)) in document_type):
  23. for f in files:
  24. if f.endswith(".txt"):
  25. doc_name = f.split(".txt")[0]
  26. if doc_name == os.path.basename(path):
  27. module_name = path.split(os.sep)[-3]
  28. doctype = path.split(os.sep)[-2]
  29. name = path.split(os.sep)[-1]
  30. if reload_doc(module_name, doctype, name, force):
  31. print module_name + ' | ' + doctype + ' | ' + name
  32. webnotes.conn.commit()
  33. return modules