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.
 
 
 
 
 
 

60 lines
2.3 KiB

  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. def listfolders(path, only_name=0):
  23. """
  24. Returns the list of folders (with paths) in the given path,
  25. If only_name is set, it returns only the folder names
  26. """
  27. import os
  28. out = []
  29. for each in os.listdir(path):
  30. dirname = each.split(os.path.sep)[-1]
  31. fullpath = os.path.join(path, dirname)
  32. if os.path.isdir(fullpath) and not dirname.startswith('.'):
  33. out.append(only_name and dirname or fullname)
  34. return out
  35. def switch_module(dt, dn, to, frm=None, export=None):
  36. """
  37. Change the module of the given doctype, if export is true, then also export txt and copy
  38. code files from src
  39. """
  40. import os
  41. webnotes.conn.sql("update `tab"+dt+"` set module=%s where name=%s", (to, dn))
  42. if export:
  43. export_doc(dt, dn)
  44. # copy code files
  45. if dt in ('DocType', 'Page', 'Search Criteria'):
  46. from_path = os.path.join(get_module_path(frm), scrub(dt), scrub(dn), scrub(dn))
  47. to_path = os.path.join(get_module_path(to), scrub(dt), scrub(dn), scrub(dn))
  48. # make dire if exists
  49. os.system('mkdir -p %s' % os.path.join(get_module_path(to), scrub(dt), scrub(dn)))
  50. for ext in ('py','js','html','css'):
  51. os.system('cp %s %s')