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.
 
 
 
 
 
 

51 lines
1.4 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
  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. import conf
  11. from webnotes.modules.import_file import import_file
  12. from webntoes.utils import get_base_path
  13. def sync_all(force=0):
  14. sync_for("lib", force)
  15. sync_for("app", force)
  16. webnotes.clear_cache()
  17. def sync_for(folder, force=0, sync_everything = False):
  18. return walk_and_sync(os.path.join(get_base_path(),
  19. folder), force, sync_everything)
  20. def walk_and_sync(start_path, force=0, sync_everything = 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. folders.sort()
  27. if sync_everything or (os.path.basename(os.path.dirname(path)) in document_type):
  28. for f in files:
  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):
  36. print module_name + ' | ' + doctype + ' | ' + name
  37. webnotes.conn.commit()
  38. return modules