25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

49 satır
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. 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):
  17. return walk_and_sync(os.path.join(os.path.dirname(os.path.abspath(conf.__file__)),
  18. folder), force, sync_everything)
  19. def walk_and_sync(start_path, force=0, sync_everything = False):
  20. """walk and sync all doctypes and pages"""
  21. modules = []
  22. document_type = ['doctype', 'page', 'report']
  23. for path, folders, files in os.walk(start_path):
  24. # sort folders so that doctypes are synced before pages or reports
  25. folders.sort()
  26. if sync_everything or (os.path.basename(os.path.dirname(path)) in document_type):
  27. for f in files:
  28. if f.endswith(".txt"):
  29. doc_name = f.split(".txt")[0]
  30. if doc_name == os.path.basename(path):
  31. module_name = path.split(os.sep)[-3]
  32. doctype = path.split(os.sep)[-2]
  33. name = path.split(os.sep)[-1]
  34. if import_file(module_name, doctype, name, force):
  35. print module_name + ' | ' + doctype + ' | ' + name
  36. webnotes.conn.commit()
  37. return modules