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.
 
 
 
 
 
 

38 lines
1.1 KiB

  1. def listfolders(path, only_name=0):
  2. """
  3. Returns the list of folders (with paths) in the given path,
  4. If only_name is set, it returns only the folder names
  5. """
  6. import os
  7. out = []
  8. for each in os.listdir(path):
  9. dirname = each.split(os.path.sep)[-1]
  10. fullpath = os.path.join(path, dirname)
  11. if os.path.isdir(fullpath) and not dirname.startswith('.'):
  12. out.append(only_name and dirname or fullname)
  13. return out
  14. def switch_module(dt, dn, to, frm=None, export=None):
  15. """
  16. Change the module of the given doctype, if export is true, then also export txt and copy
  17. code files from src
  18. """
  19. import os
  20. webnotes.conn.sql("update `tab"+dt+"` set module=%s where name=%s", (to, dn))
  21. if export:
  22. export_doc(dt, dn)
  23. # copy code files
  24. if dt in ('DocType', 'Page', 'Search Criteria'):
  25. from_path = os.path.join(get_module_path(frm), scrub(dt), scrub(dn), scrub(dn))
  26. to_path = os.path.join(get_module_path(to), scrub(dt), scrub(dn), scrub(dn))
  27. # make dire if exists
  28. os.system('mkdir -p %s' % os.path.join(get_module_path(to), scrub(dt), scrub(dn)))
  29. for ext in ('py','js','html','css'):
  30. os.system('cp %s %s')